Setting Up LUKS and Mergerfs + Snapraid on Proxmox

Wanted to use a combine storage but zfs pool cannot add mismatched drives so had to use another option: Snapraid

Snapraid and mergerfs diagram

Setting up LUKS on my disks

After setting up Proxmox on Debian with LUKS encryption on the disk, its now time for me to setup LUKS for all my hard drives. This was fairly straightforward.

Next, I shred all the disk contents since I am starting off clean:

Then I encrypted the disks

Following the instructions and providing the passphrases for all of my disks ensured that they become encrypted. Now that they are encrypted, they are no longer available to be mounted and used from the proxmox interface. So we must first unencrypt the disk and map it.

Then you can change your file system format of the unecrypted disk if you want

Next, I setup autodecrypt on startup, this won't be much of a security issue as the root directory of the proxmox and swap is already protected with LUKS encryption too. So there's no way for anyone to get the key file. First write your keyfile and make sure the permissions are strict:

Next, you setup auto-decrypt by going to the /etc/crypttab

When you save a keyfile like this, there's usually a hidden trailing character behind it (e.g: \n). You can use this command to take out any hidden trailing characters:

Test the keyfile and make sure it unlocks then close it again

Then, go to /etc/fstab to automatically mount your decrypted volumes on startup

After you are sure that everything's working update your grub and init-ramfs

This way it would be decrypted, mounted and ready to go when you reboot!

Note: If it still doesn't work, you can simply add your keyfile key to the passwords that would decrypt the disk

Setting up Snapraid and Mergerfs

Setting up Mergerfs

Install mergerfs if your system does not have it

First, we have to create a fused storage containing all the disks. Add this in the /etc/fstab:

/mnt/sda:/mnt/sdb:/mnt/sdc:

  • These are the source directories or mount points. It indicates that mergerfs will pool together the contents of these three directories (/mnt/sda, /mnt/sdb, /mnt/sdc) into a single merged filesystem. /mnt/storage:

  • This is the target directory where the merged view of the three source directories will be mounted. It will appear as if all the files in /mnt/sda, /mnt/sdb, and /mnt/sdc are in /mnt/storage. fuse.mergerfs:

  • This specifies that the filesystem type is fuse.mergerfs, which is a user-space filesystem that merges the contents of the source directories.

These are mount options for mergerfs. Here's what each means:

  • defaults: This refers to the default mount options provided by the system.

  • allow_other: This allows users other than the one who mounted the filesystem to access the merged filesystem.

  • use_ino: This option ensures that the filesystem uses inode numbers rom the underlying filesystems, which can be useful for certain backup and NFS operations.

  • category.create=mfs: This dictates the policy for creating new files. mfs stands for "Most Free Space," meaning new files will be written to the underlying drive that has the most free space available.

  • nonempty: This allows the target directory (/mnt/storage) to be non-empty at the time of mounting. Without this option, the directory must be empty.

  • 0 0: These are dump and pass options, used for filesystem checks. The first 0 indicates that the filesystem should not be dumped (backed up) by the dump command, and the second 0 indicates that the filesystem should not be checked during boot by fsck.

These are the primary options that are needed but feel free to check out all the options in mergerfs herearrow-up-right

After finishing first, test your configuration using the command:

If there's an error the system would output an error. Otherwise, you are fine!

Setting up Snapraid

Install snapraid if your system does not have snapraid

Next, you have to create at /etc/snapraid.conf. This is the snapraid configuration file where the contents, disks and parity files are written. If you have disks with different storage sizes, snapraid want the largest one to be a parity file. These are the files used by SnapRAID to store the parity data used in recovering in case of a data lost. Here's a sample snapraid.conf:

After modifying the config save the file. Try to store a sample file in one of the disks and then run the first sync

Next, setup a scheduled sync for snapraid using crontab

Choose you favority editor and then add this in crontab:

This will sync 1 am everyday by running the executable at /usr/bin/snapraid. Note that you can find where the snapraid executable is stored using:

Save and exit crontab. Now you have set up mergerfs and snapraid on your system.

Last updated