HowTo: Clone your Ubuntu 8.04 installation for easy 8.10-upgrade tests
In about 27 days, the new Ubuntu 8.10 will be released. The beta has been released yesterday. I have some spare time, so I’m using it to do an upgrade test for my installation. I don’t want my main system to be changed (or destroyed), so I’m first cloning the Ubuntu 8.04 installation on my laptop, then upgrading that clone to Ubuntu 8.10 beta.
There are two reasons why you’d want to do that:
- Check for yourself if the upgrade will work out alright when 8.10 is released, by testing without much risk.
- Test the upgrade path on your system, filing bugs if things don’t work out well, to improve Ubuntu. Which is what I want to do.
I have used this clone/upgrade path in older releases, I’m pretty sure it will also work in the future. It should also work in other distributions.
Disclaimer: I cannot be held responsible for any damage this HowTo may cause. You are on your own. Only follow the steps if you know the implications of following them. This is dangerous stuff and can destroy your data!
First, backup all your data on your installation. If anything goes wrong, you need to have a safe place for your data! There are many ways to do that, I usually rsync to an external disk.
I now delete everything that I don’t need for the test, but you don’t need to do that. It will make the process take less time though, because there’s less data to clone. DO NOT DELETE IMPORTANT DATA! I only delete music, photos, videos and documents, which are only 1:1 copies of my workstation’s data anyway.
Boot your system from an Ubuntu LiveCD. We’re going to partition and copy the partitions from there.
Now it gets a bit difficult. You need to create new partitions that can take at least the used amount of space in your old partitions. For example, my setup is:
- /dev/sda1: 5 GB on /, 2.67 GB used
- /dev/sda2: 2 GB swap
- /dev/sda3: 142 GB on /home, 8.17 GB used
Swap can be re-used in the new installation, but the other two have to be cloned. So in this case I resized sda3 to have 15 GB of free space. Then I created (in the free space) a new extended partition (disks can only take 4 partitions, so I need this “partition container“) sda4. In this container, I created sda5 (5 GB, my new /) and sda6 (10 GB, my new /home). If you are going to use the upgraded installation for more than just playing around, reserve more space. If you have only one partition, only create one clone partition. It really depends on your setup.
All of this can be done in Partition Editor which comes with every Ubuntu LiveCD.
After some time, the new partitions will be there. Don’t forget to write down your disk partitioning, or leave the Partition Editor open.
Open a terminal. Create directories for your partitions, but name them to resemble their function. It’s more foolproof like that.
mkdir old_root old_home new_root new_home
Now, mount all the partitions:
sudo mount /dev/sda1 old_root/
sudo mount /dev/sda3 old_home/
sudo mount /dev/sda5 new_root/
sudo mount /dev/sda6 new_home/
That’s about it. Now we need to copy the stuff over, bascially cloning your installation:
sudo cp -av old_root/* new_root/
sudo cp -av old_home/* new_home/
“-a” means it will preserve links, file mode/ownership/timestamps, and copy recursively. Make sure the partitions you copy this way don’t have any files like “.file” in them, or copy them over manually, because the “*” won’t match those.
Of course, the last 3 steps really depend on your setup. If you have more or less partitions, you need to adjust the commands, but you should get the idea.
Depending on the amount of data and speed of your disks/machine, this can take some time. Grab a coffee!
When this is finished, you can unmount your old partitions, just to be safe:
sudo umount old_root old_home
First, we need to change the partition identifiers in the new installation:
sudo chroot new_root
nano /etc/fstab
Here, you need to set the UUIDs of your new partitions instead of the old ones. Swap stays the same. You can find the UUIDs through
sudo blkid
Save & exit from nano.
We want to upgrade the new installation, so grub (the boot loader) needs to be configured to run from the new installation:
nano /boot/grub/menu.lst
Copy and paste the list of boot options (title, root, kernel, initrd, quiet) - there should be 3, depening on your setup - below the line “END OF DEBIAN AUTOMAGIC KERNELS LIST“. Add something like “(old installation)” to the end of the “title” lines, so they differ from the new installation. Now, find a line that says:
# kopt=root=UUID=<text> ro
And set the UUID to be the UUID of your new root partition (found through blkid).
Find the line:
# groot=(hd0,0)
and change it to
# groot=(hd0,4)
(or whatever your new root partition is).
Now we need to regenerate the boot options list:
update-grub
Ignore the errors. They are caused by the fact that the environment is mixed between the LiveCD and your installation root. Yet, the /boot/grub/menu.lst should now contain both your new as well as your old kernels. Exit from the chroot shell:
exit
In the regular LiveCD shell, we now need to install the new boot loader:
sudo grub-install –root-directory=new_root/ /dev/sda
(Depends on your setup, /dev/sda might be another disk.)
And that’s it. We should now be able to boot into the new or the old installation. Try it out! (Press Esc before Linux boot to open the grub boot loader option screen.) Verify by typing
mount
in a terminal that you are indeed using the correct partitions in each case (because of the fstab change).
You now have two identical copies of the same installation. They could also be used as a failover over something, in case you hack the wrong file in the original installation.
What I want to do is upgrade the installation to the current development version: Boot into the new installation. Open a terminal. Type:
gksudo — update-manager -d
(”–” is necessary so the “-d” won’t be mistaken for gksudo’s “debug” option.) You should now get a notification that there is a new version available. By pressing the button you start the upgrade process. Realize that this is really what you want and that you are mostly safe because you are running a cloned install, and press it.
And that’s it for this HowTo. Upgrade, file bugs, test the installation however you like. Your old system is safe. In a couple of days/weeks I’ll write a HowTo on how to remove the clone and get back to the old setup (basically, it’s “remove new partitions” and “grub-install –root-directory=old_root /dev/sda”).
If you have questions/suggestions/thanks, don’t hesitate to comment.
Update:
I often have the problem that — when resuming my 8.04/8.10 dualboot laptop from hibernation — I choose the wrong Ubuntu version in grub. It can’t resume and wipes out the hibernation image from the swap drive. This is bad. Here’s a small workaround:
Before doing “update-grub”, open /boot/grub/menu.lst and change the lines
default 0
savedefault=false
to
default saved
savedefault=true
(They are not really next to each other, this is only to shorten the text.)
Also, add “savedefault” to the regular boot option of your old installation, before or after “quiet”. With these options, grub will recognize which was the last Ubuntu version booted, and will automatically load it the next time, unless changed manually. When resuming from hibernation, it will always load the appropriate Ubuntu version.


October 3rd, 2008 at 21:01
Less bolding, please!
October 3rd, 2008 at 23:02
Hehe, okay.
I’ll watch it. I usually use that to make scanning of the text easier.