Merge lp:~mvo/ubuntu/wily/initramfs-tools-ubuntu-core/new-and-old into lp:ubuntu/wily/initramfs-tools-ubuntu-core

Proposed by Michael Vogt on 2015-10-19
Status: Merged
Merge reported by: Michael Vogt
Merged at revision: not available
Proposed branch: lp:~mvo/ubuntu/wily/initramfs-tools-ubuntu-core/new-and-old
Merge into: lp:ubuntu/wily/initramfs-tools-ubuntu-core
Diff against target: 237 lines (+128/-60)
2 files modified
hooks/ubuntu-core-rootfs (+1/-0)
scripts/ubuntu-core-rootfs (+127/-60)
To merge this branch: bzr merge lp:~mvo/ubuntu/wily/initramfs-tools-ubuntu-core/new-and-old
Reviewer Review Type Date Requested Status
Timo Jyrinki Resubmit on 2015-11-16
Oliver Grawert 2015-10-19 Pending
Ubuntu branches 2015-10-19 Pending
Review via email: mp+274875@code.launchpad.net

Description of the change

This branch adds support for initramfs-tools in snappy to mount the new squashfs/snapfs based os and kernel snaps. It also keeps compatibility with the old snappy_ab partition layout so that we can have a smooth transition and easier testing.

To post a comment you must log in.
32. By Michael Vogt on 2015-10-19

hooks/ubuntu-core-rootfs: ensure squashfs module is part of the initramfs

33. By Michael Vogt on 2015-10-19

scripts/ubuntu-core-rootfs: no need for manual insmod, system will figure it out

Michael Vogt (mvo) wrote :

Thanks a bunch Ogra for your irc suggestions that lead to r32 and r33!

34. By Michael Vogt on 2015-10-19

