How to Set Up a Separate /home Partition on Linux

By creating a separate /home partition, Linux users can preserve personal files and settings during OS reinstallations, avoiding data loss and simplifying the migration process.

Christopher Tozzi, Technology analyst

September 27, 2024

5 Min Read
Linux written on top of code
Alamy

Are you a Linux user who has grown tired of having to replace all of the user-specific files and settings every time you reinstall your operating system? If so, there's a simple solution: creating a separate /home partition for Linux.

Here's why you might want to do that, along with steps on how.

What Is /home on Linux?

On virtually all Linux-based operating systems, /home is a directory that stores users' personal files and settings. This means that most documents, photos, videos, and so on live in /home. In addition, /home hosts application configurations for individual users — so a user's browser history and preferences, for example, are stored in the /home partition, as are the settings that determine what the user's desktop background and interface look like.

For the record, we should note that systemwide configuration files and settings — like those that control the behavior of a web server or database hosted on a Linux system — are typically stored in a separate directory (usually /etc, although this can vary across different Linux distributions). The data in /home is associated with specific user accounts.

Why Create a Separate /home Partition?

Normally, when you reinstall Linux on a computer or server that already has a Linux installation in place, you have to overwrite the original system's files and directories. (You could avoid this by installing multiple Linux systems side-by-side on the same device, but that's not always possible due to limitations on available disk space.)

Related:Linux Ransomware Threats: How Attackers Target Linux Systems

As a result, all of the data stored in /home is typically lost while reinstalling Linux. To preserve user-specific files and settings, you have to copy them from your /home directory to a different hard disk, then put them back in place on the new /home directory after your new Linux installation is up and running. You may also have to adjust file permission settings to make them compatible with the new installation, which can be a pain.

You can work around this issue, however, by setting up /home on a separate partition. A partition is a stand-alone region on a hard disk, and most disks can have multiple partitions of varying sizes. By creating /home on its own partition and keeping the rest of your Linux system on a different partition, you can avoid overwriting /home when reinstalling Linux.

This means that when you boot into your new Linux installation, all of your user files and settings will remain unchanged. In most cases, you won't have to restore any data manually or update file permissions.

Related:Linux UFW (Uncomplicated Firewall) Configuration Made Easy

How to Create a Separate /home Partition

The process for setting up a separate /home partition varies depending on which Linux distribution you're using. But it's usually pretty simple.

Here are the main steps. We'll use Ubuntu as an example, but the process should be more or less the same on any modern, mainstream Linux distribution.

1. Back up your data

Making changes to disks always carries some amount of risk, so if the drive where you're setting up a separate /home partition contains any sensitive data, back it up by copying it to a separate disk.

2. Create a partition for /home

With your data backed up, you can create a separate partition for /home. One way to do this is by booting into a Linux live USB and using a disk-managed tool like gparted, which can set up separate partitions. However, that's not usually necessary because most Linux installers provide partition management features as part of the installation process — so you can create a separate /home as part of installation.

For example, while installing Ubuntu, choose the "Something else" option when asked about installation type:

Linux-Home-Install.png

This will open up a screen where you can manage partitions. Click the + (plus sign) button to add a new partition:

Linux-home-free-space.png

This will open a dialog box that looks similar to the following:

Related:How To Secure SSH Access on Ubuntu Servers (Video Tutorial)

Linux-home-create-partition.png

Configure the settings in the box as follows:

  • Choose an appropriate size for your new partition. The size should be large enough to accommodate whichever files your users will store. (You can resize your /home partition later, but that's a complicated and somewhat risky process, so it's best to err on the side of providing adequate space when you initially create it.)

  • Set up the partition as a Primary partition.

  • Choose the beginning of the space as the location for the new partition.

  • Select a file system. Ext4, a widely used file system for modern Linux installations, is a good choice.

  • Select the mount point as /home.

Click OK to save your settings.

3. Create a partition for /

You'll then need to create a second partition by clicking the + (plus sign) button again. This partition will host everything in your Linux system other than the contents of the /home directory. The mount point should be /, which represents the root directory of Linux (which, confusingly, is separate from the directory /root, but we digress).

Here's a sample configuration for this partition:

Linux-home-partition-size.png

Click OK to save these settings, then click Install Now to proceed with the installation process. The installer may warn you about making changes to your disk; this is normal.

4. Reboot

Finally, after installation completes, reboot and you'll have /home on its very own partition. 

5. Reuse your separate /home partition during future installations

Now, whenever you want to reinstall or upgrade your Linux system in the future, you can do so without touching the contents of /home by reusing the partition you already created for /home — as opposed to installing the new system entirely on the / partition, or creating another /home partition.

One very important note: Be sure not to format the /home partition when reinstalling. If you do, you'll erase all of your files.

About the Author

Christopher Tozzi

Technology analyst, Fixate.IO

Christopher Tozzi is a technology analyst with subject matter expertise in cloud computing, application development, open source software, virtualization, containers and more. He also lectures at a major university in the Albany, New York, area. His book, “For Fun and Profit: A History of the Free and Open Source Software Revolution,” was published by MIT Press.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like