Usually when you have Ubuntu installed, it is likely that the system folders and the home folder all belong to the same partition.In order to keep your custom settings, your files and folders, it is recommended that you put your home folder in a specific partition so that future alterations on the system files and folders will not have any effect on the home folder so that you would be able to upgrade or even reinstall your Ubuntu without damaging the current custom files configuration.
We provide few steps that will help you move the home folder to another partition.
Setup Partitions
In this first step, we assume that you already have an external partition, .i.e. something like /sda3. When however you would like to create a new partition, it is good practice to create an ext3 or ext4 partition in order to house the new home folder.
Read: Best Partition Managers for Linux Users
Create a temporary Home folder
Open up the terminal and type in the following sudo command which will display the uuid (Universally Unique Identifier) reference for all available partitions :
sudo blkid
Read: How to read a Mac formatted drive on a Windows PC
It could be that for older releases of Ubuntu, the command “blkid” might not be available or might not work, so instead, you could execute the following :
sudo vol_id -u <your partition name>
Like for example:
sudo vol_id -u /dev/sda3
Once this is done, you just need to insert into a file the uuid of the external partition that you have created so that it can house the new home folder.
To do this, issue the following command in order to open the fstab file. This is just to tell Ubuntu the partitions to mount at boot :
fstab Linux
The following commands will simply duplicate the current fstab file, then the year-month-day will be appended to the end of the file name. The two files will then be compared before opening the original fstab for editing.
Read: How to install BalenaEtcher on Ubuntu 20.04
To duplicate the fstab file:
sudo cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d)
To confirm the backup file matches the original file, a comparison is made:
cmp /etc/fstab /etc/fstab.$(date +%Y-%m-%d)
Now edit the original fstab in your preferred text editor:
sudo nano /etc/fstab
Append the following line to the text of the file :
UUID=xxx-xxxxx-xxxxx /media/home ext4 nodev,nosuid 0 2
And remember to replace the “xxx-xxxxx-xxxxx” with the UUID of the /home partition as well as the partition name (here ext4 is being used).
Read: How to Check Disk Space in Ubuntu 22.04
You may need to replace “gedit” with “mousepad”, “kate” or “leafpad” in case you are using Xubuntu, Kubuntu or Lubuntu respectively .
Finally save and close the fstab file and then issue the following command in order to create a mount point:
sudo mkdir /media/home
Make home directory in Linux
This will create a new folder which will be used later for mounting the new partition temporarily. This directory can be removed at the end of the procedure.
Now you can either restart your computer or you might just reload the updated fstab via the command :
sudo mount -a
The new partition “home” folder should now be mounted in the Media directory.
You may be interested to read: How to fix : Unable to install GParted on Ubuntu ?
Copy the files under /home to the new partition
In this step, we will copy all directories, files and sub-folders from the current /home Ubuntu home directory into the newly created partition. If your home file system is not encrypted, just issue the following command ( a simple copy of all files would not have been enough since in this case, the hidden files might be skipped or missed out and some file permissions might not be retained ):
sudo rsync -aXS /home/. /media/home/.
You can interrupt the rsync command several times at any time. When you invoke it again, it will check the completed progress or how much has already been achieved. This copying step can therefore be split up into many sessions. If you have added new files or created new folders or customized some apps (since the first copying/syncing operation), you may wish to run it one more time to make sure everything has been accounted for.
As hinted at above, in case your home file system is encrypted, the command above will not retain the encryption which means it will provide you with an unencrypted copy of your folders and files. You could however re-encrypt them at the end, i.e. after copying them , or copy them in their encrypted form.
Check Copying operation was completed successfully
If the operation above has finished successfully, two duplicate copies of the content of your home folder should now be available. The new copy is located under /media/home whereas the original data is under /home. In order to confirm all directories and files have been copied correctly, you could (for an unencrypted file system) use the diff command below:
sudo diff -r /home /media/home
Some errors might show up however after you have run the command above, .e.g. “files not found”. This can be ignored since it is related to the fact that some symbolic links point to locations that no longer exist (they will after reboot).
Modify fstab again
The fstab would now need to point to the newly created partition to be mounted as /home. Run the command:
sudo nano /etc/fstab
Now edit the lines you had appended earlier and replace the “/media/home” with “/home”. Finally save and exit.
Relocating the home folder
In case things did not go well, it is good practice to back up the original home folder.
You should now have two copies of the /home directory in case you have not rebooted yet : the newly created one which is mounted as /media/home and the old one which is in the same original partition (currently mounted as /home ). We now need to get rid of the old content (under old home directory) and create an empty directory which will act as a “mount point” for the newly created partition.
Type in the following commands all at once:
cd / && sudo mv /home /old_home && sudo mkdir /home
The mv command will rename /home into /old_home. The mkdir will create a new placeholder /home .
Reboot
Now you need to reboot your computer. Your newly created partition should mount as /home.
Some administrators, instead of rebooting, they by reload the updated fstab via the command :
sudo mount -a
Deleting the old content
In case you do not want to keep the old Home folder as a backup or if you think you will run out of space , you can simply remove it using the command:
sudo rm -rf /old_home
If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.
Dozens of brick-worthy commands later … A casual Linux lusr has not time or energy for this byteboi excess … no matter how-much he would like a partitioned HOME folder.
I wish that linux hard core users had the know how to be able to make a gui that worked all this command code. this write up does not work as it is not explained correctly. the fstab does not have a save command. if you read the commands at bottom none say save and if your ctr o it asks for name or type etc it is not a save function. your explanation skips steps that I am sure you know but do not say. for new linux users this is useless information. This is why Linux will never become main stream os. all this command line is old an is no better than dos (although there are more commands) but is still obsolete in the 21 century. If it cannot be made into a gui for normal users no one will ever want to switch to linux. most of these commands fail depending on your version of linux. so frustrating for a new user. I have search the net for help and all just say the same time that does not work. I did a fresh install of ubuntu 20 and it by itself made a small vfat partition where it loaded my home folder 2g size and made a 900g size ext4 partition that is not used by anything..how useless. and no one knows how to fix it or if they do cannot explain it in simple terms that work