How to mount a folder to another folder on Linux

Linux is a flexible system. If you know the trick, there are a lot of things we can do with Linux. On this tutorial, I will show you how to mount a directory to another directory. I know that this is not necessary for most end users but you may need this trick if you manage a server with multiple hard drives.

 In my case, I manage a ClearOS server with 2 hard disks installed. I want to use my second hard disk to handle all the data including user’s home directory. By default, users home directory is located inside the first disk (system disk). I want to move them and use the second disk to store all users data. So, if something happened with the system, I can easily retrieve the users data.

Before:

/home is located inside /dev/sda1 (first disk).

After

/home is located inside /dev/sdb1 (second disk)

First, we need to mount the second disk to some folder says /mnt/disk2.

mkdir -p /mnt/disk2
mount /dev/sdb1 /mnt/disk2

Now create a new directory under /mnt/disk2

mkdir -p /mnt/disk2/newhome

Mount the newhome to /home

mount -o bind /mnt/disk2/newhome /home

To automatically mount the folder at startup, edit /etc/fstab and add the following line to it.

/mnt/disk2/newhome /home none defaults,bind 0 0

Done.

Admin

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *