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:
hdparm -I /dev/sd[a-e] | grep 'Serial Number\|device size with M = 1000\|\/dev\/s'
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)
fdisk /dev/sda
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
mkfs -t ext4 /dev/sda1 tune2fs -m 0 /dev/sda1
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
ls -l /dev/disk/by-uuid
Make directories and mount each drive
mkdir /mnt/[serial #] mount -U [UUID] /mnt/sda1
For example I used:
mkdir /mnt/4Tb_S301J8YS mount -U b00867f0-5b1f-4983-a1f7-5456e7b31023 /mnt/4Tb_S301J8YS mkdir /mnt/1Tb_STF604MR290K1P mount -U aa1721d0-dd63-4df4-a13f-aa2ad7283b7b /mnt/1Tb_STF604MR290K1P mkdir /mnt/1Tb_STF604MR2P210P mount -U 8af4fecd-c84e-4e3a-a678-277e15dde4d6 /mnt/1Tb_STF604MR2P210P
5. Make mounts persistent
Add this line to your /etc/fstab file for each drive…
UUID={YOUR-UID} {/path/to/mount/point} {file-system-type} defaults,errors=remount-ro 0 1
For example I used:
UUID=b00867f0-5b1f-4983-a1f7-5456e7b31023 /mnt/4Tb_S301J8YS ext4 defaults,errors=remount-ro,nobootwait 0 2 UUID=aa1721d0-dd63-4df4-a13f-aa2ad7283b7b /mnt/1Tb_STF604MR290K1P ext4 defaults,errors=remount-ro,nobootwait 0 2 UUID=8af4fecd-c84e-4e3a-a678-277e15dde4d6 /mnt/1Tb_STF604MR2P210P ext4 defaults,errors=remount-ro,nobootwait 0 2
6. Install AuFS
apt-get install aufs-tools
7. Mount our drives as an unified mount point
Make the mount point for AUFS
mkdir /mnt/aufs-shared
Mount the AUFS volume(all one line)
mount -t aufs -o br=/mnt/1Tb_STF604MR290K1P=rw:/mnt/1Tb_STF604MR2P210P=rw:/mnt/4Tb_S301J8YS=rw -o udba=reval -o create=mfs -o sum none /mnt/aufs-shared
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
ln -s /mnt/aufs-shared /shared
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:
/mnt/aufs-shared (insecure,no_root_squash,rw,nohide,fsid=0,crossmnt)
Useful Sources
- http://www.thegeekstuff.com/2013/05/linux-aufs/
- http://aufs.sourceforge.net/aufs4/man.html
- https://en.wikipedia.org/wiki/Aufs
- http://www.cyberciti.biz/faq/linux-finding-using-uuids-to-update-fstab/
- http://www.softpanorama.org/Commercial_linuxes/Devices/managing_your_disks_by_uuid.shtml
- https://odzangba.wordpress.com/2010/02/20/how-to-free-reserved-space-on-ext4-partitions/
- http://ubuntuforums.org/showthread.php?t=2182009
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.