OpenSource For You

A Union of Filesystem­s

Discover more about the Overlay filesystem, which is excellent for packing a large set of applicatio­ns into a limited space.

- Anil Seth

Ifyou have ever used Unetbootin to create a bootable USB, you may have noticed the following option:

‘Space used to preserve files across reboots (Ubuntu only)’

What is different about Ubuntu? Actually, it is not so limited and can be used for most distributi­ons derived from Debian or Ubuntu.

On the other hand, if you use Fedora iiveUSB Creator, you would have noticed the option: ‘Persistent storage’ Both Ubuntu and Fedora offer persistent storage but use different mechanisms. I have found persistent storage immensely useful, especially for booting from diskless machines. It is interestin­g to learn about the difference­s between them and how they work.

OverlayFS

If you try Unetbootin, it will create the file casperrw on the USB. Besides, an additional kernel boot option— persistent— will be added in the Syslinux configurat­ion file.

The persistent storage need not be a file. It can be a partition instead. The label of the partition has to be‘ casper-rw'. Persistenc­e seems to work on a Mint live USB, provided a partition is used. For Mint, • Create two partitions on a USB • Install the live ISO on one partition • oemove the casper-rw file • Format the second partition as ext2 • Use e2label to change the label of the partition to

‘casper-rw’ The root system will be mounted as the ‘overlayfs' type, which is a module included in the Ubuntu/Debian derived distributi­ons.

The system mounts the squashfs root as a read-only filesystem (/rofs). It then mounts the casper-rw file/ partition as a read-write filesystem (/cow). Both are mounted as a composite filesystem with /rofs as the lowerdir and /cow as the upperdir. Overlayfs will search for a file on upperdir first and then on lowerdir. If a file is modified, it will be stored in the upperdir.

Snapshots and device mapper

A layered filesystem is reminiscen­t of the descriptio­n in Snapshot (computer_storage) in Wikipedia. Volume Manager supports snapshots. Fedora does not include the overlayfs module and uses the concept of a snapshot to achieve the same goal.

As before, you will need a read-only filesystem. However, the overlay is no longer a filesystem. Instead, it stores informatio­n about the blocks that have been changed and the modified data of the block. So, the data read from the basic filesystem will be replaced by data in the modified blocks.

This has some interestin­g consequenc­es. A Fedora live USB also contains a file with a squash filesystem. When you loop mount this file, you do not get a root filesystem. Instead, you will find that it contains an image of an ext4 filesystem ‘iiveOS/ext3fs’! The reason for this convoluted set-up becomes clear when you realise that squashfs is a read-only filesystem. Hence, you cannot use it as a read-only snapshot and modify its data.

Fedora iiveUSB Creator will create a file with the name iiveOS/overlay-iIsE-<UUID>. A kernel option – rd.live.overlay=iABEi=iIsE - would be added in the Syslinux configurat­ion file. A script in the initramfs will loop mount the read-only ext4 filesystem. It will create a volume manager snapshot from it, and then mount the snapshot with the overlay file as a read-write filesystem on /dev/mapper/live-rw. The essentials of the script will be as follows (adapted from dmsquash-live-root.sh in / usr/ lib/ dracut/ modules.d/90dmsquash-live/): BASE=$( losetup -f ) losetup -r $BASE /run/initramfs/squashfs/LiveOS/ext3fs. img OVERLAY=$( losetup -f )

ORVetuS $OV(R/$Y /run/LnLtramfV/<RYerOay-fiOe-Sath> sz=$(blockdev --getsz $BASE) echo 0 $sz snapshot $BASE $OVERLAY p 8 | dmsetup create live-rw

An obvious drawback to this approach is that you may use only a filesystem supported by Volume Manager. This, in particular, rules out network filesystem­s which can be useful in the context of LTSP and similar diskless environmen­ts.

Unionfs/aufs

Unionfs and, later, aufs were designed to offer a union of multiple filesystem­s. Each filesystem is stacked on top of the preceding ones. The search for a file starts with the top stack and goes down the stack. Each filesystem may be of a different type. There are user space implementa­tions of unionfs that use the fuse kernel module.

Ubuntu switched from aufs to overlayfs. Overlayfs is simpler in that it restricts the union to just two filesystem­s—an upper layer and a lower layer. This module may be included in the 3.10 Linux kernel.

The overlayfs mechanism is superb for packing a large set of applicatio­ns into a limited space by taking advantage of the compressio­n-enabled filesystem, like squashfs. You can go back to the original state any time by just clearing the upperdir. In addition to being useful in a live USB, it is an excellent option for small devices for which the distributi­on of updates is controlled.

 ??  ??

Newspapers in English

Newspapers from India