Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the use of the OverlayFS for the LiveOS root filesystem. #107

Merged
merged 3 commits into from
Mar 30, 2017

Conversation

FGrose
Copy link
Contributor

@FGrose FGrose commented Dec 20, 2015

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.

This implementation currently requires the enforcing=0 kernel command
line option. Further SELinux tuning may change this limitation.

(SELinux is supported in OverlayFS since kernel 4.8.)

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.

@FGrose
Copy link
Contributor Author

FGrose commented Dec 20, 2015

@bcl
Copy link
Contributor

bcl commented Dec 22, 2015

This is worth exploring, but if it can't support SELinux it can't be used for live installations. We also need to make sure that /dev/mapper/live-base or something similar points to the original base filesystem so that local changes don't get copied to the target during installation.

@FGrose
Copy link
Contributor Author

FGrose commented Dec 22, 2015

This version continues to provide /dev/mapper/live-base even with the rd.live.overlay.overlayfs option in order to be compatible with the current installation structures. Some users may eventually want to avoid any Device-mapper overhead, and the OverlayFS does depend on the read-only base image, ext3fs.img or rootfs.img, mounted at /run/rootfsbase.

The purpose of this version is to provide a means to optionally boot an OverlayFS version of LiveOS in Fedora Rawhide so that others can test its features and limitations, with the hope that those with expertise in SELinux and other affected components could explore adaptations to complete the integration.

@centos-ci
Copy link
Collaborator

Can one of the admins verify this patch?

1 similar comment
@centos-ci
Copy link
Collaborator

Can one of the admins verify this patch?

@haraldh
Copy link
Collaborator

haraldh commented Oct 20, 2016

ok to test

@Conan-Kudo
Copy link
Member

@bcl @FGrose My understanding is that this should work with SELinux now? I think Dan Walsh made it work in recent kernels so that Docker+SELinux+OverlayFS worked.

@centos-ci
Copy link
Collaborator

Can one of the admins verify this patch?

@FGrose FGrose force-pushed the overlayfs branch 3 times, most recently from ce9fe44 to 52fb5cf Compare January 8, 2017 05:15
@haraldh
Copy link
Collaborator

haraldh commented Jan 16, 2017

@centos-ci
ok to test

@haraldh
Copy link
Collaborator

haraldh commented Jan 16, 2017

@centos-ci
retest this please

@FGrose
Copy link
Contributor Author

FGrose commented Jan 16, 2017

I force pushed amended commits to simplify checking the overlayfs commandline argument for those cases where only one check is needed.

@FGrose
Copy link
Contributor Author

FGrose commented Jan 20, 2017

I force pushed a couple of fixes: 1. to better deal with the readonly_overlay code path for OverlayFS, and 2. to take advantage of the $sz variable while setting up live-osimg-min.
Here was the diff:

