dmsquash-live-root: Extend rd.live.overlay.readonly support
Support the rd.live.overlay.readonly option for writable images, such as rd.live.overlay=none and rd.writable.fsimg.master
parent
f1b65e92af
commit
3c6337f68e
|
|
@ -954,7 +954,8 @@ 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
|
||||||
|
|
|
||||||
|
|
@ -90,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=""
|
||||||
|
|
@ -108,14 +107,14 @@ 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=''
|
opt=''
|
||||||
[ -n "$readonly_overlay" ] && opt=-r
|
[ -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 $opt $OVERLAY_LOOPDEV /run/initramfs/overlayfs$pathspec
|
OVERLAY_LOOPDEV=$(losetup -f --show $opt /run/initramfs/overlayfs$pathspec)
|
||||||
|
over=$OVERLAY_LOOPDEV
|
||||||
umount -l /run/initramfs/overlayfs || :
|
umount -l /run/initramfs/overlayfs || :
|
||||||
oltype=$(det_img_fs $OVERLAY_LOOPDEV)
|
oltype=$(det_img_fs $OVERLAY_LOOPDEV)
|
||||||
if [ -z "$oltype" ] || [ "$oltype" = DM_snapshot_cow ]; then
|
if [ -z "$oltype" ] || [ "$oltype" = DM_snapshot_cow ]; then
|
||||||
|
|
@ -197,24 +196,22 @@ do_live_overlay() {
|
||||||
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
|
||||||
RO_OVERLAY_LOOPDEV=$( losetup -f )
|
RO_OVERLAY_LOOPDEV=$(losetup -f --show /overlay)
|
||||||
losetup $RO_OVERLAY_LOOPDEV /overlay
|
over=$RO_OVERLAY_LOOPDEV
|
||||||
else
|
else
|
||||||
losetup $OVERLAY_LOOPDEV /overlay
|
OVERLAY_LOOPDEV=$(losetup -f --show /overlay)
|
||||||
|
over=$OVERLAY_LOOPDEV
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# set up the snapshot
|
# set up the snapshot
|
||||||
sz=$(blockdev --getsz $BASE_LOOPDEV)
|
|
||||||
if [ -z "$overlayfs" ]; then
|
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 P 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
|
||||||
over=$OVERLAY_LOOPDEV
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -301,8 +298,6 @@ else
|
||||||
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)" > /dev/kmsg
|
echo "Unpacking live filesystem (may take some time)" > /dev/kmsg
|
||||||
|
|
@ -314,14 +309,24 @@ 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" -a -z "$overlayfs" ] ||
|
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
|
||||||
# Attach the filesystem read-only and add a DM snapshot or OverlayFS for writes.
|
# Add a DM snapshot or OverlayFS for writes.
|
||||||
losetup -r $BASE_LOOPDEV $FSIMG
|
|
||||||
do_live_overlay
|
do_live_overlay
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue