Merge ~mwhudson/casper:lp-1926137-focal into casper:focal

Proposed by Michael Hudson-Doyle
Status: Needs review
Proposed branch: ~mwhudson/casper:lp-1926137-focal
Merge into: casper:focal
Diff against target: 120 lines (+65/-18)
3 files modified
debian/changelog (+7/-0)
scripts/casper (+54/-18)
scripts/casper-helpers (+4/-0)
Reviewer Review Type Date Requested Status
Steve Langasek Pending
Review via email: mp+406506@code.launchpad.net

Commit message

only use a partition from the blockdev holding the livefs for auto logs

https://bugs.launchpad.net/ubuntu/+source/casper/+bug/1926137 describes
a situation where a partition called "writable" on the disk the user
wanted to install to was mounted and then caused the install to fail.
To avoid this, change things to only write logs to a partition on the
same block device as that holding the livefs by default.

Description of the change

This is a backport from tip. It fixes a bug that doesn't have a simple workaround but it does change behaviour: previously if you'd burnt the installer to an ISO and created a USB stick with a filesystem with label 'writable', logs would have been written to the USB stick. With this branch, they won't. But that doesn't seem like a particularly common case (it's certainly not the default case this code is intended to cover).

To post a comment you must log in.

Unmerged commits

b588f36... by Michael Hudson-Doyle

only use a partition from the blockdev holding the livefs for auto logs

https://bugs.launchpad.net/ubuntu/+source/casper/+bug/1926137 describes
a situation where a partition called "writable" on the disk the user
wanted to install to was mounted and then caused the install to fail.
To avoid this, change things to only write logs to a partition on the
same block device as that holding the livefs by default.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index d995221..746a3e8 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,10 @@
6+casper (1.445.2) UNRELEASED; urgency=medium
7+
8+ * Only use a partition from the blockdev holding the livefs for auto logs.
9+ (LP: #1926137)
10+
11+ -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Mon, 19 Jul 2021 12:39:36 +1200
12+
13 casper (1.445.1) focal; urgency=medium
14
15 * casper SRU for point release LP: #1884933:
16diff --git a/scripts/casper b/scripts/casper
17index f1d09ee..b7d74e4 100644
18--- a/scripts/casper
19+++ b/scripts/casper
20@@ -843,6 +843,59 @@ find_livefs() {
21 return 1
22 }
23
24+setup_auto_log_persistence() {
25+ # If there is a writable (or casper-rw) filesystem on a partition
26+ # of the same block device we found the live filesystem on and
27+ # we're not already using it for persistence, use it for logs and
28+ # crash reports.
29+ #
30+ # The goal here is to do this in the common case where the image
31+ # has been dd-ed onto a USB stick that has some extra space that
32+ # can be used for logs. Any kind of deviation from this scenario
33+ # and we just abort to avoid situations like
34+ # https://bugs.launchpad.net/ubuntu/+source/casper/+bug/1926137
35+ # where a partition called "writable" on the disk the user wanted
36+ # to install to was mounted and then caused the install to fail.
37+ if [ -n "$PERSISTENT" ] || [ -n "$NOPERSISTENT" ]; then
38+ return
39+ fi
40+ if [ ! -e "/dev/disk/by-label/$(root_persistence_label)" ]; then
41+ return
42+ fi
43+ livefs_src_dev=$(what_is_mounted $mountpoint)
44+ if [ -z "$livefs_src_dev" ]; then
45+ return
46+ fi
47+ livefs_src_sysfs=$(readlink -f "/sys/class/block/$(basename $livefs_src_dev)")
48+ if [ ! -f $livefs_src_sysfs/partition ]; then
49+ return
50+ fi
51+ livefs_dev=$(cat $livefs_src_sysfs/../dev)
52+ pers_dev=$(readlink -f "/dev/disk/by-label/$(root_persistence_label)")
53+ pers_sysfs=$(readlink -f "/sys/class/block/$(basename $pers_dev)")
54+ if [ ! -f $pers_sysfs/partition ]; then
55+ return
56+ fi
57+ pers_dev=$(cat $pers_sysfs/../dev)
58+ if [ $livefs_dev != $pers_dev ]; then
59+ return
60+ fi
61+ mkdir /log-persistence
62+ if mount -w "/dev/disk/by-label/$(root_persistence_label)" /log-persistence; then
63+ local i=0 d=$(date -uIdate) pdir
64+ while :; do
65+ pdir=/log-persistence/install-logs-$d.$i
66+ if [ ! -e $pdir ]; then
67+ mkdir -p $pdir/log $pdir/crash
68+ mount --bind $pdir/log "${rootmnt}/var/log"
69+ mount --bind $pdir/crash "${rootmnt}/var/crash"
70+ break
71+ fi
72+ i=$((i+1))
73+ done
74+ fi
75+}
76+
77 mountroot() {
78 exec 6>&1
79 exec 7>&2
80@@ -923,24 +976,7 @@ mountroot() {
81
82 mount_images_in_directory "${livefs_root}" "${rootmnt}"
83
84- if [ -z "$PERSISTENT" ] && [ -z "$NOPERSISTENT" ] && [ -e "/dev/disk/by-label/$(root_persistence_label)" ]; then
85- # If there is a casper-rw filesystem and we're not using it
86- # for persistence, use it for logs and crash reports.
87- mkdir /log-persistence
88- if mount -w "/dev/disk/by-label/$(root_persistence_label)" /log-persistence; then
89- local i=0 d=$(date -uIdate) pdir
90- while :; do
91- pdir=/log-persistence/install-logs-$d.$i
92- if [ ! -e $pdir ]; then
93- mkdir -p $pdir/log $pdir/crash
94- mount --bind $pdir/log "${rootmnt}/var/log"
95- mount --bind $pdir/crash "${rootmnt}/var/crash"
96- break
97- fi
98- i=$((i+1))
99- done
100- fi
101- fi
102+ setup_auto_log_persistence
103
104 # initialize the /var/crash directory in overlayfs so that inotify for
105 # /var/crash works and update-notifier will notify of crashes
106diff --git a/scripts/casper-helpers b/scripts/casper-helpers
107index 7479d98..01e419f 100644
108--- a/scripts/casper-helpers
109+++ b/scripts/casper-helpers
110@@ -65,6 +65,10 @@ where_is_mounted() {
111 return 1
112 }
113
114+what_is_mounted() {
115+ cat /proc/mounts | awk -v P=$1 '$2 == P { print $1 }'
116+}
117+
118 lastline() {
119 while read lines ; do
120 line=${lines}

Subscribers

People subscribed via source and target branches