How to Switch Between Linux Distros Without Losing your Data

Switching between Linux distributions can be hard when you’re preserving user data. Many users have ways to combat this: cloud storage solutions, external hard drives, flash drives, home servers, etc. However, none come close to just giving the home directory its own isolated space so that it is safe from being wiped away.

In this guide we’ll go over how to break out a home directory from an existing installation and protect it from future installations. It’s a tedious but simple process that is rewarding.

Note: if your hard disk already has a secondary partition that you want to move the “/home” directory to, you can follow this tutorial to migrate to the Home folder.

Unfortunately, editing an existing Linux system is not possible without a live disk. Linux does not allow resizing and the changing of filesystems while they are in use. Luckily, there are many good partition live disks out there. The Gparted live disk is based on Debian and gives users a live partitioning environment to use. Download it here.

linux-home-directory-gparted-download-page

Download Etcher and make a live disk. The instructions on how to use the Etcher tool can be found on the download page. Alternatively, get a blank CD/DVD to burn the live disk.

Configure your computer’s BIOS to load the Gparted live USB. For some, the button is either ESC or Del, while others are F2. It may be best to look up information on the machine’s BIOS to load it up. Then, configure it to boot the live USB.

When Gparted live boots up, it takes the user through selecting the keyboard map, etc. Select the keyboard map applicable to your region and continue on to the next screen. Soon after, the live disk asks which mode you prefer. Enter the command startx. This opens the Gparted graphical environment.

To extract the home directory, file systems need to be mounted. Open the terminal on the Gparted live environment, then run the lsblk command to print out devices available on the machine. With the devices printed in the terminal, determine which is the main system directory that holds your “home.” It is usually the largest partition.

linux-home-gparted-resize-root-partition

Now that the filesystem is known, go back to Gparted and find this same partition. Right click on it and select “resize,” then use the tool to shrink it down. Click the “Apply” button to apply the changes that were made. With the system partition shrunken, new free space will appear. Use this free space to make a new partition. Do this by right-clicking on the free space, then clicking “new.”

linux-home-gparted-create-home-partition

By default, Gparted should select Ext4 as the file system and use up all the free space available. All that is left is for the user to enter “Home” in the label option, then click “add” to create the partition. When done, click “Apply” to add the changes.

Note: in this tutorial “/dev/sda1” will be used as the “/” directory (also known as the root directory. The current “/home” directory is also in this partition) and “/dev/sda3” as the new “/home.” Yours may differ, and you may need to change “/dev/sda3” to something else, depending on your partition layout.

In the terminal, enter the following commands to mount the disk:

First, directories need to be made to mount both “/” and the new “/home.”

Now, mount the two partitions to the created directories.

Next, move the contents of the home directory to the new partition. Do not move “home” itself. It must stay where it is.

After moving the contents of the home directory to a separate partition, it is now possible to reboot if the user is planning on installing a new Linux installation.

The important thing to note is that to keep this home partition safe, always do a custom installation and chose the newly created home directory as a mount point during installation. DO NOT FORMAT it and always select the option that allows new installations to not touch the ”/home” partition.

See the following image for an example.

linux-home-directory-existing-home-installation

So you’ve moved your home directory outside of your root partition, but you have no intention of re-installing. To keep using your system, enter the following commands in the Gparted terminal.

