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.
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.
Open up the terminal and type in the following sudo command which will display the uuid (Universally Unique Identifier) reference for all available partitions :
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 :
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.
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).
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 ?
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.
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).
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.
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 .
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
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 coffe. Thank you so much for your visit and support.