Merge ~danielruthardt/cloud-initramfs-tools:feature/multiple-overlayroot-devices into cloud-initramfs-tools:master

Proposed by Daniel Ruthardt
Status: Needs review
Proposed branch: ~danielruthardt/cloud-initramfs-tools:feature/multiple-overlayroot-devices
Merge into: cloud-initramfs-tools:master
Diff against target: 223 lines (+82/-41)
2 files modified
overlayroot/etc/overlayroot.conf (+6/-4)
overlayroot/scripts/init-bottom/overlayroot (+76/-37)
Reviewer Review Type Date Requested Status
Ubuntu Sponsors Pending
cloud-initramfs-tools Pending
Review via email: mp+460349@code.launchpad.net

Commit message

✨ Add support for multiple overlay devices

Description of the change

✨ Add support for multiple overlay devices
Support is being added for multiple overlay "devices". More complex scenarios like mixing and matching various devices with, e.g. "tmpfs" or multiple crypt devices, are not supported.

A package used for testing purposes can be found here:
https://github.com/LF-Certification/cloud-initramfs-tools/releases/tag/v0.49-rc5

To post a comment you must log in.
86fb5ef... by Daniel Ruthardt

✏️ Fix typo

Signed-off-by: Daniel Ruthardt <email address hidden>

855b388... by Daniel Ruthardt

🐛 Replace tac (might not be available) with sed

tac is available in the initial ramdisk when built on Debian, but isn't
when build on Ubuntu (22.04). sed is available and the replacement
commmand, although not as readable, works as nicely as tac.

Signed-off-by: Daniel Ruthardt <email address hidden>

24d70ca... by Daniel Ruthardt

Revert "🚸 Improve ro detection for when both are present"

The slight improvement did not always work reliably. A good
improvement/fix is bigger than initially thought and will thus be
separated from this PR.

This reverts commit e39a0027165569dbfd19b8a2eb10f35b415c9f6b.

Revision history for this message
Daniel Ruthardt (danielruthardt) wrote :

I have removed the following part of the PR and will submit a more complete, but thus also slightly more complex, separate PR.

🚸 Improve ro detection for when both are present
Improve root file system "ro" detection for when both "ro" and "rw" are present in the kernel command line.
The above is helpful for situations when one only controls an append to the kernel command line and is not in complete control of the entire command line to be able to remove the "ro".

Revision history for this message
Daniel Ruthardt (danielruthardt) wrote :

The separate PR for the improved/fixed ro detection can now be found here: https://code.launchpad.net/~danielruthardt/cloud-initramfs-tools/+git/cloud-initramfs-tools/+merge/460784

Unmerged commits

24d70ca... by Daniel Ruthardt

Revert "🚸 Improve ro detection for when both are present"

The slight improvement did not always work reliably. A good
improvement/fix is bigger than initially thought and will thus be
separated from this PR.

This reverts commit e39a0027165569dbfd19b8a2eb10f35b415c9f6b.

855b388... by Daniel Ruthardt

🐛 Replace tac (might not be available) with sed

tac is available in the initial ramdisk when built on Debian, but isn't
when build on Ubuntu (22.04). sed is available and the replacement
commmand, although not as readable, works as nicely as tac.

Signed-off-by: Daniel Ruthardt <email address hidden>

86fb5ef... by Daniel Ruthardt

✏️ Fix typo

Signed-off-by: Daniel Ruthardt <email address hidden>

e39a002... by Daniel Ruthardt

🚸 Improve ro detection for when both are present

Signed-off-by: Daniel Ruthardt <email address hidden>

e88abb2... by Daniel Ruthardt

✨ Add support for multiple overlay devices

Signed-off-by: Daniel Ruthardt <email address hidden>

ff7e21a... by Daniel Ruthardt

✏️ Fix typo

