How To Upgrade Debian Lenny (Debian 5.0) To Squeeze (Debian 6.0) On Xen VPS

Want to support HowtoForge? Become a subscriber!
 
Submitted by r_s (Contact Author) (Forums) on Mon, 2011-03-07 17:37. :: Debian | Xen

How To Upgrade Debian Lenny (Debian 5.0) To Squeeze (Debian 6.0) On Xen VPS

This tutorial shows how to upgrade a Debian Lenny (Debian 5.0) installation on a Xen based Virtual Private Server (VPS) to Squeeze (Debian 6.0) including kernel update, dependency based boot sequencing and conversion to UUIDs.

If you do it the usual Debian way just with apt-get dist-upgrade you will most likely end up with an unbootable system. This is mainly because the update of grub fails.

Limitation: You will not be able to update grub. You have to stay with your old grub version instead; this tutorial shows how to achieve this. If anyone found a solution for this issue, please submit a comment. However, comments and criticism is welcome anytime!

Disclaimer: Even if all the steps in this how-to were carefully tested, I do not issue any guarantee that this will work for you! Do this at your own risk. Do not try this in a production environment, do not try this if you do not have access to a serial console so you are able to reverse the steps, and back up your data or make a snapshot in advance! You may end up with an unbootable system!

 

0 Some Optional Steps

The following steps are not needed to upgrade to Squeeze, but they may be useful for some of you.

 

0.1 Adding A Swap File (Optional)

For those who run a VPS with very little RAM and swap space (<512 MB) like me, it may be nice or even necessary to extend the swap space.

The following commands will create a 2 GB swap file named swapfile in the root directory, format it and activate it:

dd if=/dev/zero of=/swapfile bs=1024 count=2097152 && mkswap /swapfile && swapon /swapfile

This adds a line to your /etc/fstab to activate the swap file automatically during booting:

echo "/swapfile none swap sw 0 0" >> /etc/fstab

 

0.2 Make Shell Prompt Coloured (Optional)

This command adds an entry to your /root/.bashrc which will give you a coloured prompt like root@host:/etc# after your next login:

echo "PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '" >>/root/.bashrc

 

1 Upgrade The System To Debian Squeeze (Debian 6.0)

Please make sure you follow all steps carefully. Do nothing else until you complete this how-to to the end. Especially, do not reboot until you are finished!

 

1.1 Update sources.list

Use the following entries in your /etc/apt/sources.list:

vi /etc/apt/sources.list

You should substitute the us with a mirror close to you. You may include additional sources for your needs after these lines.

#squeeze
deb http://ftp.us.debian.org/debian/ squeeze main contrib non-free
deb-src http://ftp.us.debian.org/debian/ squeeze main contrib non-free
# squeeze release replacement mirrors for volatile sources
deb     http://mirrors.kernel.org/debian squeeze-updates main contrib
deb-src http://mirrors.kernel.org/debian squeeze-updates main contrib
#security-squeeze
deb http://security.debian.org/ squeeze/updates main contrib non-free
deb-src http://security.debian.org/ squeeze/updates main contrib non-free

Run

apt-get update

 

1.2 Install / Update / Configure locales

We do this step in advance to get rid of annoying error messages like can't set the locale; make sure $LC_* and $LANG are correct during the installation:

apt-get install locales

Services to restart for GNU libc library upgrade:
[...]
<Ok>

dpkg-reconfigure locales

Select the locale(s) suitable for your use, in this example it is en_DK.UTF-8:

Locales to be generated:
[...]
[*] en_DK.UTF-8
[...]

Set the default locale:

Default locale for the system environment:
en_DK.UTF-8

 

1.3 Prevent Automatic Upgrade Of grub

The following commands will configure apt to not upgrade grub, grub-common and grub-pc (if installed):

echo "grub hold" | dpkg --set-selections && echo "grub-common hold" | dpkg --set-selections && echo "grub-pc hold" | dpkg --set-selections

 

1.4 Running dist-upgrade

Now we are ready to download and install the actual upgrade. Depending on your last update, there will be quite a lot to download and install. You will be asked several important questions during the installation, please read everything carefully. Run:

apt-get dist-upgrade

Just make sure that everything from step 1.3 is working properly by checking for these lines:

Calculating upgrade... Done
The following packages will be REMOVED:
[...]
The following NEW packages will be installed:
[...]
The following packages have been kept back:
grub grub-common
The following packages will be upgraded:
[...]
Do you want to continue [Y/n]? Y

Use dash or not, whatever you prefer, it does not affect the upgrade process:

Use dash as the default system shell (/bin/sh)?
<Yes>

Services to restart for PAM library upgrade:
[...]
<Ok>

Migrate to dependency-based boot sequencing:

Migrate legacy boot sequencing to dependency-based sequencing?
<Yes>

Use UUIDs instead of device names:

Update disk device IDs in system configuration?
<Yes>

Apply configuration changes to disk device IDs?
<Yes>

 

1.5 Edit /etc/fstab

vi /etc/fstab

Comment out /dev/pts and /dev/shm from /etc/fstab, otherwise the system will fail to boot:

[...]
# none             /dev/pts      devpts   gid=5,mode=620 0 0
# none             /dev/shm      tmpfs    defaults       0 0
[...]

 

1.6 Configure grub

Finally we have to configure grub to use UUIDs instead of device names.

cat /etc/fstab

Locate and copy the UUID of your / partition. Important: Copy the UUID from your fstab, not the one from this example:

[...]
# /dev/sda1        /             ext3     defaults       1 1
UUID=your-uuid-here        /             ext3     defaults       1 1
[...]

Back up the current menu.lst:

mv /boot/grub/menu.lst /boot/grub/menu.lst.backup

Rebuild the menu.lst:

update-grub

Edit /boot/grub/menu.lst:

vi /boot/grub/menu.lst

Replace all occurences of root=/dev/... with root=UUID=... by using the UUID string you copied from your /etc/fstab before:

[...]
## ## End Default Options ##
title		Debian GNU/Linux, kernel 2.6.32-5-xen-amd64
root		(hd0)
kernel		/boot/vmlinuz-2.6.32-5-xen-amd64 root=UUID=your-uuid-here ro 
initrd		/boot/initrd.img-2.6.32-5-xen-amd64
title		Debian GNU/Linux, kernel 2.6.32-5-xen-amd64 (single-user mode)
root		(hd0)
kernel		/boot/vmlinuz-2.6.32-5-xen-amd64 root=UUID=your-uuid-here ro single
initrd		/boot/initrd.img-2.6.32-5-xen-amd64
[...]

Double-check that you include the word UUID= followed by the number, not just the UUID itself!

 

1.7 Clean Up (optional)

You can remove automatically installed and no longer required packages if you are sure you do not need them anymore:

apt-get autoremove

 

2 Reboot Into Your New System

If you are sure you followed all the steps above carefully and did not get any error message, it is time to reboot into your new system now. Once again: I do not issue any guarantee that your system will boot, but I wish you good luck! ;-) If all else fails, you must access the serial console emulation of your VPS and revert the steps if you know what you are doing, or you must restore your backup or snapshot!

reboot

Have fun with Debian 6.0 Squeeze! Comments and criticism welcome!


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Wed, 2011-03-09 17:50.

Grub can be upgraded, but the default grub2 config is wrong for Xen. It is easyly fixed with:

mv -i /etc/grub.d/10_linux /etc/grub.d/50_linux
update-grub2

More info: http://wiki.debian.org/Xen#Installationonsqueeze