Networking HowTos
Networking HowTos

Combine several mount points into a single virtual one using mhddfs

June 5, 2017 Linux, Storage

The MHDDFS package (known as the Multi-hdd FUSE filesystem) provides a method of joining a number of filesystems, of varying size, to appear as one large volume. The benefit of using this over something like lvm, is that if one of the hard drives dies, you only loose the data on that specific hard drive. The remaining drives will remain usable.
Mhddfs will automatically select which disk to write files to, based on the free space on the source drives. It will select the drive with the most free space.
Install mhddfs if its not already installed

$ sudo apt-get install -y mhddfs

Mount your source drives somewhere
(only needed if they are not mounted yet)

$ sudo mount /dev/sdb1 /mnt/sdb1
$ sudo mount /dev/sdc1 /mnt/sdc1
$ sudo mount /dev/sdd1 /mnt/sdd1

Show the mounts you want to combine
In my example, /dev/sdb1 is a 256mb drive, /dev/sdc1 is a 512mb drive, and /dev/sdd1 is a 1gb drive.

$ df -h
Filesystem                       Size  Used Avail Use% Mounted on
<...irrelevant lines removed...>
/dev/sdb1                        243M  2.1M  225M   1% /mnt/sdb1
/dev/sdc1                        487M  2.3M  456M   1% /mnt/sdc1
/dev/sdd1                        991M  2.6M  922M   1% /mnt/sdd1

Note that sdd1 has the most free space out of the 3.
Create a folder to use as the mount point for mhddfs

$ sudo mkdir /mnt/storage

Run mhddfs and create the virtual mount point.
Concatenate your mount points, separated by commas.

$ sudo mhddfs /mnt/sdb1,/mnt/sdc1,/mnt/sdd1 /mnt/storage -o allow_other
mhddfs: directory '/mnt/sdb1' added to list
mhddfs: directory '/mnt/sdc1' added to list
mhddfs: directory '/mnt/sdd1' added to list
mhddfs: mount to: /mnt/storage
mhddfs: move size limit 4294967296 bytes

You should now have the 3 mount points for the hdd’s mounted using mhddfs under /mnt/storage, and showing the total storage from the 3 mount points.

$ df -h
Filesystem                       Size  Used Avail Use% Mounted on
<...irrelevant lines removed...>
/dev/sdb1                        243M  2.1M  225M   1% /mnt/sdb1
/dev/sdc1                        487M  2.3M  456M   1% /mnt/sdc1
/dev/sdd1                        991M  2.6M  922M   1% /mnt/sdd1
/mnt/sdb1;/mnt/sdc1;/mnt/sdd1    1.7G  6.8M  1.6G   1% /mnt/storage

Testing the new mhddfs virtual drive
To test the operation, create some files in the individual underlying mount points (sdb1, sdc1, and sdd1):
Create a file under sdb1

$ sudo touch /mnt/sdb1/file1

Show whats in the sdb1 mount point

$ ls -l /mnt/sdb1/
total 12
-rw-r--r-- 1 root root     0 Jun  4 23:16 file1
drwx------ 2 root root 12288 Jun  4 22:57 lost+found

Create a file under sdc1

$ sudo touch /mnt/sdc1/file2

Show whats in the sdc1 mount point

$ ls -l /mnt/sdc1/
total 12
-rw-r--r-- 1 root root     0 Jun  4 23:16 file2
drwx------ 2 root root 12288 Jun  4 23:04 lost+found

Create a file under sdd1

$ sudo touch /mnt/sdd1/file3

Show whats in the sdd1 mount point

$ ls -l /mnt/sdd1/
total 16
-rw-r--r-- 1 root root     0 Jun  4 23:16 file3
drwx------ 2 root root 16384 Jun  4 22:59 lost+found

If we look at /mnt/storage now, it should show the 3 files combined under the one mount point (and the lost+found folder).

$ ls -l /mnt/storage/
total 12
-rw-r--r-- 1 root root     0 Jun  4 23:16 file1
-rw-r--r-- 1 root root     0 Jun  4 23:16 file2
-rw-r--r-- 1 root root     0 Jun  4 23:16 file3
drwx------ 2 root root 12288 Jun  4 22:57 lost+found

If we create a file under /mnt/storage, mhddfs will work out which drive to store it on.

$ sudo touch /mnt/storage/file4

Show whats in /mnt/storage now

$ ls -l /mnt/storage/
total 12
-rw-r--r-- 1 root root     0 Jun  4 23:16 file1
-rw-r--r-- 1 root root     0 Jun  4 23:16 file2
-rw-r--r-- 1 root root     0 Jun  4 23:16 file3
-rw-r--r-- 1 root root     0 Jun  4 23:27 file4
drwx------ 2 root root 12288 Jun  4 22:57 lost+found

Now, if we look in all the individual drives, we can see it has saved ‘file4’ to the sdd1 partition.
Source mount point directory listing

$ ls -l /mnt/sd*
/mnt/sdb1:
total 12
-rw-r--r-- 1 root root     0 Jun  4 23:16 file1
drwx------ 2 root root 12288 Jun  4 22:57 lost+found
/mnt/sdc1:
total 12
-rw-r--r-- 1 root root     0 Jun  4 23:16 file2
drwx------ 2 root root 12288 Jun  4 23:04 lost+found
/mnt/sdd1:
total 16
-rw-r--r-- 1 root root     0 Jun  4 23:16 file3
-rw-r--r-- 1 root root     0 Jun  4 23:27 file4
drwx------ 2 root root 16384 Jun  4 22:59 lost+found

As you can see, the file has been stored under /mnt/sdd1 automatically. It determines this based on the drive that has the most free space. As noted earlier, that was /mnt/sdd1.

You Might Also Like