The pain-free guide to switching distros
In depth: The most recent official count of Linux distros put the number at 'one hell of a lot'.This is good because it gives us plenty of choice, and choice provides freedom and freedom is good, right? Maybe it can feel as if there's a little too much choice at times, but there's no doubt that the huge variety of distributions makes Linux more interesting. However, trying different distros isn't as easy as experimenting with a new web browser, word processor or even desktop environment.
Switching to a different distro means formatting at least part of your hard disk and starting again with configuration of your system. It could also wipe out all of your personal files, depending on how your disk is partitioned.
You can use a virtual machine like VirtualBox to try new distros, but when you find one you like, it's time to bite the bullet and install it for real. The process of switching distros is largely the same whatever system you want to install, but differences between the way various distros organise themselves mean that there are inevitable variations.
We'll use the transition from Ubuntu Hardy Heron to OpenSUSE 11.0 as an example, but the basic steps are the same with most combinations of distros.
We'll be going from this...
...to this, with the minimum of fuss.
The main drawback of a new installation is that it reformats your filesystems, destroying whatever files were on them. That's fine for the distro itself, but what about your personal files?
The most important asset when switching from one distribution to another is a separate partition for /home. Not only does it prevent your personal files and settings from being destroyed when you're installing a different distro, it also gives you somewhere to save useful information, such as backups of system configuration files.
Without a separate /home partition, you need to back up everything before you start, and you can forget any idea of running a realistic dual-boot system with two distros in use at once.
A /home of your own
While a separate /home partition is a good idea, either when switching or dual booting distros, you should use a different home directory (the /home/username directory) for each distro. This is because some of the settings files in your home directory can be specific to one particular distro, desktop environment or program version and trying to apply them to another can cause problems.
To solve this we use a new directory on the same home partition and copy over only the files we want to share. If you don't already run a separate /home, it's time to divide your programs and data.
Set up /home
As always, when you're messing around with disk partitions and file systems there's a small - but real - risk of losing data. The risk isn't from the software you use; the danger is that the process might be interrupted by a power failure or another piece of software crashing the computer. If in doubt, back up first. Working with in-use file systems should be avoided, too - a Live CD/DVD is best for this, and we'll use the Ubuntu disc.
There are three stages to the process: resize your root partition, create a new /home partition in the space made available and move your data over. It's a lot easier if you have plenty of free space - if your drive is nearly full, move some files to DVDs or an external disk. Then run GParted from System > Administration > Partition Editor.
Partitions can't be resized when mounted, so if a mount point shows alongside the partition in GParted, right-click the partition and select Unmount. When resizing a partition, it's normally only possible to move the end point, so start by dragging the end of the root partition to the left until it's the size you want.
It's considered good practice not to fill a partition beyond 80%, as filling that last 20% can lead to fragmentation. But remember that you're going to remove the contents of /home after resizing, so you can probably pull that slider as far over as you want.
You can delete the swap partition for now, too - the installer will create a new one for you, after right-clicking it and selecting Swapoff from the menu.
Now, create a partition in the vacated space. There's a limit of four primary partitions, so use logical partitions whenever you can. Press Apply to start the process - this is the risky part and it's best to leave the computer undisturbed.
Once you've created the new partition, it's safest to reboot to the Live disc again, to make sure the kernel knows about the new partition layout.
Now, you need to move the files from the old /home directory to the new partition. This must be done as the root user, so open a terminal and type sudo -i to become root. If the root partition is on /dev/sda1 and the new partition on /dev/sda6, the commands to make the copy are:
mkdir -p /mnt/ mount /dev/sda1 /mnt/root mount /dev/sda6 /mnt/home rsync -a /mnt/root/home/ /mnt/home/ rm -fr /mnt/root/home/*
This assumes you have a relatively small amount of data in the home directory, otherwise you won't be able to shrink the root partition as much as you need and will have a lot of wasted space after moving the file.
If you can't move some of this off the main disc, say to DVDs or an external drive, an alternative is to create your new home partition at the end of the space made available by shrinking the root partition, making it just large enough to hold your files.
After moving the files, you can shrink the root partition further, create a third partition in the vacant space and move your home directory to that. Now, delete the partition at the end of the disk and resize the home partition to use its space.
Keep your config
A separate home partition keeps your user settings safe, but what about those system configurations you've got just right? If you've tweaked your xorg.conf or Samba setup, you don't want it to disappear forever. System settings are stored in /etc, so the easiest option is to back up this directory to your /home partition.
sudo tar czf /home/ubuntu-etc.tar.gz/etc
will archive all of /etc into a single file in /home. Sudo is necessary because some of /etc can't be read by a normal user: /etc contains sensitive information that only the superuser should be allowed to read. You could copy the directory with
cp -a /etc /home/ubuntu-etc
but an archive is probably more convenient. You might be tempted to copy only files you need, but you may regret that later when you find you missed one. An archive of /etc doesn't take up much space - usually a couple of megabytes.
Which programs are you using?
Apart from customising the system and user configurations, the other main change made to a system is installing extra packages.
Keeping track of what you've installed is quite easy, but transferring this to the other computer isn't as simple because of the differences in the way distros package various programs. Some produce a single package for a program, while others split it into program, library and development packages.
Another obstacle is that the package list contains all installed packages, some of which are only needed as dependencies - possibly distro-dependent dependencies - of other packages that you may or may not want to install. The best advice is to read through the list of packages, exclude the obvious dependencies, such as anything starting with lib or ending in -dev or -devel, and pick out the programs you know you want to run. Let the new distro's package manager handle installing the correct libraries and other dependencies. Generating the list of packages depends more on the underlying package manager, so for any Debian derivative, use:
dpkg --list >packages.txt
Those with a distro that uses RPM packages can generate it with:
rpm --query --list >packages.txt
You can shorten the list by removing all lib* packages and those with -dev in the name, as these are generally only installed as dependencies. This produces a list on Ubuntu (there are two spaces following 'ii').
dpkg --list | grep -v -e '-dev' -e '^ii lib' >packages.txt
Gentoo users only need to copy the world file - /var/lib/ portage/world - which also has the advantage of not including dependencies, only end-user programs.
That covers packages installed through the package manager, but what if you've installed from source, or even binary packages? Binary packages usually install to their own directory in /opt, so a listing of the contents of /opt will cover this
ls -1 /opt >binary_packages.txt
Packages you compiled from source are a little more tricky, but anything installing with ./configure && make && make install will install to /usr/local unless you mess with the PREFIX setting for ./configure.
ls -l /usr/local/bin >source_packages.txt
should catch most, if not all, self-compiled programs. With the lists stored, you can recreate the software collection on the new distro.
Installing the new distro
While we'll be using the same /home partition, we don't want to use the same home directory for your user. Each distro can contain different versions of the same software, even specially modified versions, and blindly sharing all configuration files can cause problems.
If you plan to use a different username on the new setup, there's no problem. Otherwise, you should rename the home directory to something like username-buntu. This is best done from a Live CD, such as the OpenSUSE installation disc. After installation is complete, we'll copy over the data files as well as some of the settings.
Now that your home files and system configurations are safe you can install the new distro in the usual way, but make sure you tell it to use your existing home partition and not to format it - when we tried it, the OpenSUSE installer wanted to delete both the root and home partitions.
Click on Create Partition Setup to specify what goes where and make sure only the root partition is to be formatted. Double check that /home won't be formatted and then proceed with the installation as normal.
With your permission
Wait for the installation to complete and reboot and you'll be presented with your new OpenSUSE desktop (or whichever distro you've installed), which will be set up with a new account for your user.
If you look in /home, you'll see directories for your user and the old user directory that you previously renamed. If you open the Properties window for each of these and check the Permissions tab, you'll probably see that the ownerships don't quite match up.
In the case of the Ubuntu to OpenSUSE switch, they have the same username but different groups. The reason for this is that Linux filesystems store the user and group information numerically, and this is translated to user and group names using the information in /etc/passwd and /etc/group.
So, even if you used the same username, the new distro may have allocated that to a different user ID (UID) and the same for groups. There's a further twist with groups: some distros put everyone in the users group, while others create a new group for each user, with the same name as the user.
As you only need to use the files from the old distribution with the new one now, you should change them all to match the new user. This needs a terminal and root access. If your username is jim, run su to become root and type:
chown -R jim: /home/jim-ubuntu
The -R causes chown to recurse through all files and sub-directories in /home/jimubuntu; the colon : following the username tells chown to also set the group to jim's primary group. If you have more than one user, repeat this for each.
Retrieving your files
This is one of the reasons we didn't simply re-use the old home directory - if the file ownerships are far enough out, you wouldn't be able to launch the window manager.
The other reason is that some files are specific to the distro, particularly those for the desktop environment. However, you can now copy over configurations for some of the 'standard', distro-independent programs, such as OpenOffice.org, Firefox and Thunderbird.
The directories you need to copy for these are .ooo-2.0, .mozilla and .thunderbird, although Ubuntu uses .openoffice.org2 and .mozilla-thunderbird, so you'll need to rename them. You can move the directories with the terminal or a file manager, but anything beginning with a full stop is hidden by default in file managers, so you'll need to enable the option to show hidden files.
You can also transfer data files, like your music and video collections, digital photos, word processor documents and spreadsheets - now's a good time to do some tidying up, delete old files and organise others into meaningful directories, just like you've been promising to do for years.
If you want to copy entire desktop environment configurations, like the .kde directory, keep a backup of the original directory for the new distro in case things don't work as you expected.
Themes, wallpapers and fonts
If you've installed any wallpapers, you'll probably want to move these over, although themes are only of any use when using the same desktop environment. Gnome themes from Ubuntu won't be a lot of use with OpenSUSE's KDE 4 (for that matter, neither will KDE 3 themes).
Transferring themes can be a tricky task, because installing a theme can place files in various directories. Missing just one of these can cause problems, so the safest option is to reinstall the theme from scratch.
Many are available as packages for various distros, or you can download them from www.kde-look.org, www.gnome-look.org or a similar site for your preferred window manager.
Wallpapers and system sounds are standard graphic and audio files, so you can use those with any desktop and distro. There are no standard locations for wallpaper images, as they are simply added to the list of available files or directories in the desktop's configuration program, available by right-clicking on the desktop.
We're sticking with KDE here, keeping our wallpapers in .kde/share/wallpapers, but you can put them anywhere you want, as long as you remember where. The same goes for system sounds, the default sounds used by Gnome and KDE are installing into specific directories in /usr, but user sounds can be installed anywhere in your home directory.
Fonts can be installed globally or for a user. KDE users can type fonts:/ into Konqueror's location bar to see a listing of either set. The user fonts are stored in .fonts in the home directory, and you only need to move them to your new home directory to make them available.
If you've installed fonts into the system directory, either /usr/share/fonts or /usr/local/share/fonts, you should copy them to your user directory before installing the new distro, as everything in /usr will be deleted. Fonts installed to /usr/share/fonts have usually been installed by the package manager, so you may prefer to let them disappear then install them from the new distros packages.
We have looked at copying your personal data and settings, with one significant exception: email. If you're using Thunderbird and intend to do so with the new distro, don't worry - we copied the hidden .thunderbird directory earlier.
It's usually a good idea to stick with the same mail program when you change distro, because they don't all store mail the same way. If you intend to use the same program, you can move over your mail directory after reinstalling, which means that your mails and settings wil be preserved.
If you want to change programs and you use POP3 mail, you may have to export and import your mail. Some programs have a specific export option, but with others you should select all mail and then save them, which will save them as mbox files (virtually every mail application has an option to import mbox files).
If you use IMAP things are much simpler, as all mail is stored on the server. Copies are cached locally to speed things up, so there will be a delay when you first use your new mail program and it has to download copies of your mails again, but your mail will still be exactly where you left it.
Providing you set up a separate partition for /home, and you only need to do this once, changing distros is not a daunting task. It is easier with some forward planning, backing up configurations and package lists, but it's fairly straightforward to switch from one distribution to another without disrupting your data, and it gives you the chance to try as many distros as you like!
We have covered moving from one distro to another without losing your settings and data, but what if you haven't made up your mind which distro to use yet? You may want to install a new one but keep the old one available in case you change your mind. Dual booting multiple Linux distros is an easy as switching between Linux and Windows, but some care is needed in sharing your data.
First of all you have to use different home directories, say /home/jim-ubuntu and /home/jim-suse. The usernames can be the same; there is no requirement for the home directory to be /home/username; and they must have the same user IDs.
The other issue is the bootloader, as most distro installers do not add other Linux distros to their boot menu. Install OpenSUSE or your chosen distro as previously and when you get to the bootloader part of the installation, tell it to install to the root partition, not the MBR of the disk.
When you reboot, you will go straight back to Ubuntu, so you need to add a SUSE option to the Ubuntu bootloader. Open a terminal and run
sudo gedit /boot/grub/menu.lst
to load the bootloader menu into your editor, and add these lines to the bottom:
title openSUSE root (hd0,5) chainloader +1
This adds an OpenSUSE option to the boot menu. The root command tells it where to find the SUSE installation. Grub counts from zero, so hd0,5 is the sixth partition of the first drive - /dev/sda6 in Linux terms. The chainloader command tells it to load the bootloader from that disk, which will give you the SUSE boot menu.
Now you need to make sure the user IDs are the same, so mount the SUSE partition with
mkdir -p /mnt/suse mount /dev/sda6 /mnt/suse
Then look for your username in the /etc/passwd files on both computers:
grep jim /etc/passwd /mnt/suse/etc/passwd
Each file should contain a line like this:
The first number is the user ID and the second the group ID, if they differ you need to edit /mnt/suse/etc/passwd to make them the same. Check /etc/group for the two distributions to make sure the group ID for the users group matches on both. Then run
chown -R jim: /home/jim-suse
When you're keeping the old distro you can't just move directories of data from one home directory to another: you want it available to both. The answer is to use symlinks, or symbolic links. These allow one directory (or file) to appear to be in two places. Simply do
ln -s /home/jim-ubuntu/music /home/jim- suse/music
...to have the music directory appear in both home directories. With KDE, you can do this by dragging the music icon from one home directory to the other and holding down the Control and Shift keys when dropping it.
Repeat this for any data directories you wish to share, but only do it for mail if you are using the same mailer on both distros.
First published in Linux Format magazine