Skip to content

Commit

Permalink
Enable the use of the OverlayFS for the LiveOS root filesystem.
Browse files Browse the repository at this point in the history
Integrate the option to use an OverlayFS as the root filesystem
into the 90dmsquash-live module for testing purposes.

The rd.live.overlay.overlayfs option allows one to request an
OverlayFS overlay.  If a persistent overlay is detected at the
standard LiveOS path, the overlay & type detected will be used.

Tested primarily with transient, in-RAM overlay boots on vfat-
formatted Live USB devices, with persistent overlay directories
on ext4-formatted Live USB devices, and with embedded, persistent
overlay directories on vfat-formatted devices. (Persistent overlay
directories on a vfat-formatted device must be in an embedded
filesystem that supports the creation of trusted.* extended
attributes, and must provide valid d_type in readdir responses.)

The rd.live.overlay.readonly option, which allows a persistent
overlayfs to be mounted read only through a higher level transient
overlay directory, has been implemented through the multiple lower
layers feature of OverlayFS.

The default transient DM overlay size has been adjusted up to 32 GiB.
This change supports comparison of transient Device-mapper vs.
transient OverlayFS overlay performance.  A transient DM overlay
is a sparse file in memory, so this setting does not consume more
RAM for legacy applications.  It does permit a user to use all of
the available root filesystem storage, and fails gently when it is
consumed, as the available free root filesystem storage on a typical
LiveOS build is only a few GiB.  Thus, when booted on other-
than-small RAM systems, the transient DM overlay should not overflow.

OverlayFS offers the potential to use all of the available free RAM
or all of the available free disc storage (on non-vfat-devices)
in its overlay, even beyond the root filesystem available space,
because the OverlayFS root filesystem is a union of directories on
two different partitions.

This patch also cleans up some message spew at shutdown, shortens
the execution path in a couple of places, and uses persistent
DM targets where required.

Documentation is updated for these changes.
  • Loading branch information
FGrose committed Mar 11, 2017
1 parent 4693daa commit ea28824
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 74 deletions.
44 changes: 35 additions & 9 deletions dracut.cmdline.7.asc
Original file line number Diff line number Diff line change
Expand Up @@ -820,10 +820,12 @@ only filesystem from the SquashFS and apply a writable device-mapper snapshot
over the read only filesystem. Using this method ensures a relatively fast
boot and lower RAM usage. Users **must be careful** to avoid writing too many
blocks to the snapshot volume. Once the blocks of the snapshot overlay are
exhausted, the root filesystem becomes unusable and requires a reboot. A
persistent overlay is marked Invalid, and requires a difficult recovery.
Non-persistent overlays default to 512 MiB in RAM, but the size can be adjusted
with the **rd.live.overlay.size=** kernel command line option.
exhausted, the root filesystem becomes read only and may cause application
failures. The overlay file is marked 'Overflow', and a difficult recovery is
required to repair and enlarge the overlay offline. Non-persistent overlays
are sparse files in RAM that only consume content space as required blocks are
allocated. They default to an apparent size of 32 GiB in RAM. The size can be
adjusted with the **rd.live.overlay.size=** kernel command line option.
+
The filesystem structure is expected to be:
+
Expand All @@ -832,7 +834,7 @@ The filesystem structure is expected to be:
squashfs.img | Squashfs from LiveCD .iso downloaded via network
!(mount)
/LiveOS
|- ext3fs.img | Filesystem image to mount read-only
|- rootfs.img | Filesystem image to mount read-only
!(mount)
/bin | Live filesystem
/boot |
Expand All @@ -854,7 +856,7 @@ of the root filesystem.
Uncompressed live filesystem image:::
When the live system was installed with the '--skipcompress' option of the
__livecd-iso-to-disk__ installation script for Live USB devices, the root
filesystem image, `ext3fs.img`, is expanded on installation and no SquashFS
filesystem image, `rootfs.img`, is expanded on installation and no SquashFS
is involved during boot.
+
- If **rd.live.ram=1** is used in this situation, the full, uncompressed
Expand Down Expand Up @@ -919,8 +921,8 @@ root=live:torrent://example.com/liveboot.img.torrent
Enables debug output from the live boot process.
**rd.live.dir=**__<path>__::
Specifies the directory within the squashfs where the ext3fs.img or rootfs.img
can be found. By default, this is __LiveOS__.
Specifies the directory within the boot device where the squashfs.img or
rootfs.img can be found. By default, this is __LiveOS__.
**rd.live.squashimg=**__<filename of SquashFS image>__::
Specifies the filename for a SquashFS image of the root filesystem.
Expand All @@ -938,6 +940,8 @@ used to persist the changes made to the device specified by the
**root=live:__<url>__** option.
- _none_ specifies no overlay when an uncompressed live root filesystem is
available.
If a persistent overlay is detected at the standard LiveOS path, the overlay &
overlay type detected (whether Device-mapper or OverlayFS) will be used.
+
[listing]
.Example
Expand All @@ -946,7 +950,7 @@ rd.live.overlay=/dev/sdb1:persistent-overlay.img
--
**rd.live.overlay.size=**__<size_MiB>__::
Specifies a non-persistent overlay size in MiB. The default is _512_.
Specifies a non-persistent overlay size in MiB. The default is _32768_.
**rd.live.overlay.readonly=**1::
Specifies a non-persistent, writable snapshot overlay to be stacked over a
Expand All @@ -963,6 +967,28 @@ blocks that are not claimed by the filesystem. In this use case, this means
that memory is given back to the kernel when the filesystem does not claim it
anymore.
**rd.live.overlay.overlayfs=**1::
Enables the use of the **OverlayFS** kernel module, if available, to provide a
copy-on-write union directory for the root filesystem. OverlayFS overlays are
directories of the files that have changed on the read-only base (lower)
filesystem. The root filesystem is provided through a special overlay type
mount that merges the lower and upper directories. If an OverlayFS upper
directory is not present on the boot device, a tmpfs directory will be created
at /run/overlayfs to provide temporary storage. Persistent storage can be
provided on vfat or msdos formatted devices by supplying the OverlayFS upper
directory within an embedded filesystem that supports the creation of trusted.*
extended attributes and provides a valid d_type in readdir responses, such as
with ext4 and xfs. On non-vfat-formatted devices, a persistent OverlayFS
overlay can extend the available root filesystem storage up to the capacity of
the LiveOS device.
If a persistent overlay is detected at the standard LiveOS path, the overlay &
overlay type detected (whether OverlayFS or Device-mapper) will be used.
The **rd.live.overlay.readonly** option, which allows a persistent overlayfs to
be mounted read only through a higher level transient overlay directory, has
been implemented through the multiple lower layers feature of OverlayFS.
Plymouth Boot Splash
~~~~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 2 additions & 1 deletion modules.d/90dm/dm-shutdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ _do_dm_shutdown() {
return $ret
}

if command -v dmsetup >/dev/null; then
if command -v dmsetup >/dev/null &&
[ "x$(dmsetup status)" != "xNo devices found" ]; then
_do_dm_shutdown $1
else
:
Expand Down
2 changes: 1 addition & 1 deletion modules.d/90dmsquash-live/apply-live-updates.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

if [ -b /dev/mapper/live-rw ] && [ -d /run/initramfs/live/updates -o -d /updates ]; then
if [ -L /run/rootfsbase ] && [ -d /run/initramfs/live/updates -o -d /updates ]; then
info "Applying updates to live image..."
mount -o bind /run $NEWROOT/run
# avoid overwriting symlinks (e.g. /lib -> /usr/lib) with directories
Expand Down
19 changes: 14 additions & 5 deletions modules.d/90dmsquash-live/dmsquash-generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,30 @@ esac

GENERATOR_DIR="$2"
[ -z "$GENERATOR_DIR" ] && exit 1

[ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR"

getargbool 0 rd.live.overlay.overlayfs && overlayfs="yes"
[ -e /xor_overlayfs ] && xor_overlayfs="yes"
ROOTFLAGS="$(getarg rootflags)"
{
echo "[Unit]"
echo "Before=initrd-root-fs.target"
echo "[Mount]"
echo "Where=/sysroot"
echo "What=/dev/mapper/live-rw"
[ -n "$ROOTFLAGS" ] && echo "Options=${ROOTFLAGS}"
if [ "$overlayfs$xor_overlayfs" = "yes" ]; then
echo "What=LiveOS_rootfs"
echo "Options=${ROOTFLAGS},lowerdir=/run/rootfsbase,upperdir=/run/overlayfs,workdir=/run/ovlwork"
echo "Type=overlay"
_dev=LiveOS_rootfs
else
echo "What=/dev/mapper/live-rw"
[ -n "$ROOTFLAGS" ] && echo "Options=${ROOTFLAGS}"
_dev=dev-mapper-live\x2drw
fi
} > "$GENERATOR_DIR"/sysroot.mount

mkdir -p "$GENERATOR_DIR/dev-mapper-live\x2drw.device.d"
mkdir -p "$GENERATOR_DIR/$_dev.device.d"
{
echo "[Unit]"
echo "JobTimeoutSec=3000"
} > "$GENERATOR_DIR/dev-mapper-live\x2drw.device.d/timeout.conf"
} > "$GENERATOR_DIR/$_dev.device.d/timeout.conf"
Loading

0 comments on commit ea28824

Please sign in to comment.