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

Proposed by Michael Hudson-Doyle
Status: Merged
Merged at revision: d278bbc8f3b519ea983d5fbcd8185b4fe4c3db15
Proposed branch: ~mwhudson/casper:lp-1977644
Merge into: casper:main
Diff against target: 88 lines (+39/-14)
3 files modified
debian/changelog (+7/-0)
debian/tests/boot (+25/-1)
scripts/casper-helpers (+7/-13)
Reviewer Review Type Date Requested Status
Steve Langasek Approve
Review via email: mp+426522@code.launchpad.net

Commit message

casper-helper: preserve entries 2-4 in the MBR when creating a new partition. (LP: #1977644, #1922342)

Description of the change

To post a comment you must log in.
Revision history for this message
Steve Langasek (vorlon) :
review: Approve
Revision history for this message
Steve Langasek (vorlon) wrote :

(any chance of an integration test for this?)

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Here's an attempt at a test. Haven't tried to run it yet though.

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 0f55316..083da4d 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,10 @@
6+casper (1.473) UNRELEASED; urgency=medium
7+
8+ * casper-helper: preserve entries 2-4 in the MBR when creating a new
9+ partition. (LP: #1977644, #1922342)
10+
11+ -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Fri, 08 Jul 2022 12:37:44 +1200
12+
13 casper (1.472) kinetic; urgency=medium
14
15 * Support iso-url= on the kernel command line as a synonym for url=, to
16diff --git a/debian/tests/boot b/debian/tests/boot
17index 5abc27e..938fdf8 100755
18--- a/debian/tests/boot
19+++ b/debian/tests/boot
20@@ -395,9 +395,33 @@ touch /hello
21 check_files_exist mnt upper/hello
22 }
23
24+test_mbr_preservation () {
25+ echo "### creating the partition to save logs preserves other mbr entries"
26+
27+ ./debian/tests/prep-image image.img ""
28+
29+ expand_image image.img
30+
31+ # Forcefully create some dubious entries in the hybrid MBR which
32+ # casper should ensure are preserved when creating the partition
33+ # for the logs (see LP: #1977644)
34+ echo -en '\0100\00\01\00\00\00\01\00\00\00\00\00\01\00\00\00\0200\00\01\00\00\00\01\00\00\00\00\00\01\00\00\00' | dd of=image.img bs=1 seek=462 conv=notrunc count=32
35+
36+ sfdisk --label-nested dos -d image.img | tee mbr-before
37+
38+ run image.img ""
39+
40+ sfdisk --label-nested dos -d image.img | tee mbr-after
41+
42+ if ! diff -u mbr-before mbr-after; then
43+ echo "casper changed entries 2-4 in mbr ^^"
44+ exit 1
45+ fi
46+}
47+
48 TESTS="test_basic test_auto_log_persistence test_clean_log_directory_each_boot
49 test_explicit_persistence test_implicit_then_explicit_persistence
50- test_no_persistence test_todisk test_uses_casper_rw_partition"
51+ test_mbr_preservation test_no_persistence test_todisk test_uses_casper_rw_partition"
52
53 for f in $TESTS; do
54 eval $f
55diff --git a/scripts/casper-helpers b/scripts/casper-helpers
56index 72a0cfe..0c9ee5b 100644
57--- a/scripts/casper-helpers
58+++ b/scripts/casper-helpers
59@@ -301,22 +301,16 @@ find_or_create_persistent_partition () {
60 if [ $((size - start*sectorsize)) -lt $((100*1024*1024)) ]; then
61 return
62 fi
63+ MBR_STASH=/tmp/mbr_stash_$$
64+ dd if="$DEVICE" bs=1 skip=462 count=48 of="$MBR_STASH"
65 echo "start=$start" | sfdisk --no-reread -q $DEVICE -a || return
66
67- # If our partition table is GPT, we have a protective MBR; ensure that
68- # after adding a new partition, if there is a protective MBR, we
69- # recreate a bootable partition, the same as xorriso does, for
70- # compatibility. (GRUB doesn't actually care which partition is marked
71- # bootable, but some BIOSes care that it exists).
72+ # If our partition table is GPT, we have a protective MBR; it is important
73+ # for some BIOSes that we preserve entries 2-4 in this MBR. See
74+ # https://bugs.launchpad.net/ubuntu/+source/casper/+bug/1977644 and the
75+ # very long https://bugs.launchpad.net/ubuntu/+source/casper/+bug/1922342.
76 if sfdisk -d $DEVICE | grep -q 'label: gpt'; then
77- # detection of dash vs busybox/bash
78- if [ "$(echo -e foo)" = "-e foo" ]; then
79- escape_arg=""
80- else
81- escape_arg=-e
82- fi
83- echo $escape_arg -n '\0200\00\01\00\00\00\01\00\00\00\00\00\01\00\00\00' \
84- | dd of=$DEVICE bs=1 seek=462 conv=notrunc count=16
85+ dd if="$MBR_STASH" bs=1 seek=462 conv=notrunc count=48 of="$DEVICE"
86 fi
87 for d in ${DEVICE}$newpartno ${DEVICE}p$newpartno ${DEVICE}-part$newpartno; do
88 if [ -e $d ]; then

Subscribers

People subscribed via source and target branches