thefoggiest.dev

Server migration: taking a shortcut

Yesterday evening, I migrated this server (the one you’re reading this blog on) to a new machine. I had only a few seconds down time, and it took me less than three hours. Here’s how I did it.

As you can read on my homepage, I use this server for a number of things, like running a couple of websites/applications, some of which are open to the internet (like this blog). I also have a subversion server, a mail server, a boinc client, and many other things. The point is, all that took quite some time to set up originally. Having to do it again would take me days, if not weeks.

Yet, I needed another machine. The old one was a Compaq Armada E500 with 512 MB RAM and a 60G hard drive. While I still think old laptops are very nice low-traffic web servers (low power, internal PSU, usually silent), this one was getting a bit old. The screen became redder every day, a crack in the back was growing wider and the fact that there was only one (slow) USB port made it unsuitable to use it as a printer/backup server as well. Also, the slowness of the machine kept me from earning a lot of boinc credits contributing lots of calculating power to the Great Cause of Science.

So wednesday I bought a smallish HP Compaq Pentium 4 machine with a really silent hard drive. It still has only 512 MB RAM and the hard drive has only 40G (a third less than the Armada), but it is obviously a lot faster. Also, it has six USB ports so I can hook up all the external drives and printers that I want. Now all I had to do was put my server OS, Ubuntu 8.04 LTS, and all the software on it.

Obviously the easiest way was to copy the entire harddisk. But using Clonezilla or some other partition copier wasn’t going to work, for two reasons: first, the new hard drive is smaller, and second, the rest of the hardware is different as well. The laptop’s configuration was not going to work on the new machine. After googling around a bit, I found the solution. First I installed a minimalistic Ubuntu 8.04 LTS on it, in other words, exactly the same OS, but without most of the software and files. Then, I became root:

# su - root

Normally, on an Ubuntu machine, you can’t be root. But on a server machine I need to have root privileges most of the time, so I always enable the root account. I do that by setting its password:

# sudo passwd root

It will ask me my own password, and the new Unix password twice. The Unix password is root’s.

The next step was to put all the relevant directories of the laptop in a zipped tar file:

# cd /
# tar -cvzf backup.tgz --exlude=/backup.tgz --exclude=/etc/fstab /etc /home /opt /tmp /usr /var

This created a tar file with the home directories, the software (in /opt and /usr), the configurations (in /etc) and their files and databases (in /var and /tmp). I didn’t copy /dev, /boot, /mnt, /media and the kernel in the root since they are obviously machine-dependent. I also excluded /etc/fstab for the same reason. Ubuntu uses specific UUIDs for media so even if you have the same hardware setup, copying /etc/fstab will not work.

The resulting file was 2.3G, but luckily I own a 16G USB drive, so I mounted that and copied the file there:

# mount -t auto /dev/sdb1 /mnt/
# cp backup.tgz /mnt/
# umount /mnt

Copying took a very long time (~30 minutes I think), so I went on to enable the root account on the new machine and made some coffee. When copying was done, I put the USB drive in the new machine, and extracted the archive to its root, overwriting the archived directories:

# mount -t auto /dev/sdb1 /mnt/
# cd /mnt
# tar -xpzf backup.tgz -C /

I omitted the v (verbose) parameter, so that any error messages wouldn’t get lost in the stoud, but all went well. Next step was to reboot the computer:

# reboot

The machine came up fine. I logged in as root (all accounts had been overwritten by the laptop’s, but I had used the same password). First thing I tried was update the machine, but apt-get complained that there was no network connection. ifconfig Revealed it was right.

# /etc/init.d/networking restart

told me there was a problem with the network (eth0) device. So I grepped through the system messages for eth0:


# dmesg | grep "eth0"
udev: eth0 renamed to eth1

I had no clue what that was about, so I googled around (on my desktop machine) and found the solution.

Next I wanted to update the machine, but apt-get complained it couldn’t resolve the sources. Other programs (ping, wget) could, so I figured it was an apt-get specific problem. I found a fix here.

I rebooted again, and then Everything Worked. All I had to do to finish it was reconfigure my router’s port forwarding to the new machine, and turn off the laptop. Tomorrow I’ll start looking into backup solutions and configuring the CUPS server.


Categorised as: blog, howto


Comments are closed.