diff --git a/modules.d/90dmsquash-live/dmsquash-live-root.sh b/modules.d/90dmsquash-live/dmsquash-live-root.sh
index 987065b..60ef6c1 100755
--- a/modules.d/90dmsquash-live/dmsquash-live-root.sh
+++ b/modules.d/90dmsquash-live/dmsquash-live-root.sh
@@ -164,13 +164,15 @@ do_live_overlay() {
 
     # set up the snapshot
     sz=$(blockdev --getsz $BASE_LOOPDEV)
-    if [ -n "$readonly_overlay" ]; then
-        echo 0 $sz snapshot $BASE_LOOPDEV $OVERLAY_LOOPDEV P 8 | dmsetup create --readonly live-ro
-        base="/dev/mapper/live-ro"
-        over=$RO_OVERLAY_LOOPDEV
-    else
-        base=$BASE_LOOPDEV
-        over=$OVERLAY_LOOPDEV
+    if [ -z "$overlayfs" ]; then
+        if [ -n "$readonly_overlay" ]; then
+            echo 0 $sz snapshot $BASE_LOOPDEV $OVERLAY_LOOPDEV P 8 | dmsetup create --readonly live-ro
+            base="/dev/mapper/live-ro"
+            over=$RO_OVERLAY_LOOPDEV
+        else
+            base=$BASE_LOOPDEV
+            over=$OVERLAY_LOOPDEV
+        fi
     fi
 
     if [ -n "$thin_snapshot" ]; then
@@ -295,7 +297,7 @@ fi
 if [ -b "$OSMIN_LOOPDEV" ]; then
     # set up the devicemapper snapshot device, which will merge
     # the normal live fs image, and the delta, into a minimzied fs image
-    echo "0 $( blockdev --getsz $BASE_LOOPDEV ) snapshot $BASE_LOOPDEV $OSMIN_LOOPDEV P 8" | dmsetup create --readonly live-osimg-min
+    echo "0 $sz snapshot $BASE_LOOPDEV $OSMIN_LOOPDEV P 8" | dmsetup create --readonly live-osimg-min
 fi
 
 ROOTFLAGS="$(getarg rootflags)"
@@ -306,8 +308,8 @@ fi
 if [ -n "$overlayfs" ]; then
     mkdir -m 0755 /run/rootfsbase
     if [ -n "$reset_overlay" ] && [ -L /run/overlayfs ]; then
-        rm -r -- $(readlink /run/overlayfs)
-        mkdir -m 0755 $(readlink /run/overlayfs)
+        ovlfs=$(readlink /run/overlayfs)
+        rm -r -- ${ovlfs}/* ${ovlfs}/.*
     fi
     if [ -n "$readonly_overlay" ]; then
         mkdir -m 0755 /run/rootfsbase-r

@haraldh
Copy link
Collaborator

haraldh commented Jan 20, 2017

rm -r -- ${ovlfs}/* ${ovlfs}/.*

Wouldn't that lead to error messages like:

rm: refusing to remove '.' or '..' directory: skipping […]
rm: refusing to remove '.' or '..' directory: skipping […]

@haraldh
Copy link
Collaborator

haraldh commented Jan 20, 2017

@centos-ci
retest please

@haraldh
Copy link
Collaborator

haraldh commented Jan 20, 2017

@centos-ci
retest this please

@FGrose FGrose force-pushed the overlayfs branch 2 times, most recently from e818087 to ea30a6d Compare January 21, 2017 07:43
@FGrose
Copy link
Contributor Author

FGrose commented Jan 21, 2017

@haraldh re: rm -r -- ${ovlfs}/* ${ovlfs}/.* -- Yes, 2 message lines in several pages. This version drops them into /dev/null. (The directory must be kept to maintain the root_t context.)

I've force pushed a couple more fixes: 1. to deal properly with a missing OverlayFS overlay or an empty/zeroed DM overlay, and 2. to die if rd.live.overlay.overlayfs is specified with a Device-mapper overlay file. 3. Also shortened the execution path slightly for the newer images using the 'rootfs.img' name.
The diff from before is the following:

diff --git a/usr/lib/dracut/modules.d/90dmsquash-live/dmsquash-live-root.sh b/modules.d/90dmsquash-live/dmsquash-live-root.sh
index 6a5d0c2..0933130 100755
--- a/usr/lib/dracut/modules.d/90dmsquash-live/dmsquash-live-root.sh
+++ b/modules.d/90dmsquash-live/dmsquash-live-root.sh
@@ -118,8 +118,12 @@ do_live_overlay() {
             losetup $opt $OVERLAY_LOOPDEV /run/initramfs/overlayfs$pathspec
             umount -l /run/initramfs/overlayfs || :
             oltype=$(det_img_fs $OVERLAY_LOOPDEV)
-            if [ $oltype = DM_snapshot_cow ]; then
-                if [ -n "$reset_overlay" ]; then
+            if [ -z "$oltype" ] || [ "$oltype" = DM_snapshot_cow ]; then
+                if [ -n "$overlayfs" ]; then
+                    die "Found a Device-mapper overlay--not OverlayFS... " \
+                        "rd.live.overlay.overlayfs is not valid."
+                elif [ -n "$reset_overlay" ]; then
+                    info "Resetting the Device-mapper overlay."
                     dd if=/dev/zero of=$OVERLAY_LOOPDEV bs=64k count=1 conv=fsync 2>/dev/null
                 fi
             else
@@ -127,11 +131,12 @@ do_live_overlay() {
                 ln -s /run/initramfs/overlayfs/overlayfs /run/overlayfs$opt
                 ln -s /run/initramfs/overlayfs/ovlwork /run/ovlwork$opt
             fi
+            setup="yes"
         elif [ -d /run/initramfs/overlayfs$pathspec ]; then
             ln -s /run/initramfs/overlayfs$pathspec /run/overlayfs$opt
             ln -s /run/initramfs/overlayfs$pathspec/../ovlwork /run/ovlwork$opt
+            setup="yes"
         fi
-        setup="yes"
     fi
     if [ -n "$overlayfs" ]; then
         modprobe overlay
@@ -230,8 +235,7 @@ fi
 if [ -e /run/initramfs/live/${live_dir}/${squash_image} ]; then
     SQUASHED="/run/initramfs/live/${live_dir}/${squash_image}"
 fi
-
-if [ -e "$SQUASHED" ] ; then
+if [ -e "$SQUASHED" ]; then
     if [ -n "$live_ram" ]; then
         echo 'Copying live image to RAM...' > /dev/kmsg
         echo ' (this may take a minute)' > /dev/kmsg
@@ -245,17 +249,17 @@ if [ -e "$SQUASHED" ] ; then
     mkdir -m 0755 -p /run/initramfs/squashfs
     mount -n -t squashfs -o ro $SQUASHED_LOOPDEV /run/initramfs/squashfs
 
-    if [ -f /run/initramfs/squashfs/LiveOS/ext3fs.img ]; then
-        FSIMG="/run/initramfs/squashfs/LiveOS/ext3fs.img"
-    elif [ -f /run/initramfs/squashfs/LiveOS/rootfs.img ]; then
+    if [ -f /run/initramfs/squashfs/LiveOS/rootfs.img ]; then
         FSIMG="/run/initramfs/squashfs/LiveOS/rootfs.img"
+    elif [ -f /run/initramfs/squashfs/LiveOS/ext3fs.img ]; then
+        FSIMG="/run/initramfs/squashfs/LiveOS/ext3fs.img"
     fi
 else
     # we might have an embedded fs image to use as rootfs (uncompressed live)
-    if [ -e /run/initramfs/live/${live_dir}/ext3fs.img ]; then
-        FSIMG="/run/initramfs/live/${live_dir}/ext3fs.img"
-    elif [ -e /run/initramfs/live/${live_dir}/rootfs.img ]; then
+    if [ -e /run/initramfs/live/${live_dir}/rootfs.img ]; then
         FSIMG="/run/initramfs/live/${live_dir}/rootfs.img"
+    elif [ -e /run/initramfs/live/${live_dir}/ext3fs.img ]; then
+        FSIMG="/run/initramfs/live/${live_dir}/ext3fs.img"
     fi
     if [ -n "$live_ram" ]; then
         echo 'Copying live image to RAM...' > /dev/kmsg
@@ -309,7 +313,8 @@ if [ -n "$overlayfs" ]; then
     mkdir -m 0755 /run/rootfsbase
     if [ -n "$reset_overlay" ] && [ -L /run/overlayfs ]; then
         ovlfs=$(readlink /run/overlayfs)
-        rm -r -- ${ovlfs}/* ${ovlfs}/.*
+        info "Resetting the OverlayFS overlay directory."
+        rm -r -- ${ovlfs}/* ${ovlfs}/.* >/dev/null 2>&1
     fi
     if [ -n "$readonly_overlay" ]; then
         mkdir -m 0755 /run/rootfsbase-r
(END)

@FGrose FGrose force-pushed the overlayfs branch 5 times, most recently from d04c836 to 37d150c Compare January 23, 2017 21:00
@FGrose
Copy link
Contributor Author

FGrose commented Jan 23, 2017

This rebased commit accomplishes the OverlayFS feature and includes the fixes from pull request #190, superseding it, if this commit is accepted.

See also some testing of sudo dnf upgrade on a LiveOS with OverlayFS at issue #104.

@haraldh
Copy link
Collaborator

haraldh commented Jan 25, 2017

@centos-ci
retest this please

@FGrose FGrose force-pushed the overlayfs branch 5 times, most recently from 4a4a876 to 572a6e2 Compare February 1, 2017 05:08
@Conan-Kudo
Copy link
Member

@FGrose @haraldh How does this look now?

@haraldh
Copy link
Collaborator

haraldh commented Mar 8, 2017

@centos-ci
retest this please

@FGrose
Copy link
Contributor Author

FGrose commented Mar 9, 2017

Added documentation for the OverlayFS overlays.

Added feedback for missing overlays. But I couldn't find a more generic test for an active plymouth splash, such as rhgb, in the DRACUT_SYSTEMD case.

To avoid two separate plymouth calls, I tried:
systemd-ask-password --timeout=0 message, but the rhgb case fails to show the message prompt (a bug, I think, in plymouth). If I could sendkey <Esc>, this would show the startup console.

I also tried

cat > /run/systemd/ask-password/ask.0000<<EOF
[Ask]
Socket=/dev/null
Message=${m[*]}
timeout=0
EOF

but the message is limited to a single line and the notification doesn't pause and is lost in a lot of other messages at the startup console.

The revised commit below, covers the case where plymouth is not available.

@FGrose FGrose force-pushed the overlayfs branch 2 times, most recently from 6a60a4c to d906d66 Compare March 10, 2017 01:14
FGrose added 2 commits March 11, 2017 00:42
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.
Provide a more prominent alert to the user if an overlay is
missing or the overlay module is not available and a temporary
overlay will be provided.  This, to avoid losing data intended to
persist.
Support the rd.live.overlay.readonly option for writable images,
such as rd.live.overlay=none and rd.writable.fsimg.
@Conan-Kudo
Copy link
Member

@haraldh It looks like the current test failures are not related to this PR, and the latest test run in master appears to be broken on the same tests.

At this point, could you consider it acceptable to merge so that it could be available in Fedora 26? @FGrose has prepared changes for my project (livecd-tools) to be able to leverage overlayfs for live media, and I'd like to pull that in and make it available for livecd-tools v26.

@haraldh haraldh merged commit 3c6337f into dracutdevs:master Mar 30, 2017
@haraldh
Copy link
Collaborator

haraldh commented Mar 30, 2017

tested locally and pushed manually

@FGrose
Copy link
Contributor Author

FGrose commented Apr 9, 2017

See pull request #217 for a fix needed for newer mount utilities on Fedora 26.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants