Saturday, November 22, 2008

When apt-get fails to reinstall a package

While experimenting with the Moin Moin Wiki, I got into some bother attempting to uninstall and reinstall it. The problem originated from me manually removing some configuration files. apt-get subsequently refused to reinstall those files. I eventually resolved by using dpkg.

I had initially followed the installation steps for Moin Moin on the Ubuntu Server Guide. So I had installed by doing
$ sudo apt-get install python-moinmoin
So to uninstall, I did
$ sudo apt-get remove python-moinmoin
I now know that that did not uninstall a base package, moinmoin-common, on which it depends. But I didn't notice that at first. All I saw was that some configuration files were still present in /etc/moin, so I rm -rf them.

And there began my trouble, because thereafter I could not get apt-get to delete or reinstall the configuration files to that dir.

I did various iterations of apt-get install, apt-get remove and apt-get purge for the moinmoin-common and python-moinmoin packages. But the remove operations never removed /etc/moin and the installs never installed the missing files.

I used dpkg-deb to inspect the moinmoin-common archive file in /var/cache/apt/archives. I could see the to files I wanted were in the archive. But I could not get them to unpack to /etc/moin.

A temporary workaround was to use dpkg-deb to extract the archive file to /tmp, which unpacked everything, and then manually copy the uninstallable files from there to /etc/moin. But I wanted to find the proper solution.

I found a thread on the Ubuntu Forums outlining an equivalent problem with an apache2 installation. The advice there was to use Synaptic to remove the package. I don't have that option as I am running a headless server and Synaptic is a GUI tool. But at least there was the suggestion of a solution. If it can be done in a Debian/Ubuntu GUI, then be sure it can be done on the command line too.

Then I found a good article at which explained how you can escalate from apt-get to dpkg to resolve package management problems.

So the happy ending was to do
$ sudo dpkg --purge moinmoin-common
This removed the troublesome files and the references to them that the package manager was evidently keeping. After that, I was able to cleanly reinstall Moin Moin.

Thursday, November 20, 2008

CUPS print server

I installed CUPS on my fit-PC mini Linux server to turn it into a USB print server.

Got a USB printer? Want to let several computers share it? Want to print to it wirelessly? Well you could buy a USB print server. Connect one of these to your router and your printer and you can share the printer on your network. If your router is wireless, you now have a wireless print server.

But since I already have an always-on mini Linux server, I can simply install CUPS on that and let it be my print server.

The setup
  • Fit-PC mini Linux server connected to my wireless router, as before.
  • USB laser printer (HP LaserJet 1010) connected to a USB port on the server.
  • CUPS installed and configured on the server to allow any PC connected to the router to use the printer.
  • Generic printer driver installed on Windows laptops so they can use the printer through the printer server.
So now I have a very handy wireless print server...
  • I can send stuff to the printer whenever I like.
  • The printer itself doesn't need to be turned on - just the server. Print jobs are spooled to the server.
  • When I want to collect printed pages, I just turn on the printer. The server detects it and sends the pending pages.
  • Pending print jobs are is written to disk, so even if you turn off the server, they are there when it restarts.
Installing and configuring CUPS on the server was straightforward.
$ sudo apt-get install cupsys
I Googled a bit for cupsys setup tips and made a few changes to /etc/cups/cupsd.conf.

