Writing to read-only devices with aufs2
Invisible Ink
Add temporary write capability to a read-only device with the stacked filesystem aufs.
Aufs [1] is a stacked filesystem similar to UnionFS [2]. One very common use for aufs is adding "temporary writing" capability to a filesystem residing on read-only media. I use aufs in Knoppix to join read-only data from the compressed Knoppix file (usually located on a CD or DVD) with a read-write filesystem on ramdisk or a USB flash drive. A stacked filesystem creates a stack of existing directories that are "transparent" to the user: Each access to a file is tried for each directory of the stack until it succeeds or the end of the stack is reached.
Even if you aren't building your own Live system, you still might have a practical use for aufs as a means of adding virtual read-write access to files stored on a read-only device. In this article, I describe how to add temporary write capability to a read-only device using aufs.
Gitting Aufs2
Aufs2 comes in two forms: a complete Git-based kernel with aufs2 included and a "standalone" version that contains only the changes that have to be patched into the kernel source.
Because checking out the complete aufs2-patched kernel is probably not the most common scenario and because compiling the ready-to-build version is no real challenge, I will describe the procedure for adding the standalone version of aufs2 to the vanilla kernel source, which you can always get from the Linux Kernel Archives [3].
The following examples are based on kernel version 2.6.29, which resides in a subdirectory of the current working directory and is called linux-2.6.29.
If you have never used git before, it might be missing from your development system. On Debian-based systems, the command for installing it is
aptitude install git-core
For other package management systems, consult your vendor documentation.
The command to check out aufs2 as standalone patch for kernel 2.6.29 is:
git clone http://git.c3sl.ufpr.br/pub/scm/aufs/aufs2-standalone.git aufs2-standalone.git
After this command, aufs2-standalone.git will be a local copy of the aufs2-standalone Git repository.
The command
git checkout origin/aufs2-29
checks out the aufs2 version for kernel 2.6.29 (note the 29 at the end of the command parameters) and defines it as the current working version. You might see a Git note or warning about origin/aufs2-29 not being a local branch, which you can safely ignore at this point.
Listing 1 shows the current working directory aufs2-standalone.git (ls -l). The directory fs includes the aufs2 source, and the include directory holds the necessary kernel include files for aufs2. Both must be copied into the kernel source directory.
Listing 1
aufs2-standalone.git (ls -l )
Adding Aufs2 Source Files
If your kernel source is located one directory above in linux-2.6.29, enter:
cd ../linux-2.6.29 cp -a ../aufs2-standalone.git/{fs,include,Documentation} . cp ../aufs2-standalone.git/config.mk fs/aufs/
The aufs2 README describes aufs2 installation differently, but I find that the method of copying all additional aufs2 source files directly to the kernel source tree is a convenient way for building ready-to-use Linux kernel image packages in Debian containing aufs2 without the need to create a modules/aufs subdirectory with a corresponding external module infrastructure.
Patching the Kernel
In the aufs2-standalone.git directory (Listing 1), you might have noticed a file called aufs2-standalone.patch. This file contains changes that have to be made to various filesystem-related places of the original kernel source. The kernel's Makefile and configuration system also require that some changes be made to them so that aufs2 will be visible as a new filesystem in make menuconfig. From the current directory, linux-2.6.29, use patch as follows,
patch -p1 < ../aufs2-standalone.git/aufs2-standalone.patch
which produces the output shown in Listing 2.
If you see no lines to indicate that an error has resulted from the patch, then everything is now set up and ready to compile.
Listing 2
Patching Files
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.