How can I merge 2 mounted volumes on Debian 10?

Viewed 164

I've got 2 volumes already mounted on a VPS from Hetzner.

The first one is on / with 1To space. The other one on /home with 2To space.

I want to get my 3 To together, how can I manage to merge those 2 volumes without erasing any data ?

Here is a picture of what a df -h looks like :

df -h

Thanks you very much !

1 Answers

You can merge them using a union filesystem. https://en.wikipedia.org/wiki/UnionFS

In Linux, you can find several kernel modules implementing a union fileystem such as aufs and overlayfs. Available modules may vary depending on kernel configuration in your vps. I will give you a configuration example using the aufs kernel module.

In first, create a subdirectory for each mount point:

mkdir -p /for-aufs
mkdir -p /home/for-aufs

To continue, create a directory for the aufs mount point:

mkdir -p /aufs

Edit your /etc/fstab file

none /aufs aufs br:/for-aufs=rw:/home/for-aufs=rw,sum,create=rr 0 0

Or using mount directly:

mount -t aufs -o br:/for-aufs=rw:/home/for-aufs=rw,sum,create=rr none /aufs

Then, you will see a new mount point in /aufs linked to /for-aufs (/dev/md2) and /home/for-aufs (/dev/md3) when executing df -h. When you are using /aufs mount point, a round-robing policy will create/modify files between /for-aufs and /home/for-aufs.

In conclusion, /for-aufs + /home/for-aufs = /aufs

Remember to read the manual for more information: http://manpages.ubuntu.com/manpages/focal/man5/aufs.5.html

Related