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
1diff --git a/overlayroot/etc/overlayroot.conf b/overlayroot/etc/overlayroot.conf
2index 3d4e167..f978f35 100644
3--- a/overlayroot/etc/overlayroot.conf
4+++ b/overlayroot/etc/overlayroot.conf
5@@ -17,13 +17,13 @@
6 # overlayroot=tmpfs
7 # overlayroot=tmpfs:swap=1
8 #
9-# * overlayroot=DEVICE or overlayroot=device:PARAMETERS
10-# mount DEVICE as overlayfs and write changes there
11-# device must already have kernel mountalbe filesystem on it.
12+# * overlayroot=DEVICE[:DEVICE] or overlayroot=device:PARAMETERS
13+# mount DEVICE(s) as overlayfs and write changes to the first
14+# device(s) must already have kernel mountalbe filesystem on them.
15 #
16 # available parameters are:
17 # * dev: default: "" [REQUIRED]
18-# use given device for backing filesystem.
19+# use given device(s) for backing filesystems.
20 # Note, 'overlayroot=/dev/vdb' is translated to
21 # 'overlayrooot=device:dev=/dev/vdb'
22 # * timeout: default: 0
23@@ -34,7 +34,9 @@
24 # examples:
25 # overlayroot=/dev/xvdb
26 # overlayroot=/dev/vdb
27+# overlayroot=/dev/vdc:/dev/vdb
28 # overlayroot=device:dev=/dev/sdb,timeout=180
29+# overlayroot=device:dev=/dev/sdc:/dev/sdb,timeout=180
30 # overlayroot=device:dev=LABEL=my-flashdrive,timeout=180
31 #
32 # * overlayroot=crypt:PARAMETERS
33diff --git a/overlayroot/scripts/init-bottom/overlayroot b/overlayroot/scripts/init-bottom/overlayroot
34index 5c13811..48892cd 100755
35--- a/overlayroot/scripts/init-bottom/overlayroot
36+++ b/overlayroot/scripts/init-bottom/overlayroot
37@@ -2,6 +2,7 @@
38 # Copyright, 2012 Dustin Kirkland <kirkland@ubuntu.com>
39 # Copyright, 2012 Scott Moser <smoser@ubuntu.com>
40 # Copyright, 2012 Axel Heider
41+# Copyright, 2024 Daniel Ruthardt <druthardt@linuxfoundation.org>
42 #
43 # Based on scripts from
44 # Sebastian P.
45@@ -335,7 +336,7 @@ overlayrootify_fstab() {
46 local hash="#" oline="" ospec="" upper="" dirs="" copy_opts="" copy_opt=""
47 local spec file vfstype opts pass freq line ro_line
48 local workdir="" use_orig="" relfile="" needs_workdir=false noauto=""
49-
50+
51 [ -f "$input" ] || return 1
52
53 cat <<EOF
54@@ -671,17 +672,29 @@ case "${overlayroot:-disabled}" in
55 /dev/*) opts="dev=${overlayroot}";;
56 *) opts="${overlayroot#device:}";;
57 esac
58- dev_setup "${opts}" ||
59- fail "failed setup overlay for ${overlayroot} [$opts]${cfgmsg}"
60+
61+ devices="$(echo "$opts" | grep -Eo 'dev=([^,]*)' | cut -d= -f2 | tr ":" "\n" | sed '1!G;h;$!d')"
62+
63+ for device in $devices; do
64+ dopts=$(echo "$opts" | sed "s,dev=[^,]*,dev=${device},")
65+
66+ dev_setup "$dopts" ||
67+ fail "failed setup overlay for ${overlayroot} [${dopts}]${cfgmsg}"
68+ done
69 mode="device"
70- device="$_RET_DEVICE"
71+
72+ mountpoints=""
73+ i=1; for device in $(echo "$devices" | sed '$d'); do
74+ mountpoints="${mountpoints:+${mountpoints}
75+}/media/root-ro-${i}"
76+ i=$((i+1)); done
77 ;;
78 crypt:*)
79 mode="crypt"
80 opts=${overlayroot#crypt:}
81 crypto_setup "${opts}" ||
82 fail "failed setup crypt for ${overlayroot}${cfgmsg}"
83- device="$_RET_DEVICE"
84+ devices="$_RET_DEVICE"
85 ;;
86 disabled)
87 debug "overlayroot disabled${cfgmsg}"
88@@ -713,39 +726,13 @@ else
89 fi
90
91 debug "swap=$swap recurse=$recurse debug=$OVERLAYROOT_DEBUG dir=$dir_prefix"
92-debug "device=$device mode=$mode driver=${overlayroot_driver}"
93+debug "devices=$(echo -n "$devices" | tr "\n" ",") mode=$mode driver=${overlayroot_driver}"
94
95 [ "$swap" = "0" -o "$swap" = "1" ] ||
96 fail "invalid setting for swap: $swap. must be '0' or '1'"
97 [ "$recurse" = "0" -o "$recurse" = "1" ] ||
98 fail "invalid setting for recurse: $recurse. must be '0' or '1'"
99
100-log_warn "configuring overlayroot with driver=${overlayroot_driver} mode=$mode opts='$opts' per $used_desc"
101-
102-# settings based on overlayroot_driver
103-workdir=""
104-case "${overlayroot_driver}" in
105- overlayfs|overlay)
106- mount_type="${overlayroot_driver}"
107- mount_opts="-o lowerdir=${root_ro},upperdir=${root_rw}/${dir_prefix}"
108- if needs_workdir; then
109- get_workdir "$root_rw" "$dir_prefix" "/"
110- workdir="$_RET"
111- mount_opts="${mount_opts},workdir=$workdir"
112- fi
113- clean_path "${mount_opts} overlayroot ${ROOTMNT}"
114- mount_opts="$_RET"
115- ;;
116- aufs)
117- mount_type="aufs"
118- mount_opts="-o dirs=${root_rw}/${dir_prefix}:${root_ro}=ro aufs-root ${ROOTMNT}"
119- ;;
120- *)
121- log_fail "invalid overlayroot driver: ${overlayroot_driver}"
122- panic "$MYTAG"
123- ;;
124-esac
125-
126 # make the mount point on the init root fs ${root_rw}
127 mkdir -p "${root_rw}" ||
128 fail "failed to create ${root_rw}"
129@@ -753,6 +740,10 @@ mkdir -p "${root_rw}" ||
130 # make the mount point on the init root fs ${root_ro}
131 mkdir -p "${root_ro}" ||
132 fail "failed to create ${root_ro}"
133+for mountpoint in $mountpoints; do
134+ mkdir -p "$mountpoint" ||
135+ fail "failed to create ${mountpoint}"
136+done
137
138 # mount the backing device to $root_rw
139 if [ "$mode" = "tmpfs" ]; then
140@@ -761,15 +752,20 @@ if [ "$mode" = "tmpfs" ]; then
141 fail "failed to create tmpfs"
142 else
143 # dev or crypto
144- mount "$device" "${root_rw}" ||
145- fail "failed mount backing device $device"
146+ device=$(echo "$devices" | tail -n1)
147+ mount "$device" "$root_rw" ||
148+ fail "failed mount backing device ${device}"
149 fi
150
151 mkdir -p "${root_rw}/${dir_prefix}" ||
152 fail "failed to create ${dir_prefix} on ${device}"
153
154-[ -z "$workdir" ] || mkdir -p "$workdir" ||
155- fail "failed to create workdir '$workdir' on ${device}"
156+i=1; for device in $(echo "$devices" | head -n -1); do
157+ mountpoint=$(echo "$mountpoints" | head -n$i | tail -n1)
158+ # mount the backing device
159+ mount "$device" "$mountpoint" ||
160+ fail "failed mount backing device ${device}"
161+i=$((i+1)); done
162
163 # root is mounted on ${ROOTMNT}, move it to ${ROOT_RO}.
164 mount --move "${ROOTMNT}" "${root_ro}" ||
165@@ -780,7 +776,45 @@ mount --move "${ROOTMNT}" "${root_ro}" ||
166 # "panic". Otherwise the boot process is very likely to fail with even more
167 # errors and leave the system in a wired state.
168
169-# mount virtual fs ${ROOTMNT} with rw-fs ${root_rw} on top or ro-fs ${root_ro}.
170+log_warn "configuring overlayroot with driver=${overlayroot_driver} mode=$mode opts='$opts' per $used_desc"
171+
172+# settings based on overlayroot_driver
173+workdir=""
174+case "${overlayroot_driver}" in
175+ overlayfs|overlay)
176+ mount_type="${overlayroot_driver}"
177+ lowerdirs="$root_ro"
178+ for mountpoint in $mountpoints; do
179+ if [ -d "${mountpoint}${dir_prefix}" ]; then
180+ lowerdir="${mountpoint}${dir_prefix}"
181+ else
182+ lowerdir="$mountpoint"
183+ fi
184+ lowerdirs="${lowerdir}:${lowerdirs}"
185+ done
186+ mount_opts="-o lowerdir=${lowerdirs},upperdir=${root_rw}/${dir_prefix}"
187+ if needs_workdir; then
188+ get_workdir "$root_rw" "$dir_prefix" "/"
189+ workdir="$_RET"
190+ mount_opts="${mount_opts},workdir=$workdir"
191+
192+ [ -z "$workdir" ] || mkdir -p "$workdir" ||
193+ fail "failed to create workdir '${workdir}' on ${device}"
194+ fi
195+ clean_path "${mount_opts} overlayroot ${ROOTMNT}"
196+ mount_opts="$_RET"
197+ ;;
198+ aufs)
199+ mount_type="aufs"
200+ mount_opts="-o dirs=${root_rw}/${dir_prefix}:${root_ro}=ro aufs-root ${ROOTMNT}"
201+ ;;
202+ *)
203+ log_fail "invalid overlayroot driver: ${overlayroot_driver}"
204+ panic "$MYTAG"
205+ ;;
206+esac
207+
208+# mount virtual fs ${ROOTMNT} with rw-fs ${root_rw} on top of ro-fs ${root_ro}.
209 debug mount -t "$mount_type" $mount_opts
210 mount -t "$mount_type" $mount_opts
211 if [ $? -ne 0 ]; then
212@@ -810,6 +844,11 @@ fi
213 mkdir -p "${ROOTMNT}/${root_ro}"
214 mount --move ${root_ro} "${ROOTMNT}${root_ro}" ||
215 fail "failed to move ${root_ro} to ${ROOTMNT}${root_ro}"
216+for mountpoint in $mountpoints; do
217+ mkdir -p "${ROOTMNT}${mountpoint}"
218+ mount --move "$mountpoint" "${ROOTMNT}${mountpoint}" ||
219+ fail "failed to move ${mountpoint} to ${ROOTMNT}${mountpoint}"
220+done
221
222 # move mount from ${root_rw} to ${ROOTMNT}${root_rw}
223 [ -d ${ROOTMNT}${root_rw} ] || mkdir -p ${ROOTMNT}${root_rw}

Subscribers

People subscribed via source and target branches