Home directory to new drive

Why moving your home directory to a other fysical drive?

Moving your Linux home folder to another drive offers several advantages, including efficient disk space management, enhanced backup and recovery capabilities, isolation of user data from system files, and seamless integration with multi-boot systems.

 

What do we need?

  • A Linux system (Debian or another distro).
  • Two drives (HDD or  SSD)

 

Wichs tools do we need?

Check if they are installed on the system:

  • fdisk: used to make partitions. (“fdisk --version”)
  • mkfs: used to create a file system. (“mkfs –version”)

Steps:

 

We recommend making a backup of your system before your start, because doing something wrong can potentially harm your system or personal data.

 

Identify your new installed drive.

 

First you must identify both your new installed disk and your previous installed disks. You can use the “lsblk” linux command for that. For sata drives it would have de following name “sdx”. It would be NVME drive it would be something like this “nvme0nx”. Your new drive probably doesn’t have any sort of partitions. And it would propably doesn’t habe mounting point either.

 

A computer screen with white text

Description automatically generated

 

Create a partition tabel on the new drive

Lets create a one or more partitions on the new drive. We going to use the fdisk interactive terminal for it.

Make sure you use the correct diskname in this step
  1. Open the fdisk interactive terminal
sudo fdisk  /dev/<disk-name> # forexample “sdb” as disk name

 

  1. Create a partition table
g # type “g” in the terminal

 

  1. Create a partition
n # start with typing “n” in the terminal
<enter> # use default partition number with clicking “enter”
<enter> # use default starting sector with clicking “enter”
50G # fill in the how big you want your partition to be (G -> GB, M -> MB, ...)

 

 

  1. Save your changes
w # to write your changes

 

  1. Check if your partition is recognized  
lsblk

 

Create a filesystem

We now have a valid partition, well not quite yet. I doesn’t have a filesystem yet. So the system cant really work with the partition for now. First we have to figure out what filesystem we want on our system. If the disk needs to be both readable for windows and linux you would probably want to use exFAT, if it doesn’t we highly recommend ext4.

 

  1. Create “ext4” filesystem

 

sudo mkfs.ext4 /dev/<partition-name>

 

 

Create a temporally mount

We have to create a temperarlly mount so we move a copy of the home directory to the new drive partition.

                 

 

  1. Make a directory
mkdir /mnt/home-directory

 

  1. Mount the partition to this directory
sudo mount /dev/<partition-name> /mnt/home-directory

 

Copy current home directory to new mount

Lets copy all current home directory files and user over to the new mounted partition.

 

  1. Copy every user and its sub files over
sudo cp -ar /home/* /mnt/home-directory/

 

We recommend to check if all files and directory are correctly copied.

 

 

 

Create new home directory

We recommend to still keep the old home directory for now, and move it to a other name. And create a new home directory instead.

 

  1. Change name of the home directory
sudo mv /home /home.old

 

  1. Create new home directory
sudo mkdir /home

 

Remount the new home partition

To finally make our new partition work we have to unmount the temperately mount and mount the partition to the newly created home directory.

 

 

  1. Unmount the partition
sudo umount /dev/<partition-name>

 

  1. Mount it to the new created home directory
sudo mount /dev/<partition-name> /home

 

  1. Check if the mount has worked
lsblk # check if the partition-name has mounted to the /home directory

 

 

Make the mount permanently

Well we now technically have a working home directory. But you will fast run in some problems. Because the mount we made is not permanently. So lets make this happen

 

 

  1. First we have to know the UUID from the partition
sudo blkid /dev/<partition-name>

 

  1. Copy the UUID because we need to fill it in to the next step
  2. Edit the fstab file
sudo nano /etc/fstab

 

  1. Add the following line to the end of this file (fill in the partition uuid)
UUID=<your-partition-uuid> /home ext4 defaults 0 2

 

  1. Save the file:
Ctrl + O

 

  1. Force the mount
sudo mount -a

 

Outro

After completing these steps, your home directory resides on the new drive, isolated from the system, and the mount is made permanent, ensuring functionality even after system restarts. Enjoy your upgraded storage setup!

recommended