Moving my firewall

Posted in General at 1:34 pm by jw

The CPU fan on my AOpen MiniPC died, which made me very sad because it doesn’t look like it’s an easily replaceable part.  While I’ll look for a source for the fan, it wasn’t feasible to just leave my firewall offline (as it hosts my email server, controls my home internet connection, monitors my UPS and does a whole bunch of other things) so I had to find another machine and move it over pretty quickly.  Fortunately I have a bunch of PCs laying around the house, much to my wife’s disgust, so I could pretty quickly just grab one and drop it in as a replacement.  The transition wasn’t quite as smooth as I’d hoped, but wasn’t too bad:

Step 1: Backup the MiniPC

The MiniPC would run for a short period of time, and could be coaxed into running longer by hitting it whenever the fan stopped.  This meant I could safely get all the data off the drive.  Although I did have the critical parts backed up (ie the email database), it would take considerable time to rebuild the full configuration so a direct transfer was a much faster idea.

My initial thought was to backup over the network to one of my desktop PCs, but I haven’t put the time into getting Samba to talk happily to Vista yet, so that didn’t work terribly well.  Failing that idea, I dug out my USB/IDE drive chassis and connected a blank IDE drive up.  Gentoo detected this quite happily from single user mode and I could then perform a full system backup onto the drive:

dd if=/dev/hda | gzip > /mnt/usbdrive/backup.gz

I ran the backup through gzip because I found quickly that the bandwidth to the USB drive was the real bottleneck in the system, so using gzip let me mitigate that a decent amount (went from 5M/sec to 15M/sec).  Fortunately it was only a 30G drive, so the whole process didn’t take much more than 30 minutes during which I could keep the CPU from overheating with beatings to the fan, and compressed air.

Step 2: Restore to new PC

Restoring to the new PC was the reverse of the backup to the USB hard drive.  It all ran pretty seamlessly (dd is an awesome command):

gzcat /mnt/usbdrive/backup.gz | dd of=/dev/hda

 The drive in the new machine was actually a 250G drive, but it dutifully copied the 30G image onto the drive and left me with the exact image of the 30G drive and a large empty space at the end of the partition table.  Running a quick fsck told me the drive hadn’t cleanly been unmounted (not surprising seeing I actually booted from it to do the initial backup) but was otherwise fine.

Step 3: ???

Well, the system booted, which was a minor miracle in itself given the complete shift in architecture from a Pentium 4 based system to an Athlon XP system.  The bigger problem was system level utilities like “awk” were failing with an Invalid Instruction exception, which from what I could tell was due to the system using SSE2 for floating point on the P4 compiles, but the Athlon XP not supporting that part of the instruction set.

Step 4: Profit!

So, how to get the base utilities working again?  The compiler wouldn’t run with the same errors, and higher level stuff like emerge was failing anyway so rebuilding the system wasn’t going to be easy.  Finally I decided to reboot from the Gentoo CD, download a new stage 3 install which I could extract to the USB drive and then copy across to the HDD the apps that weren’t working.  As the Stage 3 installation was built for a generic x86 processor, these were sure to run.  I just didn’t want to copy over my configuration so I couldn’t do a simple extract.

A few reboots later, and chasing down all the files that were necessary to copy across I had a functional compiler and functional emerge, even if the system still wasn’t booting very cleanly (Stage 3 only contains a minimum set of apps).  From there it was a simple matter to rebuild the kernel with networking drivers to get the system back onto the internet, some hacking of the udev rules to convince it which adapter was eth0 and which was eth1 (it picked eth4 and eth5 to start with for its own private reasons which escaped me at the time), and a few specific emerges to rebuild critical utilities that I didn’t want to be without for the time to fix the entire system (ie my email).

Once it was all up and running, I could issue the grandaddy of all Gentoo rebuild commands:

emerge -uDNe world

It almost worked.  I had to mess with l7–filters and iptables not having their dependencies set up properly but fortunately “emerge —resume” works to restart the last failed merge so you can merge in specific packages when needed.  After that, a quick 18 hour build process saw some 600 packages rebuilt with Athlon XP as the target system instead of Pentium 4, and a reboot showed everything up and running cleanly.

So, that’s how you move a Gentoo box to a system which doesn’t have the same instruction set.  Wasn’t the smoothest transition, but I didn’t lose any email and really only suffered a few hours effective downtime.  Not bad overall!

Leave a Comment