🐧 Move your Home directory to another hard drive or partition
Moving the home directory to another hard drive or just a partition, is often a good idea:
You might need more space on your hard drive and most likely your home folder is the biggest folder. So moving it to another hard drive frees up a lot of space.
You may want to change to another OS (or keep the option open). Then using another partition (or hard drive) is very helpful, as you don’t have to backup your data and after the installation copy it back. This is especially interesting, if you use something like a Raspberry Pi or similar devices and you often try out new distributions.
⚠ Warning:
Be aware that you move config files, which might break the system. For that reason, most of the steps are described with terminal commands. So you could execute them in the tty, if needed. Also it is highly recommended to try it within a virtual machine first and only after that on your productive machine. And of course, backup your data beforehand! 🙂
Check Devices
Run lsblk
in the terminal which will output something like:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 300M 0 part /boot/efi
└─sda2 8:2 0 19,7G 0 part /
sdb 8:16 0 8G 0 disk
sr0 11:0 1 1024M 0 rom
sda
is our main drive, whereas sdb
is our second drive, where we want to put our home directory. FYI, this example is just made up in a virtual machine. In your case the names might differ.
Create Partition (if needed)
In this example sdb
is not formatted yet. As you see, there are no partitions under sdb
. If you already have a partition, skip this step.
We will create a new partition with gparted
.
(Install and) start
gparted
Select
sdb
in the top right cornerClick on
Divice
->Create Partition Table...
-> table typemsdos
->Apply
Right click on the partition ->
New
->Add
Click on the
check mark
“Apply all Operations”Run
lsblk
again to double check results
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 300M 0 part /boot/efi
└─sda2 8:2 0 19,7G 0 part /
sdb 8:16 0 8G 0 disk
└─sdb1 8:17 0 8G 0 part
sr0 11:0 1 1024M 0 rom
```
Now we have the new partition `sdb1`.
<a id="org7c0d916"></a>
## Mount the new partition to /mnt/tmp
We will mount the new partition to /mnt/tmp so we can copy our home folder there.
``` bash
sudo mkdir /mnt/tmp
sudo mount /dev/sdb1 /mnt/tmp # replace /dev/sdb1 with your partition
Copy your home directory to the second drive
We use rsync
to copy our home directory.
sudo rsync -avx /home/ /mnt/tmp
Check if /home is created on new file system and mount it temporary
sudo mount /dev/sdb1 /home
df /dev/sdb1
Open your file explorer or terminal to check if everything is still fine.
Delete folder with safety net
Important: unmount the /home directory again and after that, we can move the home folder. The real deletion can be made, when we are 100% sure, that everything works as expected.
sudo umount /home
sudo mv /home /home.orig
Editing fstab with safety net
Copy a fstab
backup:
sudo cp /etc/fstab /etc/fstab.orig
Get the UUID from your partition via:
sudo blkid | grep "/dev/sdb1" # replace /dev/sdb1 with your partition
Edit the /etc/fstab file with your favorite text editor. Add/change the line in the file:
UUID=<copied number from above> /home ext4 defaults 0 2
Reboot the system.
Delete Home Folder
After restart and when everything is fine, you might delete the home backup directory:
rm -rf /home.orig/*
rm /etc/fstab.orig