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.
Download the partition editor
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.
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.
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.”
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.
Extracting the home directory and mounting it
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.
Keep using current 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