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

Proposed by Michael Hudson-Doyle
Status: Merged
Merged at revision: b2e8b603fa9c638060b87511f25c06cb18b6f7ce
Proposed branch: ~mwhudson/casper:lp-1926137
Merge into: casper:main
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 Approve
Review via email: mp+405864@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

I would really really really like to be able to rewrite casper in an actually good programming language.

To post a comment you must log in.
Revision history for this message
Steve Langasek (vorlon) :
review: Needs Fixing
Revision history for this message
Michael Hudson-Doyle (mwhudson) :
Revision history for this message
Steve Langasek (vorlon) :
review: Approve

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 3758744..67e8f12 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,10 @@
6+casper (1.464) 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.463) impish; urgency=medium
14
15 * Allow LAYERFS_PATH to be set in configuration files.
16diff --git a/scripts/casper b/scripts/casper
17index 307a2c7..6438a13 100644
18--- a/scripts/casper
19+++ b/scripts/casper
20@@ -842,6 +842,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_src_sysfs/partition ]; then
55+ return
56+ fi
57+ pers_dev=$(cat $pers_src_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@@ -922,24 +975,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 183587d..6fed1f9 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