AUFS (Another/Advanced Union Filesystem) for NAS storage

Since my NAS melted slightly (here) I decided to rethink my approach to storage on the device. I would always lean towards a RAID if I needed redundancy and I have used RAID5 successfully in the past. I had been using an LVM volume but when I came to replace my burnt disk, the LVM config proved a little too cumbersome to work through with all the resizing volumes, getting disk sizes right, etc. I wanted something simplier.

So I came across AUFS (Advanced/Another Union File System). It lets you mount various devices and folders in one mount point. They don’t even need to be the same filesystem. The mount point then treats everything as one combined volume. So I can add all my drives to the NAS as individual devices. Then tell AUFS to treat them as a single volume. AUFS will handle the job of allocating individual files to particular devices. And when I access the devices directly I will obviously only be able to see a portion of my total files but I will still be able to read and write to the device.

So essentially it has all the advantages of the LVM approach with the extra benefits of:
– Being able to access the files on the drives individually should I need to.
– Quicker and much more user friendly way of replacing drives and/or expanding the array.

This makes drive failures very easy to recover from. If a drive fails, just pull it out and drop in the new one. Then rsync from my backup to re-populate the missing files. Of course I’m happy to run the risk of a small number of files not having been backed up to my secondary NAS at the time of failure. This is because I have a few services running and constantly backing up my most critical files (documents and photos): Dropbox and Google Photos.

So lets get to work…

1. ID Drives
I wanted to be able to track my drives by their unique serial number printed on the outside of the drive. Makes for later easier identification just by looking at the physical drive if one should start to play up.
To see how linux has allocated each drive at the moment we can run:

Later we’ll use this info for mounting our drives according to their UUID and put them in a mount point labelled with their serial number.

2. Partition each disk (if your disks are larger than 2TB follow my guide here to partition and format them)

Delete any existing partitions…
d
Make a new partition…
n -> p -> [Enter] -> [Enter] -> [Enter]
Since it will be ext4 we don’t need to specify a type. If it was for an LVM volume we would change the type with the ‘t’ command.

3. Format the partition and remove the 5% reserved for system since this is only a storage drive

Do this for all your disks.

4. Make a mount point & mount device
Note that we are going to use the drive’s UUID to mount it to a folder named after the drive serial number to make sure the same drive is mounted in the same useful location each time. This is because Linux allocates device numbers on what can seem like a random basis, e.g. /dev/sda may be /dev/sdb the next time.
List disks by UUID with

Make directories and mount each drive

For example I used:

5. Make mounts persistent
Add this line to your /etc/fstab file for each drive…

For example I used:

6. Install AuFS

7. Mount our drives as an unified mount point

Make the mount point for AUFS

Mount the AUFS volume(all one line)

Options used:
udba=reval : aufs will reevaluate the devices to make sure any changes made directly to the mount points (but not via the aufs mount oint) are properly updated.
sum : report the correct free space for the aufs mount point. Without this it only reports the free space on the first device in the mount list
create=mfs : aufs will use the device with the Most Free Space first when creating new files. I like this as it spreads your files out across your disks more evenly which means less loss in the case of failure. Of course, you should have another backup so in reality it means that it saves you time restoring when you only lose an even portion of your files on disk failure.

I like to have a directory called ‘shared’ in my NAS root which is where my shared files like. You can create a symlink to this directory so that it points to the AUFS mount point with this ln command

 

8. Make AuFS mount point persistent
I couldn’t work out what the fstab entry for aufs mount points should be so I just put the mount command in the rc.local file which gets run on system startup, a simple  nano /etc/rc.local and add the mount command above.

9. Export AUFS via NFS

I use NFS exports to share my files with other divices in the house. To make sure the AUFS mount worked with NFS I found I had to add ‘crossmnt’ to my /etc/exports file. My /etc/exports file looks like:

 

Useful Sources

1 Comment

  1. Had exactly the same thought, I am just playing with an ARM64 SBC that has USB3.0 and was thinking that for many storage is over complex.
    With SSD and USB throughput if a device is RAID or not is a matter of choice, but I do think storage should become plug & play where if you want more space just add another JAA.

    Hopefully I will be able to create an app for https://nextcloud.com/ on the https://www.pine64.org/?page_id=7147 as for consumers adding more storage should just be a matter of JAA.

Leave a Reply

(email optional)