dmsquash-live, livenet: Simplify OverlayFS read-only overlay setup.

Use multiple lower layer directories in a single OverlayFS mount with
  a transient overlay directory.
Tolerate a command line with rd.live.overlay.readonly and NO persistent
  overlay by reconfiguring the OverlayFS mount options.
Use more compatible shell syntax for testing symlinks, and use printf
  instead of echo -e.
master
Frederick Grose 2018-08-20 19:52:53 -04:00 committed by Harald Hoyer
parent 789668deb3
commit eb18a1fe29
3 changed files with 35 additions and 17 deletions

View File

@ -54,8 +54,10 @@ GENERATOR_DIR="$2"
[ -z "$GENERATOR_DIR" ] && exit 1 [ -z "$GENERATOR_DIR" ] && exit 1
[ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR" [ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR"


getargbool 0 rd.live.overlay.readonly -d -y readonly_overlay && readonly_overlay="--readonly" || readonly_overlay=""
getargbool 0 rd.live.overlay.overlayfs && overlayfs="yes" getargbool 0 rd.live.overlay.overlayfs && overlayfs="yes"
[ -e /xor_overlayfs ] && xor_overlayfs="yes" [ -e /xor_overlayfs ] && xor_overlayfs="yes"
[ -e /xor_readonly ] && xor_readonly="--readonly"
ROOTFLAGS="$(getarg rootflags)" ROOTFLAGS="$(getarg rootflags)"
{ {
echo "[Unit]" echo "[Unit]"
@ -64,7 +66,12 @@ ROOTFLAGS="$(getarg rootflags)"
echo "Where=/sysroot" echo "Where=/sysroot"
if [ "$overlayfs$xor_overlayfs" = "yes" ]; then if [ "$overlayfs$xor_overlayfs" = "yes" ]; then
echo "What=LiveOS_rootfs" echo "What=LiveOS_rootfs"
echo "Options=${ROOTFLAGS},lowerdir=/run/rootfsbase,upperdir=/run/overlayfs,workdir=/run/ovlwork" if [ "$readonly_overlay$xor_readonly" = "--readonly" ]; then
ovlfs=lowerdir=/run/overlayfs-r:/run/rootfsbase
else
ovlfs=lowerdir=/run/rootfsbase
fi
echo "Options=${ROOTFLAGS},${ovlfs},upperdir=/run/overlayfs,workdir=/run/ovlwork"
echo "Type=overlay" echo "Type=overlay"
_dev=LiveOS_rootfs _dev=LiveOS_rootfs
else else

View File

@ -137,7 +137,7 @@ do_live_overlay() {
fi fi
if [ -n "$overlayfs" ]; then if [ -n "$overlayfs" ]; then
unset -v overlayfs unset -v overlayfs
[ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit="yes" [ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit=":>/xor_overlayfs;"
fi fi
setup="yes" setup="yes"
else else
@ -148,7 +148,7 @@ do_live_overlay() {
ln -s /run/initramfs/overlayfs/ovlwork /run/ovlwork$opt ln -s /run/initramfs/overlayfs/ovlwork /run/ovlwork$opt
if [ -z "$overlayfs" ]; then if [ -z "$overlayfs" ]; then
overlayfs="yes" overlayfs="yes"
[ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit="yes" [ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit=":>/xor_overlayfs;"
fi fi
setup="yes" setup="yes"
fi fi
@ -159,7 +159,7 @@ do_live_overlay() {
ln -s /run/initramfs/overlayfs$pathspec/../ovlwork /run/ovlwork$opt ln -s /run/initramfs/overlayfs$pathspec/../ovlwork /run/ovlwork$opt
if [ -z "$overlayfs" ]; then if [ -z "$overlayfs" ]; then
overlayfs="yes" overlayfs="yes"
[ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit="yes" [ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit=":>/xor_overlayfs;"
fi fi
setup="yes" setup="yes"
fi fi
@ -168,8 +168,7 @@ do_live_overlay() {
modprobe overlay modprobe overlay
if [ $? != 0 ]; then if [ $? != 0 ]; then
m='OverlayFS is not available; using temporary Device-mapper overlay.' m='OverlayFS is not available; using temporary Device-mapper overlay.'
unset -v overlayfs setup unset -v overlayfs setup reloadsysrootmountunit
[ -n "$reloadsysrootmountunit" ] && unset -v reloadsysrootmountunit
fi fi
fi fi


@ -181,7 +180,7 @@ do_live_overlay() {
m=' Unable to find a persistent overlay; using a temporary one.' m=' Unable to find a persistent overlay; using a temporary one.'
m="$m"$'\n All root filesystem changes will be lost on shutdown.' m="$m"$'\n All root filesystem changes will be lost on shutdown.'
m="$m"$'\n Press [Enter] to continue.' m="$m"$'\n Press [Enter] to continue.'
echo -e "\n\n\n\n${m}\n\n\n" > /dev/kmsg printf "\n\n\n\n${m}\n\n\n" > /dev/kmsg
if [ -n "$DRACUT_SYSTEMD" ]; then if [ -n "$DRACUT_SYSTEMD" ]; then
if type plymouth >/dev/null 2>&1 && plymouth --ping ; then if type plymouth >/dev/null 2>&1 && plymouth --ping ; then
if getargbool 0 rhgb || getargbool 0 splash ; then if getargbool 0 rhgb || getargbool 0 splash ; then
@ -203,6 +202,11 @@ do_live_overlay() {
if [ -n "$overlayfs" ]; then if [ -n "$overlayfs" ]; then
mkdir -m 0755 /run/overlayfs mkdir -m 0755 /run/overlayfs
mkdir -m 0755 /run/ovlwork mkdir -m 0755 /run/ovlwork
if [ -n "$readonly_overlay" ] && ! [ -h /run/overlayfs-r ]; then
info "No persistent overlay found."
unset -v readonly_overlay
[ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit="${reloadsysrootmountunit}:>/xor_readonly;"
fi
else else
dd if=/dev/null of=/overlay bs=1024 count=1 seek=$((overlay_size*1024)) 2> /dev/null dd if=/dev/null of=/overlay bs=1024 count=1 seek=$((overlay_size*1024)) 2> /dev/null
if [ -n "$setup" -a -n "$readonly_overlay" ]; then if [ -n "$setup" -a -n "$readonly_overlay" ]; then
@ -256,6 +260,7 @@ do_live_overlay() {
fi fi
ln -s $BASE_LOOPDEV /dev/live-base ln -s $BASE_LOOPDEV /dev/live-base
} }
# end do_live_overlay()


# we might have a genMinInstDelta delta file for anaconda to take advantage of # we might have a genMinInstDelta delta file for anaconda to take advantage of
if [ -e /run/initramfs/live/${live_dir}/osmin.img ]; then if [ -e /run/initramfs/live/${live_dir}/osmin.img ]; then
@ -299,7 +304,7 @@ if [ -e "$SQUASHED" ]; then
FSIMG=$SQUASHED FSIMG=$SQUASHED
if [ -z "$overlayfs" ]; then if [ -z "$overlayfs" ]; then
overlayfs="yes" overlayfs="yes"
[ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit="yes" [ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit=":>/xor_overlayfs;"
fi fi
else else
die "Failed to find a root filesystem in $SQUASHED." die "Failed to find a root filesystem in $SQUASHED."
@ -366,7 +371,7 @@ if [ -b "$OSMIN_LOOPDEV" ]; then
fi fi


if [ -n "$reloadsysrootmountunit" ]; then if [ -n "$reloadsysrootmountunit" ]; then
> /xor_overlayfs eval "$reloadsysrootmountunit"
systemctl daemon-reload systemctl daemon-reload
fi fi


@ -374,21 +379,20 @@ ROOTFLAGS="$(getarg rootflags)"


if [ -n "$overlayfs" ]; then if [ -n "$overlayfs" ]; then
mkdir -m 0755 /run/rootfsbase mkdir -m 0755 /run/rootfsbase
if [ -n "$reset_overlay" ] && [ -L /run/overlayfs ]; then if [ -n "$reset_overlay" ] && [ -h /run/overlayfs ]; then
ovlfs=$(readlink /run/overlayfs) ovlfs=$(readlink /run/overlayfs)
info "Resetting the OverlayFS overlay directory." info "Resetting the OverlayFS overlay directory."
rm -r -- ${ovlfs}/* ${ovlfs}/.* >/dev/null 2>&1 rm -r -- ${ovlfs}/* ${ovlfs}/.* >/dev/null 2>&1
fi fi
if [ -n "$readonly_overlay" ]; then if [ -n "$readonly_overlay" ] && [ -h /run/overlayfs-r ]; then
mkdir -m 0755 /run/rootfsbase-r ovlfs=lowerdir=/run/overlayfs-r:/run/rootfsbase
mount -r $FSIMG /run/rootfsbase-r
mount -t overlay LiveOS_rootfs-r -oro,lowerdir=/run/overlayfs-r:/run/rootfsbase-r /run/rootfsbase
else else
mount -r $FSIMG /run/rootfsbase ovlfs=lowerdir=/run/rootfsbase
fi fi
mount -r $FSIMG /run/rootfsbase
if [ -z "$DRACUT_SYSTEMD" ]; then if [ -z "$DRACUT_SYSTEMD" ]; then
printf 'mount -t overlay LiveOS_rootfs -o%s,%s %s\n' "$ROOTFLAGS" \ printf 'mount -t overlay LiveOS_rootfs -o%s,%s %s\n' "$ROOTFLAGS" \
'lowerdir=/run/rootfsbase,upperdir=/run/overlayfs,workdir=/run/ovlwork' \ "$ovlfs",upperdir=/run/overlayfs,workdir=/run/ovlwork \
"$NEWROOT" > $hookdir/mount/01-$$-live.sh "$NEWROOT" > $hookdir/mount/01-$$-live.sh
fi fi
else else

View File

@ -43,8 +43,10 @@ GENERATOR_DIR="$2"


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


getargbool 0 rd.live.overlay.readonly -d -y readonly_overlay && readonly_overlay="--readonly" || readonly_overlay=""
getargbool 0 rd.live.overlay.overlayfs && overlayfs="yes" getargbool 0 rd.live.overlay.overlayfs && overlayfs="yes"
[ -e /xor_overlayfs ] && xor_overlayfs="yes" [ -e /xor_overlayfs ] && xor_overlayfs="yes"
[ -e /xor_readonly ] && xor_readonly="--readonly"
ROOTFLAGS="$(getarg rootflags)" ROOTFLAGS="$(getarg rootflags)"
{ {
echo "[Unit]" echo "[Unit]"
@ -53,7 +55,12 @@ ROOTFLAGS="$(getarg rootflags)"
echo "Where=/sysroot" echo "Where=/sysroot"
if [ "$overlayfs$xor_overlayfs" = "yes" ]; then if [ "$overlayfs$xor_overlayfs" = "yes" ]; then
echo "What=LiveOS_rootfs" echo "What=LiveOS_rootfs"
echo "Options=${ROOTFLAGS},lowerdir=/run/rootfsbase,upperdir=/run/overlayfs,workdir=/run/ovlwork" if [ "$readonly_overlay$xor_readonly" = "--readonly" ]; then
ovlfs=lowerdir=/run/overlayfs-r:/run/rootfsbase
else
ovlfs=lowerdir=/run/rootfsbase
fi
echo "Options=${ROOTFLAGS},${ovlfs},upperdir=/run/overlayfs,workdir=/run/ovlwork"
echo "Type=overlay" echo "Type=overlay"
_dev=LiveOS_rootfs _dev=LiveOS_rootfs
else else