How to Move Home Directory to New Partition or Disk in Linux

On any Linux system, one of the directories that will surely grow in size has to be the /home directory. This is because system accounts (users) directories will reside in /home except root account – here users will continuously store documents and other files.

Another important directory with the same behavior is /var, it contains log files whose size will gradually increase as the system continues to run such as log files, web files, print spool files etc.

When these directories fill up, this can cause critical problems on the root file system resulting into system boot failure or some other related issues. However, sometimes you can only notice this after installing your system and configuring all directories on the root file system/partition.

Suggested Read: Linux Directory Structure and Important Files Paths Explained

In this guide, we will show how to move the home directory into a dedicated partition possibly on a new storage disk in Linux.

Installing and Partitioning a New Hard Disk in Linux

Before we proceed any further, we’ll briefly explain how to add a new hard disk to an existing Linux server.

Note: If you already have a partition ready for the operation, move to the section which explains the steps for moving /home directory in a partition of its own below.

We’ll assume you have attached the new disk to the system. On a hard disk, the number of partitions to be created as well as the partition table is normally determined by disk label type and the first few bytes of space will define the MBR (Master Boot Record) which stores the partition table as well as the boot loader (for bootable disks).

Although there are many label types, Linux only accepts two: MSDOS MBR (516 bytes in size) or GPT (GUID Partition Table) MBR.

Let’s also assume that the new new hard disk (/dev/sdb of size 270 GB used for the purpose of this guide, you probably need a bigger capacity on a server for large user base.

First you need to set the disk label type using fdisk or parted; we have used GPT label name in this example.

# parted /dev/sdb mklabel gpt

Note: fdisk only supports MSDOS MBR for now and parted supports both labels.

Now create the first partition (/dev/sdb1) with size 106GB. We have reserved 1024MB of space for the MBR.

# parted -a cylinder /dev/sdb mkpart primary 1074MB 107GB

Explaining the command above:

  • a – option to specify the partition alignment.
  • mkpart – sub command to create the partition.
  • primary – sets partition type as primary on the hard disk (other values are logical or extended).
  • 1074MB – beginning of partition.
  • 107GB – end of partition.

Now check the free space on the disk as follows.

# parted /dev/sdb print free

We will create another partition (/dev/sdb2) with size 154GB.

# parted -a cylinder /dev/sdb mkpart primary 115GB 268GB

Next, let’s set the filesystem type on each partition.

# mkfs.ext4 /dev/sdb1
# mkfs.xfs /dev/sdb2

To view all storage devices attached on the system, type.

# parted -l
List New Storage Device
List New Storage Device

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
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
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.

  1. How to Delete User Accounts with Home Directory in Linux
  2. What is Ext2, Ext3 & Ext4 and How to Create and Convert Linux File Systems
  3. 7 Ways to Determine the File System Type in Linux (Ext2, Ext3 or Ext4)
  4. How to Mount Remote Linux Filesystem or Directory Using SSHFS Over SSH

In this guide, we explained you how to move the /home directory into a dedicated partition in Linux. You can share any thoughts concerning this article via the comment form below.

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

68 thoughts on “How to Move Home Directory to New Partition or Disk in Linux”

  1. Hi, I have the following situation:

    $ sudo fdisk -l
    

    Disk /dev/sda: 1,82 TiB, 2000398934016 bytes, 3907029168 sectors
    Disk model: ST2000DM001-1ER1
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disklabel type: gpt
    Disk identifier: 9FED7901-45C1-4954-BF97-98F47C14FD92

    Dispositivo Start Fine Settori Size Tipo
    /dev/sda1 2048 1026047 1024000 500M BIOS boot
    /dev/sda2 1026048 3907028991 3906002944 1,8T Linux filesystem

    Disk /dev/sdb: 29,82 GiB, 32017047552 bytes, 62533296 sectors
    Disk model: SAMSUNG SSD CM85
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: gpt
    Disk identifier: 81AE3F2B-DF64-48D0-B161-80EBC1FBBCF6

    Dispositivo Start Fine Settori Size Tipo
    /dev/sdb1 2048 46878719 46876672 22,4G Linux filesystem
    /dev/sdb2 46878720 62531583 15652864 7,5G Linux swap

    Disk /dev/zram0: 8 GiB, 8589934592 bytes, 2097152 sectors
    Units: sectors of 1 * 4096 = 4096 bytes
    Sector size (logical/physical): 4096 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes

    namely:

    1. A 1.8T disk (sda) on which there is boot (sda1) and backup of the old /home I had in fedora 33 (sda2).
    2. A disk of about 30 G with linux (sdb1) swap (sdb2).

    This is the situation after I made the upgrade to Fedora35 with the new home on the small disk.

    I would like to mount the /home on the big disk following your instructions above, but the big disk already has data on it, the file system of the old /home. How do I proceed not to lose everything?

    Thank you for your help in advance

    Reply
  2. In Windows 7, 8, 10, 11, etc you go into c:\users\username and in that folder, there are folders like Videos, Documents, Pictures, and whatnot, right-click and choose properties, location tab and move that folder to a new drive and everything link’s perfect, its just that simple.

    Now I use Linux as my only OS, why can’t it be that simple. On Linux, I can’t go into files and click on documents for example as that is not where they are stored.

    Why isn’t there an easy way to do this?

    Reply
    • @Jason, what Ravi said, and

      In file manager (I am using Devuan) I went to /home//.

      There I right-clicked on Documents and got four options under “Send to”:

      1. Desktop (create link)
      2. 120Gb drive (a spare drive I have on the system)
      3. Data composition
      4. Mail recipient

      Your system or file manager may not have exactly those options but I am sure that something like them will be available.

      If you want to simply link a file then you may use the command from the command line.

      Reply
      • Sorry, something went wrong there on two lines:

        “I went to /home//” should read “I went to /home/my-home-directory/” and, “use the command” should read “use the command ln “

        Reply
      • Nice, but if I click on “send to” it just sends it to my email client, there is no other options, it is fine.

        All of my pictures, downloads, music, documents, and videos are stored on their own SSD so I thought I could make these the defaults instead of the default ones on my NVME where the operating system is.

        Reply
    • The step rm -rf /home is dangerous though, you cannot get it back. It should be mv /home /home-old -> this will backup everything at home, then if everything goes bad you can restore it.

      Reply
      • I don’t get it. wouldn’t you mv /home /”home-new”? or more specifically mv /home /dev/sdb/home?

        This article is all convoluted. It starts with creating an entire disk, which should be the subject of another article entirely. Either just explain moving /home to a new partition, and leave it, maybe then repeat whatever steps needed for the second example of moving /home to a new disk!!!! And creating a second disk should be a separate article entirely.

        As Open Source idealists start becoming disillusioned, there are more and more crappy articles by people just writing for clickbait, and for deadlines. It makes me sad.

        Reply
  3. My problem is that I believe in separating code and data. That is why I create two partitions, one for Linux and programs and a separate partition for my data. However, Linux developers insist that the home directory is in the same partition as the Linux code.

    Is it even possible to get Linux to use a directory on a separate partition as the “home directory”?

    Reply
    • No that’s not true at all, about “Linux developers”. In the 90s it was usually suggested every single directory immediately under root have it’s own partition. /boot, /dev, /etc, /home, /lib, and /opt, had it’s own partition, I forget further details of /bin and /sbin.

      But my point was this is rampant throughout all distros in the 80s and 90s. You just haven’t done your research! Early Linux books all explain this. The fact is that Windows users were content and only understood “C:”. Maybe an extra D; disk, or network disk tat might be Z: or K:. Forget individual partitions.

      So, after rabidly going after Windows users for 20 years, Most large Linux distros gave up and made it convenient to put everything, or nearly everything in one partition, so users could transition. By the way, Chrome OS typically has eleven partitions, all hidden from the user, and Mac OSX also hides partitions from users.

      Humans generally are too stupid to keep track of partitions. We are drowning in stupidity every day. I’m thinking of giving myself a lobotomy so I can blend in. I’m almost tempted to give you a pat on the head for wanting a different partition arrangement. But then you’re also too lazy to find this material in texts (online or off). So I guess there’s not much hope at all.

      Reply
  4. Thanks for your clear and useful instructions.

    I have to move my /home because the HDD is nearly full. I have a 1 Tb disk installed and I am preparing to partition it etc.

    I am confused about the partitions you create in your examples. sdb1 and sdb2 have different file systems and I wonder why it is necessary to have two partitions.

    My idea was to create the whole HDD as one partition to mount as /home.

    Should I have a second partition? I don’t need one for any other purpose.

    Reply
    • Replying to my own comment. What a loser ;)

      I made a decision and flew with it. I created a partition on the new HDD that used all but the first MB of the disk. Then followed the instructions to ultimately mount it as /home by editing fstab.

      It worked. So if anyone else wondered about the partitioning you don’t need more than one.

      Reply
  5. The rsync command with options.

    rsync -av

    should be

    rsync -av -A -X

    to preserve SELinux contexts – otherwise, some distributions will fail to mount /home properly (or at all) after this.

    Reply
    • Also, shopt -s dotglob if using cp. Not sure if rsync does hidden files by default, I have always just enabled dotglob for it if I want it to include hidden files.

      Reply
  6. is rm -rf home/* not dangerous? At that time, other programs may crash or even create new directories. Should we not first mount the new drive?

    Reply
  7. @Aaron

    Yes, a new line was added to /etc/fstab (using the correct UUID of course). I’m no Linux expert and so not being familiar enough to repair a system that I can’t boot into of course I scrapped the installation.

    It’s only a VM I’m experimenting with and I had a previous snapshot, so no great loss to me. But I still have no idea what I did wrong. I’ll have another go later.

    Reply
      • @Aaron

        Brilliant. It worked this time.

        I copied your procedure line by line into a LibreOffice document both to check what I was doing and for future reference, adjusting the partition name and UUID as I went.

        This time I noticed that LO inserted a space after the equals sign in the /etc/fstab line when I pasted the UUID which I then had to delete. I think this is what messed me up last time.

        e.g. UUID= bdaa2...

        Regards.

        Reply
  8. I do not want to move /home, I want to move /home/robert. I believe separating code and data is a GOOD THING. So I have partitioned my disk so that Ubuntu MATE gets one partition and all my data is in a different partition.

    This means that when I have to reinstall Ubuntu MATE (Like if release 19.10 does not work at all), none of my data is affected and third party code is untouched. My system uses /media/robert as the mount point.

    Unfortunately, too many Linux programs think that separating code and data is a BAD THING, so they put all their code in my /home/robert directory. Is it possible to get Unix to use /media/robert/Shared/Users/robert as my home directory?

    Reply
  9. It seems to be missing something. did not work for me when I rebooted I could not get into mint at all. rereading I still don’t understand a lot.

    Reply
  10. Great instructions except that I not having faith in the process did not delete the original home folder and wonder where it went and if it is wasting space somewhere. I have successfully moved my home to a new partition but not sure if and where the old users are under filesystem

    Reply
  11. etx4 – describes the filesystem type on the device/partition and it is confusing to noobs.

    Perhaps that should be ‘ext4’?

    Reply
  12. Hi, I got as far as /mount /dev/sdb1 to /home/jud.

    The result was a home folder which showed the contents of sdb1, but there are some problems with rights, e.g. sudo gedit /etc/fstab worked before the change, but not after, and gparted ran before, not after.

    Also, I have two different Linux Mint installs, a version 18.3 and a 19, and would like both to share a single /home.

    thanks for a clear and informed post

    Reply
    • @Jud

      We have to test first whether you can use the same home directory for two same distro installs, before we can give you a solution. But, thanks for liking the guide and giving us feedback.

      Reply
      • After posting prior comment, I modified fstab on two different installs of Linux Mint 18.3 Cinnamon, which appear successful, no rights problems so far. I know that is anecdotal and in no way a test, but am encouraged by results [and Home is separately backed up in case it all goes away]. Thanks again.

        Reply
  13. Thank you for this post.

    To get the partition in the FSTAB file you can use this command:

    # echo UUID=$(blkid /dev/sdb1 | cut -d'"' -f2) /home ext4 default 0 2 >> /etc/fstab
    
    Reply
  14. Hi Aaron,

    Thank you for this detailed post.

    I am following your post to move my / directory to a new raid 1 HD. I have managed to set up my raid HD till now. I wish to move the whole / rather than /home directory.

    My difficulty comes when mounting my new HD. I cannot mount my HD within my / directory if I understand correctly. What do you suggest, please? This is what I have on the server. Of course, /dev/md3, which is my new raid needs to be unmounted from /srv/home.

    root@mail:/# df -hl
    Filesystem      Size  Used Avail Use% Mounted on
    udev             32G  4.0K   32G   1% /dev
    tmpfs           6.3G  944K  6.3G   1% /run
    /dev/md2        197G  159G   29G  85% /
    none            4.0K     0  4.0K   0% /sys/fs/cgroup
    none            5.0M     0  5.0M   0% /run/lock
    none             32G     0   32G   0% /run/shm
    none            100M     0  100M   0% /run/user
    /dev/md1        488M   74M  388M  17% /boot
    /dev/md3        5.5T   34G  5.2T   1% /srv/home
    

    Many thanks for your advice.

    Reply
  15. Thanks a lot for this post, it worked perfectly. I have only one suggestion to improve it:

    At the very end, when you have added the new partition to /etc/fstab, it is a good idea to execute ‘mount -a‘, which will try to mount the stuff in the file.

    This ensures that your fstab file is fine. I had a typo in it, and that can be quite annoying if you do not discover it in time and only find out at the next reboot…

    Reply
  16. Aaron, your procedure worked great! I installed and partitioned a Western Digital 1TB external USB drive (/dev/sdb) and created 1 partition (sdb1) with 500GB (the rest I left as free space). Using your procedure, I moved my /home directory and am successfully mounting it via /etc/fstab.

    However, this did not solve the problem that I’m having. I have an internal 250GB drive (/dev/sda) that is still being reported by the df command as having 0 free disk space available.

    Do you have any insights as to why this is happening on my Linux box (Debian 8)? I have checked lsof and found mainly files being held open by the systemd and X11 processes. df also sees that /home is now mounted on /dev/sdb1. I was expecting that the 660+MB /home to show as free. I have also shutdown hoping that any processes preventing the space on /dev/sda from being freed would release it.

    I was hoping to attach files with the output from df and parted -l but do not see any way of doing this. If you can add any suggestions or point me in any directions, i would appreciate your help. Once I get this issue solved I will probably use this process to create a second partition on /dev/sdb and move my /var to it as you mention in your article.

    Thanks in advance,
    Mitch

    Reply
      • Aaron, Tried to recycle an old 1TB WD drive to use for /home and /var, it crashed! Bought a WD easy store portable USB 2TB drive for $59.00 and implemented using your procedure.

        Everything worked flawlessly. I now have Debian upgraded to 9.0, with /dev/sdb1 (500GB) as /home, /dev/sdb2 (750GB) as /var and /dev/sdb3 (750GB) as /tmp. /dev/sda (250GB) as the system/boot device with only 1% used. I should be good to go for a long time. The old /dev/sdba with everything physically on it lasted for 2 years.

        I modified your procedure by 2 steps for each /home, /var and /tmp. /srv has /home, /var and /tmp in it. When it came to the step to rm (/home/*, /var/* and /tmp/*) I renamed (mv) those directories to /-hold until I tested with root and user logins. This gave me the safety net of recovering easily if I needed to. Then I created new /home, /var and /tmp directories to mount to. In the end I removed the *-hold directories.

        Thank you for your article and help. This is a GREAT site, I’ve looked at your other suggested articles … all are of the highest quality. I WILL be bookmarking this site for future reference.

        Mitch

        Reply
  17. Newbie here, and wanting to isolate my data and worked very well, just for the info “rm -rf /home/*” failed initially because I had Nemo open there and “diff -r /home /srv/home” showed a few files in the “Trash“.

    Reply
  18. Very clear, elegant, simply, and it worked, first try for me. I had watched 20 videos and all kinds of complex ways to do this. I was sure there was a simpler method, but couldn’t find one. Then I found this post. WOW, is all I can say. Saved my a lot of trouble and fixed my no room on /root problem. THANK YOU SO MUCH!

    Reply
  19. If you’re not using LVM this method is OK, but I’d strongly suggest stopping any service that allows users login or access in any way to the contents in /home wile the task is being executed. Think sshd, httpd (if allowing ~user), ftp. If possible, ‘telinit 1’ is the safest choice (in fact, it is a MUST if moving /var to another disk/partition).
    Bottom line: use LVM for a happier life :-)

    Reply
    • @Nahuel

      “but I’d strongly suggest stopping any service that allows users login or access in any way to the contents in /home wile the task is being executed.” – so true, actually forgot to mention this in the guide. Many thanks for the head up.

      Reply
  20. Thank you for your article, a very detailed explanation.

    But I have one question about the content of the /home folder after remounting on /dev/sdb1.

    As far as I understand, in the beginning you created /srv/home folder and then copy the content from /home folder to the /srv/home. After that you checked the difference between them by using diff tool.

    Then you removed everything inside of the /home and unmounted /srv/home.

    Everything is clear at this stage.

    And next, you remounted again /home to a new HDD /dev/sdb1.

    But in my opinion, in that case the new /home folder is empty since you removed the content of this folder earlier and didn’t copy the content from /srv/home to this /home before this mounting.

    What did I miss here?

    Thank you!

    Reply
    • @Alexey

      Yes, the new /home folder is empty since its content was removed earlier on. Remember we copied it into the /srv/home directory which was mounted to /dev/sdb1. Meaning the content was stored in the space on /dev/sdb1; here /srv/home only acted as the mount point.

      A mount point like /srv/home or /home is simply a directory from which we can access a filesystem space such as /dev/sdb1.

      Then we unmounted /srv/home but still the content is present on /dev/sdb1, finally we mounted /dev/sdb1 to /home which is the new mount point.

      I know it’s a little confusing but reading through the mount command manual page will help you understand better.

      Reply
  21. Thanks for your great article! I’m a newbie so I have a question: why you partitioned the second hard drive in two partitions and why you have chosen to format the second one in xfs?

    Flavio

    Reply
    • @Flavio

      We have created two partitions with different filesystem types for demonstration purposes. You can choose to create one partition on the new disk depending on your needs.

      Thanks.

      Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.