Add a comment (#) above your fstab edit. This makes it easier to note what filesystems do what in the file.

Give the new partition the “/home” mount point.

Not many people talk about it, but having a separate home directory is a great idea. With it, it is very easy to jump between Linux distributions without needing to fuss with backing up data or worrying about losing everything. If you’ve been looking for an easy way to accomplish breaking your home directory out of it’s cage, this guide is for you!

Image credit: vavco.ir

13 comments

  1. As a distro-hopper I have learned long time ago to keep my ‘/’, ‘/swap/ and ‘/home’ partitions separate. I used to partition all my disks with a 20 GB ‘/’ partition and a 4 GB ‘/swap’ partition. Whatever is space was left on the drive became my ‘/home’ partition. This setup has allowed me to install any size distro, from TinyCore to PCLinuxOS Full Monty, on the same drive without having to worry about re-partitioning or running out of space for the root system.

    Recently I started using an entire 40 GB SSD as my ‘/’ and a mechanical HD for my swap and home. Using the HD saves wear and tear on the SSD and the SSD provides me with a much faster boot(s).

  2. Handy article. Wish I’d found it back when I’d first decided to install Linux. Maybe I wouldn’t have accidentally trashed the only OS that was already on my PC. But then, it was only winVista, so I wasn’t too bummed.

  3. Won’t this procedure also put user configuration files onto the /home directory? What if the other distro you are installing needs some different configuration and you are multi-booting?

    • I ran into that problem with conflicting config files. So now I use a /home on the distro’s partition, then use a big data partition for all my good stuff. The only problem is mounting at bootup which I haven’t figured out yet; bookmarking it, permissions, all that. So now I just manually mount it. Also, there’s stuff like my boot screen (grub-customizer) that runs on one distro so I have to boot that to change it.

      • What desktop (KDE, Gnome, etc.) are you using?
        In KDE — you can try System Settings -> Hardware -> Removable Drives -> Disconnected Devices see if your data partition is listed. If it is, check the “Automount in Login” box. See if that helps.

        If that does not help, maybe you can write a short Bash script to mount the partition and have the script executed by the init process.

        • I’m running Ubuntu MATE which is gnome 2 based I hear. Anyhow, I have “Automount on login” checked, to no avail. Might be a bug so I’ll pursue it.

          • SOLVED…. So, on my Ubuntu MATE, I went to Control Center->Hardware->Disks-> clicked on my disk and partition I wanted to automount, found the “additional partition options” button, “edit mount options”. The partition was set to Automatic mount ON, and Mount at startup (but can’t change, grayed out). Well, switching to Automount OFF, with the Mount at startup still checked, it does actually automount at startup. (It changes the /etc/fstab file.) GUIs are wonderful, when they actually work how you’d expect.

  4. I keep my data on separate spinners, not on the OS SSD, and symlink the various directories (Videos, Music, .pan2, etc.) into $HOME after removing the corresponding directories. Nearly everything else in $HOME is OS-specific or GUI-specific and will cause problems if you preserve it. This also simplifies backups.

  5. Thank you for the article. Would it be advisable to say a few things about root home and user home locations? As I understand it root and user home directories are not co-located.

  6. I though about trying this option but i was,worried about
    The simlinks issue after reading a guide years ago . If a user eanted to upgrade from mint 18 to mint 18.1 would the simlinks have issues? I am sure the upgrade installer assumes the home is in the root.

  7. @Col_Panek What’s a GUI? (I’m a retired Unix sysadmin :-) ) The simple answer is as described in the article, just add ‘/dev/sda3 /mnt/home ext4 errors=remount-ro 0 1’ to /etc/fstab. Create /mnt/home first.
    As others have noted, configuration files are invariably different so don’t mount it on /home.
    Roland’s idea is the way to go, but first as root do ‘chown $USER: /mnt/home’ (after it’s mounted, not before), then from your $HOME simply do: ‘rmdir ; mkdir /mnt/home/; ln -s /mnt/home/ ‘ for the directories you want.
    This does rely, however, on you being the only user. If you want to accommodate other users, then you’ll need to have another level, ie /mnt/home/USER/ – again, using root, chown each USER directory, but leave /mnt/home as owned by root.
    Then there will be another gotcha – make sure that each USER in the different distributions has the same UID – as long as you create users in the same order on each distribution, this will likely be the case – the first user, you, will be UID 1000, the next is 1001 etc. But check! This is because linux uses $UID to identify owner permissions, not $USER.

    The situation with grub is interesting (I haven’t used grub-customiser, plain screens do for me) – each time you upgrade a system, it will rebuild the grub loader, and should still pick up all the others, but the order in the menu will change. I set GRUB_SAVE_DEFAULT in each distribution, and from memory (I could be wrong) this does seem to remember which one was last used even if the order has changed.

    @jj root’s home is /root, just leave this alone. This might depend on the distribution in use, but generally you shouldn’t be using root, certainly not for ordinary use. Use sudo.

    @Dave Not an authoritative answer, but Mint is based on Ubuntu, and I see no reason why an upgrade would want to have anything to do with the user home directories. Upgraded versions of GUI software might change configurations when they run, but the plan is to have all the config files in the true /home anyway.

    One more point. I have set up several partitions/distributions with a common /var/www. The Ubuntu-based ones caused a problem. During installation, I specified the partition as /var/www, without selecting the format option, as recommended in the article. Ubuntu didn’t format it, but just deleted all the files in it instead :-( In my opinion, best not to specify your /mnt/home at all during the install, leave it as unused, then add it to /etc/fstab on first boot.

    • Small error in my post –
      ‘rmdir ; mkdir /mnt/home/; ln -s /mnt/home/ ‘ should have been ‘rmdir DIR; mkdir /mnt/home/DIR; ln -s /mnt/home/DIR DIR ‘
      I’d used ‘dir’ enclosed in angle brackets, seems the editor stripped them out .

Comments are closed.

Sponsored Stories