Skip to content

Commit f785c4b

Browse files
committed
Fix up the GPT in the initramfs
This adjusts the GPT in the initramfs, and (obviously) requires the previous commit. Fixes: QubesOS/qubes-issues#4974
1 parent 96010d0 commit f785c4b

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

dracut/full-dmroot/module-setup.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ install() {
1818
inst_multiple \
1919
sfdisk \
2020
swapon \
21-
mkswap
21+
mkswap \
22+
gptfix
2223
}

dracut/full-dmroot/qubes_cow_setup.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,32 @@ modprobe xenblk || modprobe xen-blkfront || warn "Qubes: Cannot load Xen Block F
5454

5555
log_begin "Waiting for /dev/xvda* devices..."
5656
udevadm settle --exit-if-exists=/dev/xvda
57-
log_end
5857

5958
# prefer partition if exists
60-
if [ -b /dev/xvda1 ]; then
59+
if /usr/sbin/gptfix fix /dev/xvda; then
60+
udevadm settle --exit-if-exists=/dev/xvda1
6161
if [ -e "/dev/disk/by-partlabel/Root\\x20filesystem" ]; then
6262
ROOT_DEV=$(readlink "/dev/disk/by-partlabel/Root\\x20filesystem")
6363
ROOT_DEV=${ROOT_DEV##*/}
6464
else
6565
ROOT_DEV=xvda3
6666
fi
67+
if ! [ -b "/dev/$ROOT_DEV" ]; then udevadm settle "--exit-if-exists=/dev/$ROOT_DEV"; fi
6768
else
68-
ROOT_DEV=xvda
69+
status=$?
70+
case $status in
71+
(1|2) # EIO, ENOMEM, or bug. Fatal.
72+
die 'Fatal error reading partition table';;
73+
(4|5|8) # Bad or no partition table
74+
ROOT_DEV=xvda;;
75+
(*)
76+
# TODO: what should be done?
77+
# This is things like:
78+
# - "Partition table not supported"
79+
die 'GPT cannot be fixed';;
80+
esac
6981
fi
82+
log_end
7083

7184
SWAP_SIZE_GiB=1
7285
SWAP_SIZE_512B=$(( SWAP_SIZE_GiB * 1024 * 1024 * 2 ))

dracut/simple/init.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,33 @@ die() {
2828

2929
echo "Waiting for /dev/xvda* devices..."
3030
while ! [ -e /dev/xvda ]; do sleep 0.1; done
31-
32-
# prefer partition if exists
33-
if [ -b /dev/xvda1 ]; then
31+
# Fix up partition tables
32+
if /usr/sbin/gptfix fix /dev/xvda; then
33+
while ! [ -e /dev/xvda1 ]; do sleep 0.01; done
3434
if [ -d /dev/disk/by-partlabel ]; then
3535
ROOT_DEV=$(readlink "/dev/disk/by-partlabel/Root\\x20filesystem")
3636
ROOT_DEV=${ROOT_DEV##*/}
3737
else
38-
ROOT_DEV=$(grep -l "PARTNAME=Root filesystem" /sys/block/xvda/xvda*/uevent |\
38+
ROOT_DEV=$(grep -l "PARTNAME=Root filesystem" /sys/block/xvda/xvda*/uevent |
3939
grep -o "xvda[0-9]")
4040
fi
4141
if [ -z "$ROOT_DEV" ]; then
4242
# fallback to third partition
4343
ROOT_DEV=xvda3
4444
fi
45+
while ! [ -b "/dev/$ROOT_DEV" ]; do sleep 0.01; done
4546
else
46-
ROOT_DEV=xvda
47+
case $? in
48+
(1|2) # EIO, ENOMEM, or bug. Fatal.
49+
die 'Fatal error reading partition table';;
50+
(4|5|8) # Bad or no partition table
51+
ROOT_DEV=xvda;;
52+
(*)
53+
# TODO: what should be done?
54+
# - "Partition table not supported"
55+
# - "Disk truncated"
56+
die 'GPT cannot be fixed or disk truncated';;
57+
esac
4758
fi
4859

4960
SWAP_SIZE_GiB=1

dracut/simple/module-setup.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ install() {
2929
rmdir \
3030
sleep \
3131
sfdisk \
32-
mkswap
32+
mkswap \
33+
gptfix
3334
}

0 commit comments

Comments
 (0)