Do you find yourself switching between Linux distributions frequently? When upgrading, do you favor clean installations over in-place upgrades? Do you hate that you have to back up all your personal data, or else lose it?
What if I told you that this doesn’t have to happen?
It’s actually quite easy to switch between different Linux distributions or perform clean installations and still retain all of your personal data. We’ll show you what to do so that you’re all set up no matter your current situation.
How Does It Work?
What’s the magic that lets you keep all your personal data? Simple: separate partitions.
Whenever you install Linux, you have to tell the installer what partition setup you’d like to have on your hard drive. If Linux is the only operating system on the hard drive, you’ll most likely have one or two partitions. This includes the main partition, usually formatted as ext4, which includes the operating system and all of your data.
Optionally, you can also have an additional partition called the “swap partition.” All it does is allows a portion of your hard drive to be used as RAM overflow space, as well as the location where RAM data is stored during hibernation.
However, you have the freedom to create as many partitions as you’d like, and you’re also able to tell the installer which partitions should be used for which folders. In order to achieve the effect that we want, we’ll need to create an additional ext4-formatted partition. The first one should have “/” (the root folder) mounted to it, and the other partition should have “/home” mounted to it. All of your personal data is stored in the “/home/<user>” folder, so that means all of your personal data will be stored in the second partition.
Once you’re wanting to change Linux distributions or perform an upgrade, you’re free to wipe out the first partition that contains the operating system and your installed applications. However, the second partition that has all of your personal files and preferences can remain untouched.
Next, when you perform the new Linux installation, you can tell the installer to reformat the first partition (to start from scratch), but leave the second partition alone and just mount it to “/home”. Then, all you need to do is make sure that you set up the same username and password as before, and everything should be back to the way it was.
The only thing you’d still have to do is reinstall your applications, but you won’t have to reconfigure them because their settings were stored along with your other personal files. The only downside to this is that keeping the settings while switching between distributions may cause incompatibilities. For example, although Fedora and Ubuntu both use GNOME as the default desktop backend, Ubuntu’s implementation is quite different, and settings from Fedora could get messy. Be aware.
Make sure that when you are giving the two partitions space, you give each of them enough room. If your first, root partition is very small, you won’t be able to install very many applications, and if the second partition is too small then you won’t have much room to save your personal files. The partition sizes are hard limits.
I’d suggest you give your first partition 15 or 20GB of space, if you don’t plan on installing a lot of applications. If you plan on installing many applications or games (which take up substantial amounts of space), then you’re better off with 50+GB. Gamers should look at the games they’re interested in installing and add up how much space each one takes up. If you find that your partition sizes weren’t appropriate for your usage, you can always resize them by booting into a Live environment and running a partitioning tool.
Already Have Linux Installed?
If you already have a Linux installation in place and have everything (including your Home folder) on the same partition, don’t worry. It only takes a few steps to achieve the setup you need. The steps are as follows:
- Download the Live environment ISO of your favorite Linux distribution, and burn it to a CD/DVD or write it to a USB drive.
- Boot into your newly-created media.
- Use a partitioning tool such as GParted to resize your ext4 partition to the size you want it to be.
- Use the same tool to create a new ext4 partition in the empty space created by resizing the first partition. Make note of what partition it is. It should look like
/dev/sdXY, where X is a letter designating the drive and Y is a number designating the partition. An example is
- Mount both partitions, and copy over the contents of the home folder to the new partition. Make sure that you’re copying over all of the contents of the home folder, and not the home folder itself. Otherwise, when everything is done, all of your stuff will be in “/home/home/user”, which won’t work.
- Now open a terminal and run the command
gksudo geditto open the Gedit text editor. Now use the menus to open the file located at /etc/fstab in the first partition.
- Add the following line to the end of the file:
/dev/sdXY /home ext4 errors=remount-ro 0 1. Again, make sure to replace
/dev/sdXYwith the actual designation for the partition.
- Save it, and restart. Make sure to remove the Live environment media so that you boot back into your regular installation.
The different won’t be obvious, but your personal data will now be on a separate partition which will stay out of the way while switching distros or performing upgrades! I definitely recommend that people try to do this, because the benefits far outweigh the single drawback of restricted space within the partition. However, you’re always able to fire up the Live environment and resize the partitions as needed.
Have you placed your home folder on a separate partition? What tips do you have for readers when they’re doing their own partitioning? Let us know in the comments!
Explore more about: Linux Distro.