mhddfs - Mounting multiple partitions in one directory

    I want to talk about how to mount two sections in one directory.
    Honestly, I never thought about such an opportunity until I came across a client with a similar wish. At first it seemed to me that this was impossible, but digging through the Internet I found a couple of interesting articles. An article from the site hotbits.ru was taken as the basis for the work . But in the article mounted partitions of the same disk, I had to mount partitions from different disks. As it turned out, there is no difference.

    The operating system used of Ubuntu 14.04 .

    The first thing to do is create the partitions themselves.
    In my case, it was the / dev / sda3 partition located on the system drive and the / dev / sdb1 partitionwhich occupied the entire second disk.

    Mount both sections. To do this, create mount points in / mnt .

    ~# mkdir /mnt/sda3
    ~# mkdir /mnt/sdb1
    ~# mount /dev/sda3 /mnt/sda3
    ~# mount /dev/sdb1 /mnt/sdb1
    


    We look what happened

    ~# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda1        85G  1.1G   79G   2% /
    none            4.0K     0  4.0K   0% /sys/fs/cgroup
    udev            3.9G  4.0K  3.9G   1% /dev
    tmpfs           796M  412K  796M   1% /run
    none            5.0M     0  5.0M   0% /run/lock
    none            3.9G     0  3.9G   0% /run/shm
    none            100M     0  100M   0% /run/user
    /dev/sda3       826G   73M  784G   1% /mnt/sda3
    /dev/sdb1       917G   72M  871G   1% /mnt/sdb1
    


    Next, install the special mhddfs utility , which will allow us to merge both of these sections into one.

    ~# apt-get install mhddfs
    


    We will mount both sections in the directory in / home .
    To do this, do:

    ~# mhddfs /mnt/sda3,/mnt/sdb1 /home
    mhddfs: directory '/mnt/sda3' added to list
    mhddfs: directory '/mnt/sdb1' added to list
    mhddfs: mount to: /home
    mhddfs: move size limit 4294967296 bytes
    


    Check

    ~# df -h
    Filesystem           Size  Used Avail Use% Mounted on
    /dev/sda1             85G  1.2G   79G   2% /
    none                 4.0K     0  4.0K   0% /sys/fs/cgroup
    udev                 3.9G  4.0K  3.9G   1% /dev
    tmpfs                796M  412K  796M   1% /run
    none                 5.0M     0  5.0M   0% /run/lock
    none                 3.9G     0  3.9G   0% /run/shm
    none                 100M     0  100M   0% /run/user
    /dev/sda3            826G   73M  784G   1% /mnt/sda3
    /dev/sdb1            917G   72M  871G   1% /mnt/sdb1
    /mnt/sda3;/mnt/sdb1  1.8T  144M  1.7T   1% /home
    


    Everything was mounted and as a result, we have instead of two separate mount points with sizes of 826GB and 917GB, one with a capacity of 1.8Tb.

    In the original article, the -o allow_other mount option was used , which allows other users to have access to the partition, but I do not need it, because the user is on the system alone.

    Now unmount (or unmount) / home and make the partitions mounted at boot time. This is natural, no one will manually mount partitions every time, but to mount at boot time, you need to add the fuse module .

    ~# echo "fuse" >> /etc/modules
    


    And now we’ll fix / etc / fstab by adding the following lines to it:

    /dev/sda3 /mnt/sda3 ext4 defaults 0 2
    /dev/sdb1 /mnt/sdb1 ext4 defaults 0 2
    mhddfs#/mnt/sda3,/mnt/sdb1 /home fuse defaults,mlimit=10G 0 0
    


    mlimit = 10G shows that at least 10 gigabytes of free space should remain on any of the partitions. This means that if 10 gigabytes of free space is left, then this section will no longer be recorded.

    And now it remains to check whether we correctly registered everything in fstab . We do:

    ~# mount -a
    mhddfs: directory '/mnt/sda3' added to list
    mhddfs: directory '/mnt/sdb1' added to list
    mhddfs: mount to: /home
    mhddfs: move size limit 10737418240 bytes
    


    There are no errors, therefore everything is in order. We check:

     ~# df -h
    Filesystem           Size  Used Avail Use% Mounted on
    /dev/sda1             85G  1.2G   79G   2% /
    none                 4.0K     0  4.0K   0% /sys/fs/cgroup
    udev                 3.9G  4.0K  3.9G   1% /dev
    tmpfs                796M  412K  796M   1% /run
    none                 5.0M     0  5.0M   0% /run/lock
    none                 3.9G     0  3.9G   0% /run/shm
    none                 100M     0  100M   0% /run/user
    /dev/sda3            826G   73M  784G   1% /mnt/sda3
    /dev/sdb1            917G   72M  871G   1% /mnt/sdb1
    /mnt/sda3;/mnt/sdb1  1.8T  144M  1.7T   1% /home
    


    Everything is in place, the task is completed. For confidence, you can reboot the system.

    And by the way, you can copy files to the combined directory / home , or to the directory / mnt / sda3 or / mnt / sdb1 . Files still appear in / home as if they were on the same partition. And I noticed that if you copy it to / home , the files are copied to the partition that is mounted in the first order, that is, on sda3 . I assume that this will happen until the 10 GB limit is reached, and only then the files will be copied to sdb1 .

    That's all.

    PS If you believe the source, then you can mount more than two partitions with different file systems in one directory. In practice, I did not check this, I can’t confirm it.

    Also popular now: