How to Move Home Directory to New Partition or Disk in Linux

On any Linux system, one of the directories that will surely grow in size has to be the /home directory. This is because system accounts (users) directories will reside in /home except root account – here users will continuously store documents and other files.

Another important directory with the same behavior is /var, it contains log files whose size will gradually increase as the system continues to run such as log files, web files, print spool files etc.

When these directories fill up, this can cause critical problems on the root file system resulting into system boot failure or some other related issues. However, sometimes you can only notice this after installing your system and configuring all directories on the root file system/partition.

Suggested Read: Linux Directory Structure and Important Files Paths Explained

In this guide, we will show how to move the home directory into a dedicated partition possibly on a new storage disk in Linux.

Installing and Partitioning a New Hard Disk in Linux

Before we proceed any further, we’ll briefly explain how to add a new hard disk to an existing Linux server.

Note: If you already have a partition ready for the operation, move to the section which explains the steps for moving /home directory in a partition of its own below.

We’ll assume you have attached the new disk to the system. On a hard disk, the number of partitions to be created as well as the partition table is normally determined by disk label type and the first few bytes of space will define the MBR (Master Boot Record) which stores the partition table as well as the boot loader (for bootable disks).

Although there are many label types, Linux only accepts two: MSDOS MBR (516 bytes in size) or GPT (GUID Partition Table) MBR.

Let’s also assume that the new new hard disk (/dev/sdb of size 270 GB used for the purpose of this guide, you probably need a bigger capacity on a server for large user base.

First you need to set the disk label type using fdisk or parted; we have used GPT label name in this example.

# parted /dev/sdb mklabel gpt

Note: fdisk only supports MSDOS MBR for now and parted supports both labels.

Now create the first partition (/dev/sdb1) with size 106GB. We have reserved 1024MB of space for the MBR.

# parted -a cylinder /dev/sdb mkpart primary 1074MB 107GB

Explaining the command above:

  • a – option to specify the partition alignment.
  • mkpart – sub command to create the partition.
  • primary – sets partition type as primary on the hard disk (other values are logical or extended).
  • 1074MB – beginning of partition.
  • 107GB – end of partition.

Now check the free space on the disk as follows.

# parted /dev/sdb print free

We will create another partition (/dev/sdb2) with size 154GB.

# parted -a cylinder /dev/sdb mkpart primary 115GB 268GB

Next, let’s set the filesystem type on each partition.

# mkfs.ext4 /dev/sdb1
# mkfs.xfs /dev/sdb2

To view all storage devices attached on the system, type.

# parted -l
List New Storage Device

List New Storage Device

Moving Home Directory into a Dedicated Partition

Now we have added the new disk and created the necessary partition; it’s now time to move the home folder into one of the partitions. To use a fileysystem, it has to be mounted to the root filesystem at a mount point: the target directory such as /home.

First list the filesystem usage using df command on the system.

# df -l
Linux Filesystem Usage

Linux Filesystem Usage

We will start by creating a new directory /srv/home where we can mount /dev/sdb1 for the time being.

# mkdir -p /srv/home
# mount /dev/sdb1 /srv/home 

Then move the content of /home into /srv/home (so they will be practically stored in /dev/sdb1) using rsync command or cp command.

# rsync -av /home/* /srv/home/
OR
# cp -aR /home/* /srv/home/

After that, we will find the difference between the two directories using the diff tool, if all is well, continue to the next step.

# diff -r /home /srv/home

Afterwards, delete all the old content in the /home as follows.

# rm -rf /home/*

Next unmount /srv/home.

# umount /srv/home

Finally, we have to mount the filesystem /dev/sdb1 to /home for the mean time.

# mount /dev/sdb1 /home
# ls -l /home

The above changes will last only for the current boot, add the line below in the /etc/fstab to make the changes permanent.

Use following command to get the partition UUID.

# blkid /dev/sdb1

/dev/sdb1: UUID="e087e709-20f9-42a4-a4dc-d74544c490a6" TYPE="ext4" PARTLABEL="primary" PARTUUID="52d77e5c-0b20-4a68-ada4-881851b2ca99"

Once you know the partition UUID, open /etc/fstab file add following line.

UUID=e087e709-20f9-42a4-a4dc-d74544c490a6   /home   ext4   defaults   0   2

Explaining the field in the line above:

  • UUID – specifies the block device, you can alternatively use the device file /dev/sdb1.
  • /home – this is the mount point.
  • etx4 – describes the filesystem type on the device/partition.
  • defaults – mount options, (here this value means rw, suid, dev, exec, auto, nouser, and async).
  • 0 – used by dump tool, 0 meaning don’t dump if filesystem is not present.
  • 2 – used by fsck tool for discovering filesystem check order, this value means check this device after root filesystem.

Save the file and reboot the system.

You can run following command to see that /home directory has been successfully moved into a dedicated partition.

# df -hl
Check Filesystem Usage on Linux

Check Filesystem Usage on Linux

That’s It for now! To understand more about Linux file-system, read through these guides relating to filesystem management on Linux.

  1. How to Delete User Accounts with Home Directory in Linux
  2. What is Ext2, Ext3 & Ext4 and How to Create and Convert Linux File Systems
  3. 7 Ways to Determine the File System Type in Linux (Ext2, Ext3 or Ext4)
  4. How to Mount Remote Linux Filesystem or Directory Using SSHFS Over SSH

In this guide, we explained you how to move the /home directory into a dedicated partition in Linux. You can share any thoughts concerning this article via the comment form below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

41 Responses

  1. jesse says:

    Great instructions except that I not having faith in the process did not delete the original home folder and wonder where it went and if it is wasting space somewhere. I have successfully moved my home to a new partition but not sure if and where the old users are under filesystem

  2. Steve says:

    etx4 – describes the filesystem type on the device/partition and it is confusing to noobs.

    Perhaps that should be ‘ext4’?

  3. Adhiana says:

    thanks for sharing this

  4. Jud Jennings says:

    Hi, I got as far as /mount /dev/sdb1 to /home/jud.

    The result was a home folder which showed the contents of sdb1, but there are some problems with rights, e.g. sudo gedit /etc/fstab worked before the change, but not after, and gparted ran before, not after.

    Also, I have two different Linux Mint installs, a version 18.3 and a 19, and would like both to share a single /home.

    thanks for a clear and informed post

    • Aaron Kili says:

      @Jud

      We have to test first whether you can use the same home directory for two same distro installs, before we can give you a solution. But, thanks for liking the guide and giving us feedback.

      • Jud Jennings says:

        After posting prior comment, I modified fstab on two different installs of Linux Mint 18.3 Cinnamon, which appear successful, no rights problems so far. I know that is anecdotal and in no way a test, but am encouraged by results [and Home is separately backed up in case it all goes away]. Thanks again.

  5. James Ray says:

    Wouldn’t it be simpler to use the GNOME Disks program?

  6. Janne says:

    and otherwayround?

    how to change it back tothe main harddrive root?

  7. Fan says:

    Thank you for this post.

    To get the partition in the FSTAB file you can use this command:

    # echo UUID=$(blkid /dev/sdb1 | cut -d'"' -f2) /home ext4 default 0 2 >> /etc/fstab
    
  8. Amar says:

    Thanks for the steps and the explanations, it helped me on more than one occasion.

  9. Stephen says:

    Hi Aaron,

    Thank you for this detailed post.

    I am following your post to move my / directory to a new raid 1 HD. I have managed to set up my raid HD till now. I wish to move the whole / rather than /home directory.

    My difficulty comes when mounting my new HD. I cannot mount my HD within my / directory if I understand correctly. What do you suggest, please? This is what I have on the server. Of course, /dev/md3, which is my new raid needs to be unmounted from /srv/home.

    [email protected]:/# df -hl
    Filesystem      Size  Used Avail Use% Mounted on
    udev             32G  4.0K   32G   1% /dev
    tmpfs           6.3G  944K  6.3G   1% /run
    /dev/md2        197G  159G   29G  85% /
    none            4.0K     0  4.0K   0% /sys/fs/cgroup
    none            5.0M     0  5.0M   0% /run/lock
    none             32G     0   32G   0% /run/shm
    none            100M     0  100M   0% /run/user
    /dev/md1        488M   74M  388M  17% /boot
    /dev/md3        5.5T   34G  5.2T   1% /srv/home
    

    Many thanks for your advice.

  10. Tim S says:

    Thanks a lot for this post, it worked perfectly. I have only one suggestion to improve it:

    At the very end, when you have added the new partition to /etc/fstab, it is a good idea to execute ‘mount -a‘, which will try to mount the stuff in the file.

    This ensures that your fstab file is fine. I had a typo in it, and that can be quite annoying if you do not discover it in time and only find out at the next reboot…

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.