📜 ⬆️ ⬇️

mhddfs - Mounting multiple partitions in one directory

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

Ubuntu 14.04 was used as the operating system.

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

We mount both sections. To do this, create the mount points in / mnt .
')
~# mkdir /mnt/sda3 ~# mkdir /mnt/sdb1 ~# mount /dev/sda3 /mnt/sda3 ~# mount /dev/sdb1 /mnt/sdb1 


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 utility mhddfs , which will allow us to merge both of these sections into one.

 ~# apt-get install mhddfs 


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

 ~# 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 of 826GB and 917GB in size, one with a volume of 1.8Tb.

The original article used the mount option -o allow_other , which allows other users to have access to the partition, but I don’t need it, because there is only one user in the system.

And now unmount (or unmount) / home and make it so that partitions are mounted when the system boots. 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 will correct / 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 indicates that there should be at least 10 gigabytes of free space on any partition. This means that if there is 10 gigabytes of free space left, then this section will no longer be recorded.

And now it remains to check whether we have 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. Checking:

  ~# 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. To be sure, you can reboot the system.

And by the way, you can copy files either to the combined / home directory, or to the / mnt / sda3 or / mnt / sdb1 directory. Files still appear in / home as if they were on the same partition. And it is noticed that if you copy to / home , then the files are copied to the partition that is first in the mount order, that is, to sda3 . I suppose that this will happen until a limit of 10 GB 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 in one directory and with different file systems. In practice, I did not check, I can not confirm.

Source: https://habr.com/ru/post/264853/


All Articles