Migrate a live server from Ubuntu to Debian remotely

You think I’m crazy, but yes, you can do it. The below instructions have been tested by me and worked flawlessly. I started out by doing a migration locally using a virtual environment and you should too.

In case you’re wondering why, basically, I have a server that does not have hardware virtualization support and I wanted to use Xen’s paravirtualization capabilities to manage virtual machines. Ubuntu server makes a great guest but it really prefers KVM over Xen and KVM, as far as I know, does not support machines like mine without the proper cpu instructions. Debian does have good support for Xen so I’m switching to it as my host (Dom0).

I’d like to say a few thank yous to the following people and groups who helped me:

Challenges:

My only issue not outlined in the steps below pertained to differing device names after the server rebooted. In my original installation of Ubuntu Server my network cards were eth2 and eth3, but in Debian they were eth0 and eth1. I’m not sure why this happened.

I performed this upgrade on a remote server some 2,000 miles away. The only access I had to it were via SSH. Reboots are done by filing a “reboot ticket” with the collocation facility. They usually respond quickly but I can’t expect them to do more than reboot the machine. Fortunately, they will hook a monitor up to the server and choose an option from the boot menu if I give them clear instructions.

Before you begin consider rebooting the server. If it’s been a while since a reboot then your server will likely run a file system (fs) check. Depending on the size of the fs this could take a while and there is nothing more un-nerving than making a configuration change and rebooting and waiting an interminable amount of time wondering if it worked or not. Also, if you can’t successfully reboot your server w/out manual intervention, fix whatever prevents it before making changes like this.

Assumptions:

  • You’re using Ubuntu Server 9.04 or newer and you installed using LVM and you are not using all of the disk. I repeat, you must have room to create a new LVM volume.
  • You have two primary partitions, one for the LVM volumes and one for /boot. This is the default for newer Ubuntu server installs.
  • We’ll be migrating to Debian Lenny using the Xen kernel
  • i386 architecture
  • No data will be lost using these procedures. The original Ubuntu installation will not be altered except for the installation of a few packages and changes to the boot menu.
  • The University of Northern Iowa’s Debian mirror is ideal for you. If not, use a different mirror.
  • My lvm container is called “ubuntu-xen-host”. Anywhere that you see it below, substitute it for your server’s. You can find it by looking at lvdisplay (2nd command in the instructions below) and is usually the host name of your server as set during the initial installation.
  • You are competent managing the server from the command line and understand what the commands below do. Take a min before performing the steps below to familiarize yourself with the commands so that  you understand them.

Doing the migration

Prepare the machine and install Debian Lenny

sudo apt-get install debootstrap
sudo lvdisplay
sudo lvcreate -L 8G -n debian ubuntu-xen-host
sudo mkfs -t ext3 -m 1 -v /dev/ubuntu-xen-host/debian
sudo mkdir /mnt/debian
sudo mount -t ext3 /dev/ubuntu-xen-host/debian /mnt/debian/
sudo debootstrap lenny /mnt/debian/ http://debian.cns.uni.edu/debian #
takes a while to download packages
sudo mount --bind /dev /mnt/debian/dev
sudo mount --bind /boot /mnt/debian/boot
sudo chroot /mnt/debian/

We’re now in a chroot environment that will soon be our running server

mount -t proc none /proc
mount -t devpts none /dev/pts
apt-get install ssh locales initramfs-tools vim
linux-image-2.6.26-2-686 lvm2 madam # takes a while to download
packages
# you will get a warning about unsigned packages - enter "Yes"
# you will see many errors about locale and $LANG, ignore for now
# choose "No" to "create a symbolic link to the current kernel image
# choose "No" to "abort initrd kernel image installation?"
# watch the output to make sure that an init ramfs is created - you need  this
# it takes a moment so you'll probably see a message, "Generating
/boot/initrd.img…"
dpkg-reconfigure locales
# choose at least en_US.UTF-8 (unless you prefer another language)
# set the default to your chosen language, i.e. en_US.UTF-8
passwd # set the root password
adduser matthew # substitute your user name
exit # to leave the chroot environment

Copy some configuration information to the new fs

sudo cp /etc/network/interfaces /mnt/debian/etc/network/interfaces
sudo cp /etc/hosts /mnt/debian/etc/hosts
sudo cp /etc/fstab /mnt/debian/etc/fstab
ls /dev/disk/by-uuid/ > /tmp/uuid.list
sudo vim /mnt/debian/etc/fstab /tmp/uuid.list
## in an editor (vim here) change the uuid for the / partition to be the UUID of the newly created "debian" partition
sudo vim /boot/grub/menu.list
## in vim add the new kernel to the boot menu as the first option
changing the root=… part to match the new filesystem you created
## uuid should remain these same as it should be pointing at your
/boot partition
## also change the kernel path - for example, /vmlinuz-2.6.26-2-686
## and the initrd path to match
## also you may want to comment out the line that says "hiddenmenu"

Now reboot and make sure to choose the newly installed debian from the boot menu.

When the server is ready log in as a user w/ root permissions and then install grub on the new fs using:

apt-get install grub
grub-install --no-floppy --recheck /dev/hda

You can now mount your old filesystem and recover any important data. When you’re ready to reclaim the space you can remove it using:

lvremove /dev/ubuntu-xen-host/root

That’s it, you’re done. It worked for me, your mileage may very. Leave a comment if you have a question or if you benefit from this.

Comments
One Response to “Migrate a live server from Ubuntu to Debian remotely”
  1. Matt says:

    By the way, if you use Landscape to manage your machines you can now upgrade the operating system through the web. Nice work Landscape team!

Leave A Comment