Signed-off-by: Daniel Ruthardt <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/overlayroot/etc/overlayroot.conf b/overlayroot/etc/overlayroot.conf
index 3d4e167..f978f35 100644
--- a/overlayroot/etc/overlayroot.conf
+++ b/overlayroot/etc/overlayroot.conf
@@ -17,13 +17,13 @@
17# overlayroot=tmpfs17# overlayroot=tmpfs
18# overlayroot=tmpfs:swap=118# overlayroot=tmpfs:swap=1
19#19#
20# * overlayroot=DEVICE or overlayroot=device:PARAMETERS20# * overlayroot=DEVICE[:DEVICE] or overlayroot=device:PARAMETERS
21# mount DEVICE as overlayfs and write changes there21# mount DEVICE(s) as overlayfs and write changes to the first
22# device must already have kernel mountalbe filesystem on it.22# device(s) must already have kernel mountalbe filesystem on them.
23#23#
24# available parameters are:24# available parameters are:
25# * dev: default: "" [REQUIRED]25# * dev: default: "" [REQUIRED]
26# use given device for backing filesystem.26# use given device(s) for backing filesystems.
27# Note, 'overlayroot=/dev/vdb' is translated to27# Note, 'overlayroot=/dev/vdb' is translated to
28# 'overlayrooot=device:dev=/dev/vdb'28# 'overlayrooot=device:dev=/dev/vdb'
29# * timeout: default: 029# * timeout: default: 0
@@ -34,7 +34,9 @@
34# examples:34# examples:
35# overlayroot=/dev/xvdb35# overlayroot=/dev/xvdb
36# overlayroot=/dev/vdb36# overlayroot=/dev/vdb
37# overlayroot=/dev/vdc:/dev/vdb
37# overlayroot=device:dev=/dev/sdb,timeout=18038# overlayroot=device:dev=/dev/sdb,timeout=180
39# overlayroot=device:dev=/dev/sdc:/dev/sdb,timeout=180
38# overlayroot=device:dev=LABEL=my-flashdrive,timeout=18040# overlayroot=device:dev=LABEL=my-flashdrive,timeout=180
39#41#
40# * overlayroot=crypt:PARAMETERS42# * overlayroot=crypt:PARAMETERS
diff --git a/overlayroot/scripts/init-bottom/overlayroot b/overlayroot/scripts/init-bottom/overlayroot
index 5c13811..48892cd 100755
--- a/overlayroot/scripts/init-bottom/overlayroot
+++ b/overlayroot/scripts/init-bottom/overlayroot
@@ -2,6 +2,7 @@
2# Copyright, 2012 Dustin Kirkland <kirkland@ubuntu.com>2# Copyright, 2012 Dustin Kirkland <kirkland@ubuntu.com>
3# Copyright, 2012 Scott Moser <smoser@ubuntu.com>3# Copyright, 2012 Scott Moser <smoser@ubuntu.com>
4# Copyright, 2012 Axel Heider4# Copyright, 2012 Axel Heider
5# Copyright, 2024 Daniel Ruthardt <druthardt@linuxfoundation.org>
5#6#
6# Based on scripts from7# Based on scripts from
7# Sebastian P.8# Sebastian P.
@@ -335,7 +336,7 @@ overlayrootify_fstab() {
335 local hash="#" oline="" ospec="" upper="" dirs="" copy_opts="" copy_opt=""336 local hash="#" oline="" ospec="" upper="" dirs="" copy_opts="" copy_opt=""
336 local spec file vfstype opts pass freq line ro_line337 local spec file vfstype opts pass freq line ro_line
337 local workdir="" use_orig="" relfile="" needs_workdir=false noauto=""338 local workdir="" use_orig="" relfile="" needs_workdir=false noauto=""
338 339
339 [ -f "$input" ] || return 1340 [ -f "$input" ] || return 1
340341
341 cat <<EOF342 cat <<EOF
@@ -671,17 +672,29 @@ case "${overlayroot:-disabled}" in
671 /dev/*) opts="dev=${overlayroot}";;672 /dev/*) opts="dev=${overlayroot}";;
672 *) opts="${overlayroot#device:}";;673 *) opts="${overlayroot#device:}";;
673 esac674 esac
674 dev_setup "${opts}" ||675
675 fail "failed setup overlay for ${overlayroot} [$opts]${cfgmsg}"676 devices="$(echo "$opts" | grep -Eo 'dev=([^,]*)' | cut -d= -f2 | tr ":" "\n" | sed '1!G;h;$!d')"
677
678 for device in $devices; do
679 dopts=$(echo "$opts" | sed "s,dev=[^,]*,dev=${device},")
680
681 dev_setup "$dopts" ||
682 fail "failed setup overlay for ${overlayroot} [${dopts}]${cfgmsg}"
683 done
676 mode="device"684 mode="device"
677 device="$_RET_DEVICE"685
686 mountpoints=""
687 i=1; for device in $(echo "$devices" | sed '$d'); do
688 mountpoints="${mountpoints:+${mountpoints}
689}/media/root-ro-${i}"
690 i=$((i+1)); done
678 ;;691 ;;
679 crypt:*)692 crypt:*)
680 mode="crypt"693 mode="crypt"
681 opts=${overlayroot#crypt:}694 opts=${overlayroot#crypt:}
682 crypto_setup "${opts}" ||695 crypto_setup "${opts}" ||
683 fail "failed setup crypt for ${overlayroot}${cfgmsg}"696 fail "failed setup crypt for ${overlayroot}${cfgmsg}"
684 device="$_RET_DEVICE"697 devices="$_RET_DEVICE"
685 ;;698 ;;
686 disabled)699 disabled)
687 debug "overlayroot disabled${cfgmsg}"700 debug "overlayroot disabled${cfgmsg}"
@@ -713,39 +726,13 @@ else
713fi726fi
714727
715debug "swap=$swap recurse=$recurse debug=$OVERLAYROOT_DEBUG dir=$dir_prefix"728debug "swap=$swap recurse=$recurse debug=$OVERLAYROOT_DEBUG dir=$dir_prefix"
716debug "device=$device mode=$mode driver=${overlayroot_driver}"729debug "devices=$(echo -n "$devices" | tr "\n" ",") mode=$mode driver=${overlayroot_driver}"
717730
718[ "$swap" = "0" -o "$swap" = "1" ] ||731[ "$swap" = "0" -o "$swap" = "1" ] ||
719 fail "invalid setting for swap: $swap. must be '0' or '1'"732 fail "invalid setting for swap: $swap. must be '0' or '1'"
720[ "$recurse" = "0" -o "$recurse" = "1" ] ||733[ "$recurse" = "0" -o "$recurse" = "1" ] ||
721 fail "invalid setting for recurse: $recurse. must be '0' or '1'"734 fail "invalid setting for recurse: $recurse. must be '0' or '1'"
722735
723log_warn "configuring overlayroot with driver=${overlayroot_driver} mode=$mode opts='$opts' per $used_desc"
724
725# settings based on overlayroot_driver
726workdir=""
727case "${overlayroot_driver}" in
728 overlayfs|overlay)
729 mount_type="${overlayroot_driver}"
730 mount_opts="-o lowerdir=${root_ro},upperdir=${root_rw}/${dir_prefix}"
731 if needs_workdir; then
732 get_workdir "$root_rw" "$dir_prefix" "/"
733 workdir="$_RET"
734 mount_opts="${mount_opts},workdir=$workdir"
735 fi
736 clean_path "${mount_opts} overlayroot ${ROOTMNT}"
737 mount_opts="$_RET"
738 ;;
739 aufs)
740 mount_type="aufs"
741 mount_opts="-o dirs=${root_rw}/${dir_prefix}:${root_ro}=ro aufs-root ${ROOTMNT}"
742 ;;
743 *)
744 log_fail "invalid overlayroot driver: ${overlayroot_driver}"
745 panic "$MYTAG"
746 ;;
747esac
748
749# make the mount point on the init root fs ${root_rw}736# make the mount point on the init root fs ${root_rw}
750mkdir -p "${root_rw}" ||737mkdir -p "${root_rw}" ||
751 fail "failed to create ${root_rw}"738 fail "failed to create ${root_rw}"
@@ -753,6 +740,10 @@ mkdir -p "${root_rw}" ||
753# make the mount point on the init root fs ${root_ro}740# make the mount point on the init root fs ${root_ro}
754mkdir -p "${root_ro}" ||741mkdir -p "${root_ro}" ||
755 fail "failed to create ${root_ro}"742 fail "failed to create ${root_ro}"
743for mountpoint in $mountpoints; do
744 mkdir -p "$mountpoint" ||
745 fail "failed to create ${mountpoint}"
746done
756747
757# mount the backing device to $root_rw748# mount the backing device to $root_rw
758if [ "$mode" = "tmpfs" ]; then749if [ "$mode" = "tmpfs" ]; then
@@ -761,15 +752,20 @@ if [ "$mode" = "tmpfs" ]; then
761 fail "failed to create tmpfs"752 fail "failed to create tmpfs"
762else753else
763 # dev or crypto754 # dev or crypto
764 mount "$device" "${root_rw}" ||755 device=$(echo "$devices" | tail -n1)
765 fail "failed mount backing device $device"756 mount "$device" "$root_rw" ||
757 fail "failed mount backing device ${device}"
766fi758fi
767759
768mkdir -p "${root_rw}/${dir_prefix}" ||760mkdir -p "${root_rw}/${dir_prefix}" ||
769 fail "failed to create ${dir_prefix} on ${device}"761 fail "failed to create ${dir_prefix} on ${device}"
770762
771[ -z "$workdir" ] || mkdir -p "$workdir" ||763i=1; for device in $(echo "$devices" | head -n -1); do
772 fail "failed to create workdir '$workdir' on ${device}"764 mountpoint=$(echo "$mountpoints" | head -n$i | tail -n1)
765 # mount the backing device
766 mount "$device" "$mountpoint" ||
767 fail "failed mount backing device ${device}"
768i=$((i+1)); done
773769
774# root is mounted on ${ROOTMNT}, move it to ${ROOT_RO}.770# root is mounted on ${ROOTMNT}, move it to ${ROOT_RO}.
775mount --move "${ROOTMNT}" "${root_ro}" ||771mount --move "${ROOTMNT}" "${root_ro}" ||
@@ -780,7 +776,45 @@ mount --move "${ROOTMNT}" "${root_ro}" ||
780# "panic". Otherwise the boot process is very likely to fail with even more776# "panic". Otherwise the boot process is very likely to fail with even more
781# errors and leave the system in a wired state.777# errors and leave the system in a wired state.
782778
783# mount virtual fs ${ROOTMNT} with rw-fs ${root_rw} on top or ro-fs ${root_ro}.779log_warn "configuring overlayroot with driver=${overlayroot_driver} mode=$mode opts='$opts' per $used_desc"
780
781# settings based on overlayroot_driver
782workdir=""
783case "${overlayroot_driver}" in
784 overlayfs|overlay)
785 mount_type="${overlayroot_driver}"
786 lowerdirs="$root_ro"
787 for mountpoint in $mountpoints; do
788 if [ -d "${mountpoint}${dir_prefix}" ]; then
789 lowerdir="${mountpoint}${dir_prefix}"
790 else
791 lowerdir="$mountpoint"
792 fi
793 lowerdirs="${lowerdir}:${lowerdirs}"
794 done
795 mount_opts="-o lowerdir=${lowerdirs},upperdir=${root_rw}/${dir_prefix}"
796 if needs_workdir; then
797 get_workdir "$root_rw" "$dir_prefix" "/"
798 workdir="$_RET"
799 mount_opts="${mount_opts},workdir=$workdir"
800
801 [ -z "$workdir" ] || mkdir -p "$workdir" ||
802 fail "failed to create workdir '${workdir}' on ${device}"
803 fi
804 clean_path "${mount_opts} overlayroot ${ROOTMNT}"
805 mount_opts="$_RET"
806 ;;
807 aufs)
808 mount_type="aufs"
809 mount_opts="-o dirs=${root_rw}/${dir_prefix}:${root_ro}=ro aufs-root ${ROOTMNT}"
810 ;;
811 *)
812 log_fail "invalid overlayroot driver: ${overlayroot_driver}"
813 panic "$MYTAG"
814 ;;
815esac
816
817# mount virtual fs ${ROOTMNT} with rw-fs ${root_rw} on top of ro-fs ${root_ro}.
784debug mount -t "$mount_type" $mount_opts818debug mount -t "$mount_type" $mount_opts
785mount -t "$mount_type" $mount_opts819mount -t "$mount_type" $mount_opts
786if [ $? -ne 0 ]; then820if [ $? -ne 0 ]; then
@@ -810,6 +844,11 @@ fi
810mkdir -p "${ROOTMNT}/${root_ro}"844mkdir -p "${ROOTMNT}/${root_ro}"
811mount --move ${root_ro} "${ROOTMNT}${root_ro}" ||845mount --move ${root_ro} "${ROOTMNT}${root_ro}" ||
812 fail "failed to move ${root_ro} to ${ROOTMNT}${root_ro}"846 fail "failed to move ${root_ro} to ${ROOTMNT}${root_ro}"
847for mountpoint in $mountpoints; do
848 mkdir -p "${ROOTMNT}${mountpoint}"
849 mount --move "$mountpoint" "${ROOTMNT}${mountpoint}" ||
850 fail "failed to move ${mountpoint} to ${ROOTMNT}${mountpoint}"
851done
813852
814# move mount from ${root_rw} to ${ROOTMNT}${root_rw}853# move mount from ${root_rw} to ${ROOTMNT}${root_rw}
815[ -d ${ROOTMNT}${root_rw} ] || mkdir -p ${ROOTMNT}${root_rw}854[ -d ${ROOTMNT}${root_rw} ] || mkdir -p ${ROOTMNT}${root_rw}

Subscribers

People subscribed via source and target branches