Merge branch 'overlayfs' of https://github.com/FGrose/dracut into FGrose-overlayfs

master
Harald Hoyer 2017-03-30 10:53:22 +02:00
commit 1dd68c2f23
7 changed files with 213 additions and 86 deletions

View File

@ -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 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 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 blocks to the snapshot volume. Once the blocks of the snapshot overlay are
exhausted, the root filesystem becomes unusable and requires a reboot. A exhausted, the root filesystem becomes read only and may cause application
persistent overlay is marked Invalid, and requires a difficult recovery. failures. The overlay file is marked 'Overflow', and a difficult recovery is
Non-persistent overlays default to 512 MiB in RAM, but the size can be adjusted required to repair and enlarge the overlay offline. Non-persistent overlays
with the **rd.live.overlay.size=** kernel command line option. 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: The filesystem structure is expected to be:
+ +
@ -832,7 +834,7 @@ The filesystem structure is expected to be:
squashfs.img | Squashfs from LiveCD .iso downloaded via network squashfs.img | Squashfs from LiveCD .iso downloaded via network
!(mount) !(mount)
/LiveOS /LiveOS
|- ext3fs.img | Filesystem image to mount read-only |- rootfs.img | Filesystem image to mount read-only
!(mount) !(mount)
/bin | Live filesystem /bin | Live filesystem
/boot | /boot |
@ -854,7 +856,7 @@ of the root filesystem.
Uncompressed live filesystem image::: Uncompressed live filesystem image:::
When the live system was installed with the '--skipcompress' option of the When the live system was installed with the '--skipcompress' option of the
__livecd-iso-to-disk__ installation script for Live USB devices, the root __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. is involved during boot.
+ +
- If **rd.live.ram=1** is used in this situation, the full, uncompressed - If **rd.live.ram=1** is used in this situation, the full, uncompressed
@ -919,8 +921,8 @@ root=live:torrent://example.com/liveboot.img.torrent
Enables debug output from the live boot process. Enables debug output from the live boot process.


**rd.live.dir=**__<path>__:: **rd.live.dir=**__<path>__::
Specifies the directory within the squashfs where the ext3fs.img or rootfs.img Specifies the directory within the boot device where the squashfs.img or
can be found. By default, this is __LiveOS__. rootfs.img can be found. By default, this is __LiveOS__.


**rd.live.squashimg=**__<filename of SquashFS image>__:: **rd.live.squashimg=**__<filename of SquashFS image>__::
Specifies the filename for a SquashFS image of the root filesystem. Specifies the filename for a SquashFS image of the root filesystem.
@ -938,6 +940,8 @@ used to persist the changes made to the device specified by the
**root=live:__<url>__** option. **root=live:__<url>__** option.
- _none_ specifies no overlay when an uncompressed live root filesystem is - _none_ specifies no overlay when an uncompressed live root filesystem is
available. 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] [listing]
.Example .Example
@ -946,11 +950,12 @@ rd.live.overlay=/dev/sdb1:persistent-overlay.img
-- --


**rd.live.overlay.size=**__<size_MiB>__:: **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:: **rd.live.overlay.readonly=**1::
Specifies a non-persistent, writable snapshot overlay to be stacked over a Specifies a non-persistent, writable snapshot overlay to be stacked over a
read-only snapshot of the root filesystem, `/dev/mapper/live-ro`. read-only snapshot of the root filesystem, `/dev/mapper/live-ro`, or a read-
only loop device of a writable `rootfs.img`.


**rd.live.overlay.reset=**1:: **rd.live.overlay.reset=**1::
Specifies that a persistent overlay should be reset on boot. All root Specifies that a persistent overlay should be reset on boot. All root
@ -963,6 +968,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 that memory is given back to the kernel when the filesystem does not claim it
anymore. 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 Plymouth Boot Splash
~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~

View File

