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

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

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

Leave a comment