scripts/ubuntu-core-rootfs: do not hardcode LABEL=writable (thanks ogra!

Oliver Grawert (ogra) wrote :

there is one line that makes me itch a bit ....
after we mount $rootmnt from $writable_mnt we move $writable_mnt underneath $rootmnt, so we are effectively pulling out the floor under ourselves.
while i'm not sure what the implications of this actually are (since run-init makes everything above $rootmnt invisible anyway once we switch to the real root) I wonder if we shouldnt use --bind instead of --move (thats line 197 below)

mount --move "$writable_mnt" "${rootmnt}/writable"

35. By Michael Vogt on 2015-10-21

fix label, re-add insmod of squashfs

36. By Michael Vogt on 2015-10-21

remove debug entry

Timo Jyrinki (timo-jyrinki) wrote :

Please resubmit to xenial.

review: Resubmit

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/ubuntu-core-rootfs'
2--- hooks/ubuntu-core-rootfs 2015-02-25 10:05:57 +0000
3+++ hooks/ubuntu-core-rootfs 2015-10-21 13:53:20 +0000
4@@ -22,3 +22,4 @@
5 copy_exec /bin/chown
6 copy_exec /sbin/findfs
7 copy_exec /sbin/e2fsck
8+manual_add_modules squashfs
9
10=== modified file 'scripts/ubuntu-core-rootfs'
11--- scripts/ubuntu-core-rootfs 2015-08-24 13:54:01 +0000
12+++ scripts/ubuntu-core-rootfs 2015-10-21 13:53:20 +0000
13@@ -147,60 +147,10 @@
14 done
15 }
16
17-#---------------------------------------------------------------------
18-# XXX: Entry point - called by the initramfs "/init" script.
19-#---------------------------------------------------------------------
20-mountroot()
21+fsck_writable()
22 {
23- local writable_label="writable"
24-
25- local writable_mnt="/tmpmnt_${writable_label}"
26-
27- pre_mountroot
28-
29- [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-premount"
30- run_scripts /scripts/local-premount
31- [ "$quiet" != "y" ] && log_end_msg
32-
33- # There are 2 root partitions but grub tells us which to boot
34- # with via "root="
35- for x in $(cat /proc/cmdline); do
36- case "${x}" in
37- root=*)
38- root="${x#*=}"
39- ;;
40- esac
41- done
42-
43- # Make sure the device has been created by udev before we try to mount
44- wait-for-root "$root" "${ROOTDELAY:-180}" || panic "unable to find root partition '$root'"
45-
46- [ -n "$root" ] || panic "no root partition specified"
47-
48- if echo "$root" | grep -q ^/; then
49- path="$root"
50- else
51- # convert UUID/LABEL to a device name
52- path=$(findfs "$root" 2>/dev/null || :)
53- fi
54-
55- [ -e "$path" ] || panic "root device $path does not exist"
56-
57- # Mount the root filesystem read-only.
58- echo "initrd: mounting $path" >/dev/kmsg || true
59- mount -o defaults,ro "$path" "$rootmnt"
60-
61- rootpath="$path"
62-
63- # Create a read-only bind mount on top of the already read-only
64- # FS. This is to stop the system from noticing when the root
65- # filesystem is made writable (when system updates are applied).
66- mount -o bind,ro "$rootmnt" "$rootmnt"
67-
68- echo "initrd: mounting /run" >/dev/kmsg || true
69- mount -o rw,nosuid,noexec,relatime,mode=755 -t tmpfs tmpfs "${rootmnt}/run"
70-
71- mkdir -p "$writable_mnt"
72+ local writable_label="$1"
73+ local writable_mnt="$2"
74
75 path=$(get_partition_from_label "$writable_label")
76
77@@ -226,9 +176,122 @@
78
79 echo "$(date '+%s'): end" >> "$logfile" || true
80
81- echo "initrd: mounting $writable_label partition" >/dev/kmsg || true
82- mount "$path" "$writable_mnt"
83- mkdir -p "${rootmnt}/writable"
84+}
85+
86+# setup $rootmnt based on os/kernel snaps
87+do_new_style_root_mounting()
88+{
89+ root="LABEL=$writable_label"
90+
91+ # Make sure the device has been created by udev before we try to mount
92+ wait-for-root "$root" "${ROOTDELAY:-180}" || panic "unable to find root partition '$root'"
93+
94+ [ -n "$root" ] || panic "no root partition specified"
95+
96+ if echo "$root" | grep -q ^/; then
97+ path="$root"
98+ else
99+ # convert UUID/LABEL to a device name
100+ path=$(findfs "$root" 2>/dev/null || :)
101+ fi
102+
103+ [ -e "$path" ] || panic "root device $path does not exist"
104+
105+ # FIXME: meh, system should figure this out
106+ #insmod ./lib/modules/*/kernel/fs/nls/nls_iso8859-1.ko
107+ insmod ./lib/modules/*/kernel/fs/squashfs/squashfs.ko
108+
109+ # mount writable rw
110+ path=$(get_partition_from_label "$writable_label")
111+ mount "$path" "$writable_mnt"
112+
113+ # mount OS snap
114+ mount "${writable_mnt}/system-data/var/lib/snappy/snaps/${snappy_os}" "$rootmnt"
115+
116+ # now add a kernel bind mounts to it
117+ local kernel_mnt="/tmpmnt_kernel"
118+ mkdir -p "$kernel_mnt"
119+ mount "${writable_mnt}/system-data/var/lib/snappy/snaps/${snappy_kernel}" "$kernel_mnt"
120+ for d in modules firmware; do
121+ mount -o bind "${kernel_mnt}/lib/$d" "$rootmnt/lib/$d"
122+ done
123+}
124+
125+# setup $rootmnt from system_ab style
126+do_old_style_root_mounting()
127+{
128+ # Make sure the device has been created by udev before we try to mount
129+ wait-for-root "$root" "${ROOTDELAY:-180}" || panic "unable to find root partition '$root'"
130+
131+ [ -n "$root" ] || panic "no root partition specified"
132+
133+ if echo "$root" | grep -q ^/; then
134+ path="$root"
135+ else
136+ # convert UUID/LABEL to a device name
137+ path=$(findfs "$root" 2>/dev/null || :)
138+ fi
139+
140+ [ -e "$path" ] || panic "root device $path does not exist"
141+
142+ # Mount the root filesystem read-only.
143+ echo "initrd: mounting $path" >/dev/kmsg || true
144+ mount -o defaults,ro "$path" "$rootmnt"
145+
146+ rootpath="$path"
147+
148+ # Create a read-only bind mount on top of the already read-only
149+ # FS. This is to stop the system from noticing when the root
150+ # filesystem is made writable (when system updates are applied).
151+ mount -o bind,ro "$rootmnt" "$rootmnt"
152+}
153+
154+#---------------------------------------------------------------------
155+# XXX: Entry point - called by the initramfs "/init" script.
156+#---------------------------------------------------------------------
157+mountroot()
158+{
159+ pre_mountroot
160+
161+ [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-premount"
162+ run_scripts /scripts/local-premount
163+ [ "$quiet" != "y" ] && log_end_msg
164+
165+ # find what snappy-os version to use
166+ for x in $(cat /proc/cmdline); do
167+ case "${x}" in
168+ # new kernel/os snap vars
169+ snappy_os=*)
170+ snappy_os="${x#*=}"
171+ ;;
172+ snappy_kernel=*)
173+ snappy_kernel="${x#*=}"
174+ ;;
175+ # old system-ab style
176+ root=*)
177+ root="${x#*=}"
178+ ;;
179+ esac
180+ done
181+
182+ # always ensure writable is in a good state
183+ writable_label="writable"
184+ writable_mnt="/tmpmnt_${writable_label}"
185+ mkdir -p "$writable_mnt"
186+ fsck_writable "$writable_label" "$writable_mnt"
187+
188+ # check if we are on a new os/kernel snap system or a old snappy_ab one
189+ if [ -n "$snappy_os" ] && [ -n "$snappy_kernel" ]; then
190+ do_new_style_root_mounting
191+ else
192+ do_old_style_root_mounting
193+ fi
194+
195+ # mount /run
196+ echo "initrd: mounting /run" >/dev/kmsg || true
197+ mount -o rw,nosuid,noexec,relatime,mode=755 -t tmpfs tmpfs "${rootmnt}/run"
198+
199+ # move /writable to its final destination
200 mount --move "$writable_mnt" "${rootmnt}/writable"
201
202 # Prepare the fstab
203@@ -243,7 +306,11 @@
204 echo "# DO NOT EDIT THIS FILE BY HAND - YOUR CHANGES WILL BE OVERWRITTEN" >> "$fstab"
205 echo "# (See writable-paths(5) for details)" >> "$fstab"
206 echo "/dev/root / rootfs defaults,ro 0 0" >> "$fstab"
207-
208+ # FIXME: ideally we would mount /writable RO here and
209+ # let systemd do a "remount,rw" for us. unfortunately
210+ # this is not supported by systemd so we need to do
211+ # the RW mount and fsck dance etc here :/
212+ echo "LABEL=writable /writable auto defaults 0 0" >> "$fstab"
213 handle_writable_paths "$writable_paths" "$fstab"
214 fi
215
216@@ -273,6 +340,7 @@
217 fi
218 fi
219
220+ # FIXME: the below can go away once we no longer support snappy_ab
221 # add an fstab entry to mount the "other" rootfs partition read-only
222 partition=$(findfs LABEL="system-b" 2>/dev/null || :)
223 abs_rootpath=$(readlink -f "$rootpath" || :)
224@@ -281,11 +349,10 @@
225 else
226 other="$partition"
227 fi
228-
229 if [ -n "$other" ]; then
230 echo "$other /writable/cache/system auto defaults,ro 0 0" >> "$fstab"
231- fi
232-
233+ fi
234+
235 # Mount the systemd overlay so that we have a complete root partition during boot
236 mkdir -p "${rootmnt}/writable/system-data/etc/systemd/system"
237 mount -o bind "${rootmnt}/writable/system-data/etc/systemd/system" "${rootmnt}/etc/systemd/system"

Subscribers

People subscribed via source and target branches

to all changes: