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
diff --git a/debian/changelog b/debian/changelog
index 0f55316..083da4d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
1casper (1.473) UNRELEASED; urgency=medium
2
3 * casper-helper: preserve entries 2-4 in the MBR when creating a new
4 partition. (LP: #1977644, #1922342)
5
6 -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Fri, 08 Jul 2022 12:37:44 +1200
7
1casper (1.472) kinetic; urgency=medium8casper (1.472) kinetic; urgency=medium
29
3 * Support iso-url= on the kernel command line as a synonym for url=, to10 * Support iso-url= on the kernel command line as a synonym for url=, to
diff --git a/debian/tests/boot b/debian/tests/boot
index 5abc27e..938fdf8 100755
--- a/debian/tests/boot
+++ b/debian/tests/boot
@@ -395,9 +395,33 @@ touch /hello
395 check_files_exist mnt upper/hello395 check_files_exist mnt upper/hello
396}396}
397397
398test_mbr_preservation () {
399 echo "### creating the partition to save logs preserves other mbr entries"
400
401 ./debian/tests/prep-image image.img ""
402
403 expand_image image.img
404
405 # Forcefully create some dubious entries in the hybrid MBR which
406 # casper should ensure are preserved when creating the partition
407 # for the logs (see LP: #1977644)
408 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
409
410 sfdisk --label-nested dos -d image.img | tee mbr-before
411
412 run image.img ""
413
414 sfdisk --label-nested dos -d image.img | tee mbr-after
415
416 if ! diff -u mbr-before mbr-after; then
417 echo "casper changed entries 2-4 in mbr ^^"
418 exit 1
419 fi
420}
421
398TESTS="test_basic test_auto_log_persistence test_clean_log_directory_each_boot422TESTS="test_basic test_auto_log_persistence test_clean_log_directory_each_boot
399 test_explicit_persistence test_implicit_then_explicit_persistence423 test_explicit_persistence test_implicit_then_explicit_persistence
400 test_no_persistence test_todisk test_uses_casper_rw_partition"424 test_mbr_preservation test_no_persistence test_todisk test_uses_casper_rw_partition"
401425
402for f in $TESTS; do426for f in $TESTS; do
403 eval $f427 eval $f
diff --git a/scripts/casper-helpers b/scripts/casper-helpers
index 72a0cfe..0c9ee5b 100644
--- a/scripts/casper-helpers
+++ b/scripts/casper-helpers
@@ -301,22 +301,16 @@ find_or_create_persistent_partition () {
301 if [ $((size - start*sectorsize)) -lt $((100*1024*1024)) ]; then301 if [ $((size - start*sectorsize)) -lt $((100*1024*1024)) ]; then
302 return302 return
303 fi303 fi
304 MBR_STASH=/tmp/mbr_stash_$$
305 dd if="$DEVICE" bs=1 skip=462 count=48 of="$MBR_STASH"
304 echo "start=$start" | sfdisk --no-reread -q $DEVICE -a || return306 echo "start=$start" | sfdisk --no-reread -q $DEVICE -a || return
305307
306 # If our partition table is GPT, we have a protective MBR; ensure that308 # If our partition table is GPT, we have a protective MBR; it is important
307 # after adding a new partition, if there is a protective MBR, we309 # for some BIOSes that we preserve entries 2-4 in this MBR. See
308 # recreate a bootable partition, the same as xorriso does, for310 # https://bugs.launchpad.net/ubuntu/+source/casper/+bug/1977644 and the
309 # compatibility. (GRUB doesn't actually care which partition is marked311 # very long https://bugs.launchpad.net/ubuntu/+source/casper/+bug/1922342.
310 # bootable, but some BIOSes care that it exists).
311 if sfdisk -d $DEVICE | grep -q 'label: gpt'; then312 if sfdisk -d $DEVICE | grep -q 'label: gpt'; then
312 # detection of dash vs busybox/bash313 dd if="$MBR_STASH" bs=1 seek=462 conv=notrunc count=48 of="$DEVICE"
313 if [ "$(echo -e foo)" = "-e foo" ]; then
314 escape_arg=""
315 else
316 escape_arg=-e
317 fi
318 echo $escape_arg -n '\0200\00\01\00\00\00\01\00\00\00\00\00\01\00\00\00' \
319 | dd of=$DEVICE bs=1 seek=462 conv=notrunc count=16
320 fi314 fi
321 for d in ${DEVICE}$newpartno ${DEVICE}p$newpartno ${DEVICE}-part$newpartno; do315 for d in ${DEVICE}$newpartno ${DEVICE}p$newpartno ${DEVICE}-part$newpartno; do
322 if [ -e $d ]; then316 if [ -e $d ]; then

Subscribers

People subscribed via source and target branches