For what it's worth, here's the diff between the default configuration (Ubuntu 8.04) and my current version.
$ diff /etc/cups/cupsd.conf.original /etc/cups/cupsd.conf
> Listen <my-server-ip-address>:631
< DefaultAuthType Basic
> DefaultAuthType None
< Order allow,deny
> Order deny,allow
> Deny From All
> Allow From
> Allow From 192.168.2.*
> Allow 192.168.2.*
> Allow 192.168.2.*
I think I had to restart the server once after installing cupsys, before I could access its web interface from my laptop. (Maybe apparmor related. I'm begining to think that reboot is required to allow any newly installed HTTP service available. Could be wrong there.)

Anyway, once it's setup right, you can point your browser to
to browse and manage the print server.

The setup on Windows laptops was very easy. I used "Add Printer" to add a network printer, specifying connect by URL, and a generic PostScript driver (I used Generic / MS Publisher ImageSetter).

There are of course many other ways to set it up, e.g. different printer driver options are covered here. But this is working out nicely for me.

Wednesday, November 12, 2008

Performance of SqueezeCenter on fit-PC Slim

Here is some data on the performance of SqueezeCenter on my fit-PC Slim.

Library rescan

4004 mp3 files

* Look for new & changed music - 1:50
* Clear library and rescan everything - 18:01

3987 flac files

* Clear library and rescan everything - 13:06

Power consumption was peaked at 9 watts during rescans compared to 7 watts for normal operation.

Web interface*

Full cold load^ of the interface - 15 secs
Warm load - 5 secs

*Firefox 2
^Clear browser cache and restart browser

Saturday, November 8, 2008

Some photos of the fit-PC

"For those who like that sort of thing, that is the sort of thing they like."

fit-PC and a AAA battery

fit-PC on the left next to the Linksys router

Squeezebox and fit-PC

Typical power consumption 7 watts

Thursday, November 6, 2008

SqueezeCenter on the fit-PC Slim

It's a few weeks since I installed SqueezeCenter 7.2 on my mini Linux server. I'm delighted to say that it's working out great.

Music playback on my Squeezebox player is flawless. The responsiveness of the player and web interface is just fine.

My server is the recently released fit-PC Slim (512MB RAM), which I ordered diskless and fitted with a 250GB disk. It's running a minimal server install of Ubuntu 8.04 with a few services including SqueezeCenter.

In its current configuration, my fit-PC draws just 7 watts.

I think that's pretty terrific. I expect to get the power consumption even lower whenever I get around to disabling the WIFI adapter in the BIOS.

I only have one Squeezebox, so can't comment on the ability to serve multiple clients, though I have played to the Squeezebox and my laptop simultaneously without glitches. Also, no problem streaming music while performing other background tasks, like copying on new music files and transcoding from FLAC to mp3.

I reckon the fit-PC is a really great fit for SqueezeCenter.

Saturday, November 1, 2008

Akasa HDD enclosure - remove the jumpers

I decommissioned my old server tonight and ripped out everything useful, including the 250GB IDE/PATA disk. I got an Akasa disk enclosure a few weeks ago specifically to recycle this disk. I had a couple of false starts, but they were resolved by removing the jumpers on the disk. (The Akasa manual says nothing about jumpers).

First off, with one jumper in the master/single position, Windows XP couldn't see the disk at all. Next, I misread the jumper diagram on the disk and put it in the "limit disk capacity" setting. Now Windows could see the disk, but only 33.8 GB of it. Same story connected to Linux. Finally, I removed the jumpers altogether. Now Linux and Windows can see the disk and its full capacity.

Formatting the disk with an NTFS partition now...

Wednesday, October 15, 2008

Migrating subversion repository

I have a small subversion repository on my old server. I want to migrate it to the fit-PC.

Looking at the relevant section of Version Control with Subversion, it looks like it should be easy. Just create a dumpfile on the old box and load it to a new repository on the new one.

So on the old box
$ svnadmin dump repos > dumpfile
and copy the dumpfile onto the new box.

Last time I setup subversion + apache for HTTP access. This time I'm going to try svn+ssh.

As usual, Ubuntu provides a good general reference.

Install subversion
$ sudo apt-get install subversion 
Setup a subversion user and group, add myself to the group
$ sudo addgroup svn
$ sudo useradd -g svn -m -p <pwd> svn
$ sudo usermod -a -G svn <my_user>
Create the repository and load the dumpfile
$ sudo su svn
$ cd /home/svn
$ svnadmin create repos
$ svnadmin load repos < dumpfile
I want svnserve process to start when the box boots, so I added this line to /etc/rc.local:
sudo -u svn svnserve -d -r /home/svn
I'll make a proper init.d script like this one later.

Restart the box

Verify I am a member of the svn group
$ groups
Verify that svnserve process started
$ ps -ef | grep svnserve
Verify I can read the repository locally
$ svn list svn://localhost/repos/<project>/trunk

Setup access to the repository from Eclipse on my laptop

(I already have the subclipse plugin installed).

File / Import
Checkout Projects from SVN
Create a new repository location

That fails with an error dialog and this message on the console:
    The system cannot find the file specified. 
svn: Can't create tunnel: The system cannot find the file specified.

Back to Google... The answer is here.

The problem was that Eclipse was not configured with an SSH client. Quick fix for me was to switch the Eclipse / Team / SVN configuration from JavaHL (which requires external SSH client) to SVNKit (which includes one). Now it works.

Edit! Actually, not quite there yet...

On attempting to commit to the repository, I got error
svn: Commit failed (details follow):
svn: Can't create directory '/home/svn/repos/db/transactions/1-1.txn':
Permission denied
It turns out that svn+ssh does not connect to the svnserve daemon I started above, but rather creates a temporary svnserve process (on each invocation) as the ssh user. And in the setup above, the ssh user has read access to the repos, but not write access. (Just like if you use subversion + apache and don't make the repository writable by the www-data user).

Temporary workaround (to commit my current work) is to make the whole repository writable by my ssh user
$ cd /home/svn
$ sudo chown <sshuser>:<sshuser> -R repos
Now the commit succeeds.

Next task is to read the relevant section of the Subversion manual more carefully. My original setup above will support working with the repository using svn://<host>/repos. I might just go with that for now.

Monday, October 13, 2008

Installing SqueezeCenter

Running SqueezeCenter to feed the Squeezebox music player is my old server's main duty. So it's first up for installation on my new fit-PC.

Edit /etc/apt/sources.list to add
deb stable main

$ sudo apt-get update
$ sudo apt-get install squeezecenter
The web interface is not available from my laptop until I restart the box (something to do with apparmor?). On restart, I can access the web interface fine.

SqueezeCenter installs mysql (unless you have it already) and SqueezeCenter then runs its own mysql instance, in addition to the default one. I don't want two mysql instances running on my little server, so I'll disable the default one for now:
$ cd /etc/rc2.d
$ cat README
$ sudo mv S18mysql-ndb K82mysql-ndb
$ sudo mv S19mysql K81mysql
$ sudo mv S17mysql-ndb-mgm K83mysql-ndb-mgm
Alternative would be to get squeezecenter to use the default mysql instance instead, and disable the dedicated squeezecenter one. Supposed to be possible. I'll try that whenever I end up with some other application which needs mysql.

Sunday, October 12, 2008

Initial setup

The first thing I want to do is get rid of the monitor and keyboard, so

$ sudo apt-get install openssh-server
$ sudo apt-get install screen

(Screen is great. I use it whenever I need to kick off some long-duration command. It means I can close the laptop, dropping my ssh session, but still reconnect to the console running the command whenever I want to.)

Edit /etc/network/interfaces to change from DHCP to static IP address, which is covered well here.

Serial console

I never tried this before...

I ordered the serial cable with my fit-PC and got a €3 generic USB RS-232 adapter cable from this store on ebay.

The instructions on the fit-PC wiki were great. On the other side, all I had to do was check which COM port the USB adapter was on using Windows device manager, and then create a serial PuTTY session using the same configuration.

With this setup, I get GRUB and kernel output to, and login from, the serial console. This is a real bonus compared to my old PC server.

I'd really like to be able to configure the fit-PC BIOS over the serial connection as well, but it sounds like that might be a bit more difficult.

Anyway, BIOS configuration changes aside, I can ditch the keyboard and monitor now. My fit-PC is ready to be a headless server.

Saturday, October 11, 2008

Ubuntu USB stick install, part 2

I finally got a successful install. But it took several attempts and a lot of Google.

First attempt

In the fit-PC BIOS setup, I set Drive C: Nand Flash but neglected to set Drive D: IDE. So when the installer got round to the partitioning stage it could only see the USB stick, not the hard disk. Hit reset button and start again...

Second attempt

I didn't create a separate ext3 /boot partition, just XFS root and /home partitions. Apparently installing GRUB on an XFS partition is not a good thing. Near the end of the install, the installer offers to install LILO for me. Now I dimly remembered going through LILO versus GRUB before and preferring GRUB, so I try to install GRUB anyway. The installer warns me that this is a bad idea. When I ignore that this makes a fatal error in the install which then hangs. Grit teeth, hit reset button and start again...

Third and fourth attempts

I created a separate ext3 /boot partition to stay sweet with GRUB. So I now have
#1 primary 100MB ext3 /boot
#1 primary 4GB XFS /
#5 logical 246GB XFS /home
Now the install completed successfully each time. But it all ended in tears when I tried to reboot the fit-PC. Each time, it immediately dropped to a debugger interface, saying Embedded BIOS Debugger Breakpoint Trap and refused to do anything else. Weep, hit the sack and try again in the morning...

I noticed that after each install attempt, I could no longer boot from the USB stick. It gave GRUB Error 21. I could fix the stick by reconnecting it to my old Linux box and doing install-mbr /dev/sdb. But why?

I finally guessed that the Ubuntu installer must be installing GRUB to the MBR of my USB stick, instead of the hard disk in my fit-PC where I needed it. Armed with that hunch, Google finally gave me some answers, like this, this and this.

Fifth attempt

I let the Ubuntu installer run to the very end, where it tells you to reboot. At that point, I opened a console and took a look around.

I found (fdisk) that my hard disk partitions were mounted on /target. So I did
# chroot /target
# grub-install /dev/sdb
to install GRUB into the MBR of the hard disk. Then I went back to the installer's console and let it finish.

On restart I removed the USB stick, hit DEL to enter the BIOS setup, reverted to Drive C: IDE and saved to reboot.

On first attempt GRUB started (phew) but said
Error 21: Selected disk does not exist
Press any key to continue...
So I did. Then GRUB gives the menu list of image it can boot and allows you to edit and boot them. I edited the entry for the first image. It's first line was root (hd1,0). I edited that to root (hd0,0) and the hit 'b' to boot. The system booted at last.

Once in, I took a look at /boot/grub/menu.list. All three had root (hd1,0).

I rebooted to confirm that GRUB would fail again with same error.
It did. I fixed as before. Once back in, I edited /boot/grub/menu.list to change all the hd1 to hd0 and rebooted again.

At last, the system boots successfully. Now I can get on with the more interesting stuff.

Friday, October 10, 2008

fit-PC BIOS notes

Once you have a bootable device attached to fit-PC, you enter the BIOS by holding down DEL key after resetting the box.

To reset the BIOS to factory defaults, hit down arrow 8 times, then hit enter. You never know when that might come in handy.

There's a "print out" of the BIOS menus here on the fit-PC wiki.

Ubuntu USB stick install on fit-PC, part 1

Hard disk installed. Bootable USB stick ready. Here we go...

Following the advice on the fit-PC forum I made the following BIOS settings:
Drive C: Nand Flash | Boot 1st
Drive D: IDE
It booted to the installer from the USB stick. I chose the cli boot option and set it off.

So that's the USB stick part over then, I thought. Just a normal install from here. (Wrong! See part 2 for the gory details.)

The installer's first big question is partitioning. I went with
#1 primary   4GB XFS /
#5 logical 246GB XFS /home
No swap. I can add it later if I need it.

I'm giving XFS a try this time because I might end up storing some ISO files on this disk. It's supposed to be a good file system for large files.

Thursday, October 9, 2008

Preparing to install from a USB stick

Since I ordered the diskless version of fit-PC, I need to add a hard disk and an operating system.

For the hard disk (2.5" IDE), I ordered a 250GB Western Digital Scorpio.

While I waited for the disk to arrive, I got ready to install the OS.

I'll stick with Ubuntu. I don't have a USB CD drive, so I'll try to install it from a USB memory stick. I followed the instructions here to make put a bootable installer on to my USB stick. The warnings about checking the correct device name are important! AFAIK the only way to be sure is to mount and list the device. Mine was /dev/sdb1.

I want a minimal server installation, so I just copied the netboot image and left it at that. I'll pull the packages I need from the network as I need them.

I initially tried
$ sudo zcat boot.img.gz > /dev/sdb1
but that was giving permission errors. So instead
$ sudo su
# zcat boot.img.gz > /dev/sdb1
did the job. I tried booting my laptop from the USB stick, but it said it was not a bootable device, so I followed the instructions on that same page to install an MBR.

I tried again to boot my laptop. This time it booted to a prompt
Ummm... Back to Google. I found the answer here - first enter "a", then "1" and it launched the text-based installer. Good. Hopefully it'll do the same on the fit-PC.

Wednesday, October 8, 2008

I ordered a fit-PC

I ordered a mini PC to replace my old Linux server.

Ever since I got a Squeezebox network music player a couple of years ago, I've been running a vintage Pentium III desktop PC as a music server. It's currently running the Ubuntu OS (8.04 Server Edition) and is hosting
I also use it to transcode my music files from FLAC to MP3, which it does... slowly but surely.

It's been fine, but is a bit big, noisy and wasteful. So I've been looking for something small, quiet and energy efficient to replace it.

fit-PC SlimI settled on the new fit-PC Slim - a tiny, fanless PC with a 500MHz processor, 512MB RAM and 4-6W power consumption. It should be a drop in replacement for the old box, I hope, with a bit of room to spare.

The stock version comes with a smallish 60GB hard disk, so I ordered the diskless version and will get a bigger disk separately.

I asked them to ship me a cable for the mini RS-232 port, so I can try using the serial console. Which might be fun.