Merging Multiple Partitions

Earlier I talked about my awesome media/storage server named "stooge". I got 2 new 2TB SATA drives and wanted to merge them in a cool way without data-loss & reverse-usability and expense issues associated with other solutions like RAID & xfs.

My focus is storage capacity, not primarily data integrity, but I want it to be fairly secure, too. I want to be able to recover things on a per-drive basis, if I get any problems, so striping the 2 drives together is not an option. Basically, here is what I want: I want partitions that can stand-alone on their own, meaning that if I take a drive out of stooge, I want the filesystem to be readable and portable. I want one big mount that has media and incoming files (my largest file-collections,) split between the 2.

Joining Drives

I started by looking into unionfs, which lets you mount seperate partitions as if they are one. The problem is that it's not balanced, so whichever partion is priority1 will just fill up. I thought maybe I could do some hackery around ctime at boot to move older files to priority2 drive, and priority1 drive does all the write operations in running-mode, but this seemed awfully hacky. I then learned about mhddfs which allows something very similar to unionfs but balances on a file-structure level between multiple partitions. This is what I want.

Volume mounts

My 2 volumes are ext4, so they have some journaling recovery options for data-security. Here are their /etc/fstab entries. The options nodev,noexec,nobootwait make them be storage-only (nodev,noexec) I set nobootwait, so it will boot unattended, and I can ssh, even if the drives are funky. Your partitions are probably different. I used UUIDs sudo blkid so it won't mismount the wrong partition, but you can also use the dev name.

# /mnt/store1 on /dev/sda6
UUID=ac0b74b9-36e4-4897-9e44-53e397310681 /mnt/store1     ext4    nodev,noexec,nobootwait 0       2
# /mnt/store2 on /dev/sdb1
UUID=43db0993-98bd-4cfe-8243-9ab4b12271fd /mnt/store2     ext4    nodev,noexec,nobootwait 0       2

If you haven't made the directories yet, let's do that & ensure the directory permissions are cool:

sudo mkdir /mnt/store1 /mnt/store2 /share
sudo chown nobody:nogroup /mnt/store1 /mnt/store2 /share
sudo chmod 6775 /mnt/store1 /mnt/store2 /share

Empty out these dirs by moving files, if they have stuff before you mount. Now, mount them (or you can just reboot)

sudo mount /mnt/store1
sudo mount /mnt/store2

I double-checkled permissions of contained files/dirs, to ensure no probs, later:

sudo chown -R nobody:nogroup /mnt/store?
sudo chmod -R 775 /mnt/store?
sudo find /mnt/store? -type f -exec chmod 6664 {} +
sudo find /mnt/store? -type d -exec chmod 6775 {} +


First, let's install the needed tools:

sudo apt-get install mhddfs

Now, we can test it out (your partitions are probably different):

sudo mhddfs /mnt/store1,/mnt/store2 /share -o allow_other,uid=65534,gid=65534

You should get something that looks like this:

mhddfs: directory '/mnt/store1' added to list
mhddfs: directory '/mnt/store2' added to list
mhddfs: mount to: /share
mhddfs: move size limit 4294967296 bytes

Sweet! 4TBs of semi-reliable data!

I used uid=65534,gid=65534 to set mount perms to nobody:nogroup.

Ok, let's make it work on boot. Add this to fstab:

# unioned /share
mhddfs#/mnt/store1,/mnt/store2 /share fuse defaults,allow_other,uid=65534,gid=65534,mode=0775,nobootwait 0 0