@ -14,7 +14,8 @@ _do_dm_shutdown() {
return $ret 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 _do_dm_shutdown $1
else else
: :

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/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..." info "Applying updates to live image..."
mount -o bind /run $NEWROOT/run mount -o bind /run $NEWROOT/run
# avoid overwriting symlinks (e.g. /lib -> /usr/lib) with directories # avoid overwriting symlinks (e.g. /lib -> /usr/lib) with directories

View File

@ -52,21 +52,30 @@ esac


GENERATOR_DIR="$2" 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.overlayfs && overlayfs="yes"
[ -e /xor_overlayfs ] && xor_overlayfs="yes"
ROOTFLAGS="$(getarg rootflags)" ROOTFLAGS="$(getarg rootflags)"
{ {
echo "[Unit]" echo "[Unit]"
echo "Before=initrd-root-fs.target" echo "Before=initrd-root-fs.target"
echo "[Mount]" echo "[Mount]"
echo "Where=/sysroot" echo "Where=/sysroot"
echo "What=/dev/mapper/live-rw" if [ "$overlayfs$xor_overlayfs" = "yes" ]; then
[ -n "$ROOTFLAGS" ] && echo "Options=${ROOTFLAGS}" 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 } > "$GENERATOR_DIR"/sysroot.mount


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

View File

@ -28,9 +28,10 @@ getargbool 0 rd.live.overlay.readonly -d -y readonly_overlay && readonly_overlay
overlay=$(getarg rd.live.overlay -d overlay) overlay=$(getarg rd.live.overlay -d overlay)
getargbool 0 rd.writable.fsimg -d -y writable_fsimg && writable_fsimg="yes" getargbool 0 rd.writable.fsimg -d -y writable_fsimg && writable_fsimg="yes"
overlay_size=$(getarg rd.live.overlay.size=) overlay_size=$(getarg rd.live.overlay.size=)
[ -z "$overlay_size" ] && overlay_size=512 [ -z "$overlay_size" ] && overlay_size=32768


getargbool 0 rd.live.overlay.thin && thin_snapshot="yes" getargbool 0 rd.live.overlay.thin && thin_snapshot="yes"
getargbool 0 rd.live.overlay.overlayfs && overlayfs="yes"


# CD/DVD media check # CD/DVD media check
[ -b $livedev ] && fs=$(blkid -s TYPE -o value $livedev) [ -b $livedev ] && fs=$(blkid -s TYPE -o value $livedev)
@ -89,7 +90,6 @@ do_live_overlay() {
# create a sparse file for the overlay # create a sparse file for the overlay
# overlay: if non-ram overlay searching is desired, do it, # overlay: if non-ram overlay searching is desired, do it,
# otherwise, create traditional overlay in ram # otherwise, create traditional overlay in ram
OVERLAY_LOOPDEV=$( losetup -f )


l=$(blkid -s LABEL -o value $livedev) || l="" l=$(blkid -s LABEL -o value $livedev) || l=""
u=$(blkid -s UUID -o value $livedev) || u="" u=$(blkid -s UUID -o value $livedev) || u=""
@ -107,51 +107,117 @@ do_live_overlay() {
devspec=$( echo $overlay | sed -e 's/:.*$//' ) devspec=$( echo $overlay | sed -e 's/:.*$//' )


# need to know where to look for the overlay # need to know where to look for the overlay
setup="" if [ -z "$setup" -a -n "$devspec" -a -n "$pathspec" -a -n "$overlay" ]; then
if [ -n "$devspec" -a -n "$pathspec" -a -n "$overlay" ]; then
mkdir -m 0755 /run/initramfs/overlayfs mkdir -m 0755 /run/initramfs/overlayfs
opt=''
[ -n "$readonly_overlay" ] && opt=-r
mount -n -t auto $devspec /run/initramfs/overlayfs || : mount -n -t auto $devspec /run/initramfs/overlayfs || :
if [ -f /run/initramfs/overlayfs$pathspec -a -w /run/initramfs/overlayfs$pathspec ]; then if [ -f /run/initramfs/overlayfs$pathspec -a -w /run/initramfs/overlayfs$pathspec ]; then
losetup $OVERLAY_LOOPDEV /run/initramfs/overlayfs$pathspec OVERLAY_LOOPDEV=$(losetup -f --show $opt /run/initramfs/overlayfs$pathspec)
if [ -n "$reset_overlay" ]; then over=$OVERLAY_LOOPDEV
dd if=/dev/zero of=$OVERLAY_LOOPDEV bs=64k count=1 conv=fsync 2>/dev/null umount -l /run/initramfs/overlayfs || :
oltype=$(det_img_fs $OVERLAY_LOOPDEV)
if [ -z "$oltype" ] || [ "$oltype" = DM_snapshot_cow ]; then
if [ -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
if [ -n "$overlayfs" ]; then
unset -v overlayfs
[ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit="yes"
fi
setup="yes"
else
mount -n -t $oltype $opt $OVERLAY_LOOPDEV /run/initramfs/overlayfs
if [ -d /run/initramfs/overlayfs/overlayfs ] &&
[ -d /run/initramfs/overlayfs/ovlwork ]; then
ln -s /run/initramfs/overlayfs/overlayfs /run/overlayfs$opt
ln -s /run/initramfs/overlayfs/ovlwork /run/ovlwork$opt
if [ -z "$overlayfs" ]; then
overlayfs="yes"
[ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit="yes"
fi
setup="yes"
fi
fi
elif [ -d /run/initramfs/overlayfs$pathspec ] &&
[ -d /run/initramfs/overlayfs$pathspec/../ovlwork ]; then
ln -s /run/initramfs/overlayfs$pathspec /run/overlayfs$opt
ln -s /run/initramfs/overlayfs$pathspec/../ovlwork /run/ovlwork$opt
if [ -z "$overlayfs" ]; then
overlayfs="yes"
[ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit="yes"
fi fi
setup="yes" setup="yes"
fi fi
umount -l /run/initramfs/overlayfs || : fi
if [ -n "$overlayfs" ]; then
modprobe overlay
if [ $? != 0 ]; then
m='OverlayFS is not available; using temporary Device-mapper overlay.'
unset -v overlayfs setup
[ -n "$reloadsysrootmountunit" ] && unset -v reloadsysrootmountunit
fi
fi fi


if [ -z "$setup" -o -n "$readonly_overlay" ]; then if [ -z "$setup" -o -n "$readonly_overlay" ]; then
if [ -n "$setup" ]; then if [ -n "$setup" ]; then
warn "Using temporary overlay." warn "Using temporary overlay."
elif [ -n "$devspec" -a -n "$pathspec" ]; then elif [ -n "$devspec" -a -n "$pathspec" ]; then
warn "Unable to find persistent overlay; using temporary" [ -z "$m" ] &&
sleep 5 m=' Unable to find a persistent overlay; using a temporary one.'
m=($'\n' "$m" $'\n'
' All root filesystem changes will be lost on shutdown.'
$'\n' ' Press any key to continue')
echo -e "\n\n\n${m[*]}\n\n\n" > /dev/kmsg
if [ -n "$DRACUT_SYSTEMD" ]; then
if plymouth --ping ; then
if getargbool 0 rhgb || getargbool 0 splash ; then
m[0]='>>>'$'\n''>>>'$'\n''>>>'$'\n\n'
m[5]=$'\n''<<<'$'\n''<<<'$'\n''<<<'
plymouth display-message --text="${m[*]}"
else
plymouth ask-question --prompt="${m[*]}" --command=true
fi
else
m[0]='>>>'
m[5]='<<<'
unset -v m[2] m[4]
systemd-ask-password --timeout=0 "${m[*]}"
fi
else
plymouth --ping && plymouth --quit
read -s -r -p $'\n\n'"${m[*]}:" -n 1 reply
fi
fi fi

if [ -n "$overlayfs" ]; then
dd if=/dev/null of=/overlay bs=1024 count=1 seek=$((overlay_size*1024)) 2> /dev/null mkdir -m 0755 /run/overlayfs
if [ -n "$setup" -a -n "$readonly_overlay" ]; then mkdir -m 0755 /run/ovlwork
RO_OVERLAY_LOOPDEV=$( losetup -f )
losetup $RO_OVERLAY_LOOPDEV /overlay
else else
losetup $OVERLAY_LOOPDEV /overlay 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
RO_OVERLAY_LOOPDEV=$(losetup -f --show /overlay)
over=$RO_OVERLAY_LOOPDEV
else
OVERLAY_LOOPDEV=$(losetup -f --show /overlay)
over=$OVERLAY_LOOPDEV
fi
fi fi
fi fi


# set up the snapshot # set up the snapshot
sz=$(blockdev --getsz $BASE_LOOPDEV) if [ -z "$overlayfs" ]; then
if [ -n "$readonly_overlay" ]; then if [ -n "$readonly_overlay" ] && [ -n "$OVERLAY_LOOPDEV" ]; then
echo 0 $sz snapshot $BASE_LOOPDEV $OVERLAY_LOOPDEV N 8 | dmsetup create --readonly live-ro echo 0 $sz snapshot $BASE_LOOPDEV $OVERLAY_LOOPDEV P 8 | dmsetup create --readonly live-ro
base="/dev/mapper/live-ro" base="/dev/mapper/live-ro"
over=$RO_OVERLAY_LOOPDEV else
else base=$BASE_LOOPDEV
base=$BASE_LOOPDEV fi
over=$OVERLAY_LOOPDEV
fi fi


if [ -n "$thin_snapshot" ]; then if [ -n "$thin_snapshot" ]; then
modprobe dm_thin_pool modprobe dm_thin_pool
mkdir /run/initramfs/thin-overlay mkdir -m 0755 /run/initramfs/thin-overlay


# In block units (512b) # In block units (512b)
thin_data_sz=$(( $overlay_size * 1024 * 1024 / 512 )) thin_data_sz=$(( $overlay_size * 1024 * 1024 / 512 ))
@ -170,7 +236,7 @@ do_live_overlay() {


# Create a snapshot of the base image # Create a snapshot of the base image
echo 0 $sz thin /dev/mapper/live-overlay-pool 0 $base | dmsetup create live-rw echo 0 $sz thin /dev/mapper/live-overlay-pool 0 $base | dmsetup create live-rw
else elif [ -z "$overlayfs" ]; then
echo 0 $sz snapshot $base $over PO 8 | dmsetup create live-rw echo 0 $sz snapshot $base $over PO 8 | dmsetup create live-rw
fi fi


@ -178,17 +244,9 @@ do_live_overlay() {
echo 0 $sz linear $BASE_LOOPDEV 0 | dmsetup create --readonly live-base echo 0 $sz linear $BASE_LOOPDEV 0 | dmsetup create --readonly live-base
} }


# live cd helper function
do_live_from_base_loop() {
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
OSMINSQFS=/run/initramfs/live/${live_dir}/osmin.img OSMINSQFS=/run/initramfs/live/${live_dir}/osmin.img
fi

if [ -n "$OSMINSQFS" ]; then
# decompress the delta data # decompress the delta data
dd if=$OSMINSQFS of=/run/initramfs/osmin.img 2> /dev/null dd if=$OSMINSQFS of=/run/initramfs/osmin.img 2> /dev/null
OSMIN_SQUASHED_LOOPDEV=$( losetup -f ) OSMIN_SQUASHED_LOOPDEV=$( losetup -f )
@ -204,13 +262,12 @@ fi
if [ -e /run/initramfs/live/${live_dir}/${squash_image} ]; then if [ -e /run/initramfs/live/${live_dir}/${squash_image} ]; then
SQUASHED="/run/initramfs/live/${live_dir}/${squash_image}" SQUASHED="/run/initramfs/live/${live_dir}/${squash_image}"
fi fi

if [ -e "$SQUASHED" ]; then
if [ -e "$SQUASHED" ] ; then
if [ -n "$live_ram" ]; then if [ -n "$live_ram" ]; then
echo "Copying live image to RAM..." echo 'Copying live image to RAM...' > /dev/kmsg
echo "(this may take a few minutes)" echo ' (this may take a minute)' > /dev/kmsg
dd if=$SQUASHED of=/run/initramfs/squashed.img bs=512 2> /dev/null dd if=$SQUASHED of=/run/initramfs/squashed.img bs=512 2> /dev/null
echo "Done copying live image to RAM." echo 'Done copying live image to RAM.' > /dev/kmsg
SQUASHED="/run/initramfs/squashed.img" SQUASHED="/run/initramfs/squashed.img"
fi fi


@ -219,34 +276,32 @@ if [ -e "$SQUASHED" ] ; then
mkdir -m 0755 -p /run/initramfs/squashfs mkdir -m 0755 -p /run/initramfs/squashfs
mount -n -t squashfs -o ro $SQUASHED_LOOPDEV /run/initramfs/squashfs mount -n -t squashfs -o ro $SQUASHED_LOOPDEV /run/initramfs/squashfs


if [ -f /run/initramfs/squashfs/LiveOS/ext3fs.img ]; then if [ -f /run/initramfs/squashfs/LiveOS/rootfs.img ]; then
FSIMG="/run/initramfs/squashfs/LiveOS/ext3fs.img"
elif [ -f /run/initramfs/squashfs/LiveOS/rootfs.img ]; then
FSIMG="/run/initramfs/squashfs/LiveOS/rootfs.img" FSIMG="/run/initramfs/squashfs/LiveOS/rootfs.img"
elif [ -f /run/initramfs/squashfs/LiveOS/ext3fs.img ]; then
FSIMG="/run/initramfs/squashfs/LiveOS/ext3fs.img"
fi fi
else else
# we might have an embedded fs image to use as rootfs (uncompressed live) # we might have an embedded fs image to use as rootfs (uncompressed live)
if [ -e /run/initramfs/live/${live_dir}/ext3fs.img ]; then if [ -e /run/initramfs/live/${live_dir}/rootfs.img ]; then
FSIMG="/run/initramfs/live/${live_dir}/ext3fs.img"
elif [ -e /run/initramfs/live/${live_dir}/rootfs.img ]; then
FSIMG="/run/initramfs/live/${live_dir}/rootfs.img" 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 fi
if [ -n "$live_ram" ]; then if [ -n "$live_ram" ]; then
echo 'Copying live image to RAM...' echo 'Copying live image to RAM...' > /dev/kmsg
echo '(this may take a few minutes)' echo ' (this may take a minute or so)' > /dev/kmsg
dd if=$FSIMG of=/run/initramfs/rootfs.img bs=512 2> /dev/null dd if=$FSIMG of=/run/initramfs/rootfs.img bs=512 2> /dev/null
echo 'Done copying live image to RAM.' echo 'Done copying live image to RAM.' > /dev/kmsg
FSIMG='/run/initramfs/rootfs.img' FSIMG='/run/initramfs/rootfs.img'
fi fi
fi fi


if [ -n "$FSIMG" ] ; then if [ -n "$FSIMG" ] ; then
BASE_LOOPDEV=$( losetup -f )

if [ -n "$writable_fsimg" ] ; then if [ -n "$writable_fsimg" ] ; then
# mount the provided filesystem read/write # mount the provided filesystem read/write
echo "Unpacking live filesystem (may take some time)" echo "Unpacking live filesystem (may take some time)" > /dev/kmsg
mkdir /run/initramfs/fsimg/ mkdir -m 0755 /run/initramfs/fsimg/
if [ -n "$SQUASHED" ]; then if [ -n "$SQUASHED" ]; then
cp -v $FSIMG /run/initramfs/fsimg/rootfs.img cp -v $FSIMG /run/initramfs/fsimg/rootfs.img
else else
@ -254,35 +309,70 @@ if [ -n "$FSIMG" ] ; then
fi fi
FSIMG=/run/initramfs/fsimg/rootfs.img FSIMG=/run/initramfs/fsimg/rootfs.img
fi fi
if [ -n "$writable_fsimg" ] || [ -z "$SQUASHED" -a -n "$live_ram" ] || opt=-r
# For writable DM images...
if [ -z "$SQUASHED" -a -n "$live_ram" -a -z "$overlayfs" ] ||
[ -n "$writable_fsimg" ] ||
[ "$overlay" = none -o "$overlay" = None -o "$overlay" = NONE ]; then [ "$overlay" = none -o "$overlay" = None -o "$overlay" = NONE ]; then
losetup $BASE_LOOPDEV $FSIMG if [ -z "$readonly_overlay" ]; then
sz=$(blockdev --getsz $BASE_LOOPDEV) opt=''
setup=rw
else
setup=yes
fi
fi
BASE_LOOPDEV=$(losetup -f --show $opt $FSIMG)
sz=$(blockdev --getsz $BASE_LOOPDEV)
if [ "$setup" == rw ]; then
echo 0 $sz linear $BASE_LOOPDEV 0 | dmsetup create live-rw echo 0 $sz linear $BASE_LOOPDEV 0 | dmsetup create live-rw
else else
# mount the filesystem read-only and add a dm snapshot for writes # Add a DM snapshot or OverlayFS for writes.
losetup -r $BASE_LOOPDEV $FSIMG do_live_overlay
do_live_from_base_loop
fi fi
fi fi


[ -e "$SQUASHED" ] && umount -l /run/initramfs/squashfs [ -e "$SQUASHED" ] && [ -z "$overlayfs" ] && umount -l /run/initramfs/squashfs


if [ -b "$OSMIN_LOOPDEV" ]; then if [ -b "$OSMIN_LOOPDEV" ]; then
# set up the devicemapper snapshot device, which will merge # set up the devicemapper snapshot device, which will merge
# the normal live fs image, and the delta, into a minimzied fs image # the normal live fs image, and the delta, into a minimzied fs image
echo "0 $( blockdev --getsz $BASE_LOOPDEV ) snapshot $BASE_LOOPDEV $OSMIN_LOOPDEV N 8" | dmsetup create --readonly live-osimg-min echo "0 $sz snapshot $BASE_LOOPDEV $OSMIN_LOOPDEV P 8" | dmsetup create --readonly live-osimg-min
fi

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


ROOTFLAGS="$(getarg rootflags)" ROOTFLAGS="$(getarg rootflags)"
if [ -n "$ROOTFLAGS" ]; then
ROOTFLAGS="-o $ROOTFLAGS"
fi


ln -s /dev/mapper/live-rw /dev/root if [ -n "$overlayfs" ]; then

mkdir -m 0755 /run/rootfsbase
if [ -z "$DRACUT_SYSTEMD" ]; then if [ -n "$reset_overlay" ] && [ -L /run/overlayfs ]; then
printf 'mount %s /dev/mapper/live-rw %s\n' "$ROOTFLAGS" "$NEWROOT" > $hookdir/mount/01-$$-live.sh ovlfs=$(readlink /run/overlayfs)
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
mount -r $FSIMG /run/rootfsbase-r
mount -t overlay LiveOS_rootfs-r -oro,lowerdir=/run/overlayfs-r:/run/rootfsbase-r /run/rootfsbase
else
mount -r $FSIMG /run/rootfsbase
fi
if [ -z "$DRACUT_SYSTEMD" ]; then
#FIXME What to link to /dev/root? Is it even needed?
printf 'mount -t overlay LiveOS_rootfs -o%s,%s %s\n' "$ROOTFLAGS" \
'lowerdir=/run/rootfsbase,upperdir=/run/overlayfs,workdir=/run/ovlwork' \
"$NEWROOT" > $hookdir/mount/01-$$-live.sh
fi
else
ln -s /dev/mapper/live-rw /dev/root
if [ -z "$DRACUT_SYSTEMD" ]; then
[ -n "$ROOTFLAGS" ] && ROOTFLAGS="-o $ROOTFLAGS"
printf 'mount %s /dev/mapper/live-rw %s\n' "$ROOTFLAGS" "$NEWROOT" > $hookdir/mount/01-$$-live.sh
fi
ln -s $BASE_LOOPDEV /run/rootfsbase
fi fi


need_shutdown need_shutdown

View File

@ -17,7 +17,7 @@ depends() {


# called by dracut # called by dracut
installkernel() { installkernel() {
instmods squashfs loop iso9660 instmods squashfs loop iso9660 overlay
} }


# called by dracut # called by dracut

View File

@ -57,6 +57,6 @@ info "root was $liveroot, is now $root"
# make sure that init doesn't complain # make sure that init doesn't complain
[ -z "$root" ] && root="live" [ -z "$root" ] && root="live"


wait_for_dev -n /dev/mapper/live-rw wait_for_dev -n /run/rootfsbase


return 0 return 0