Skip to content

Commit

Permalink
Fix up the GPT in the initramfs
Browse files Browse the repository at this point in the history
This adjusts the GPT in the initramfs, and (obviously) requires the
previous commit.

Fixes: QubesOS/qubes-issues#4974
  • Loading branch information
DemiMarie committed Dec 8, 2024
1 parent f0c98fd commit 3fbb214
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
3 changes: 2 additions & 1 deletion dracut/full-dmroot/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ install() {
inst_multiple \
sfdisk \
swapon \
mkswap
mkswap \
gptfix
}
19 changes: 16 additions & 3 deletions dracut/full-dmroot/qubes_cow_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,32 @@ modprobe xenblk || modprobe xen-blkfront || warn "Qubes: Cannot load Xen Block F

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

# prefer partition if exists
if [ -b /dev/xvda1 ]; then
if /usr/sbin/gptfix fix /dev/xvda; then
udevadm settle --exit-if-exists=/dev/xvda1
if [ -e "/dev/disk/by-partlabel/Root\\x20filesystem" ]; then
ROOT_DEV=$(readlink "/dev/disk/by-partlabel/Root\\x20filesystem")
ROOT_DEV=${ROOT_DEV##*/}
else
ROOT_DEV=xvda3
fi
if ! [ -b "/dev/$ROOT_DEV" ]; then udevadm settle "--exit-if-exists=/dev/$ROOT_DEV"; fi
else
ROOT_DEV=xvda
status=$?
case $status in
(1|2) # EIO, ENOMEM, or bug. Fatal.
die 'Fatal error reading partition table';;
(4|5|8) # Bad or no partition table
ROOT_DEV=xvda;;
(*)
# TODO: what should be done?
# This is things like:
# - "Partition table not supported"
die 'GPT cannot be fixed';;
esac
fi
log_end

SWAP_SIZE_GiB=1
SWAP_SIZE_512B=$(( SWAP_SIZE_GiB * 1024 * 1024 * 2 ))
Expand Down
21 changes: 16 additions & 5 deletions dracut/simple/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,33 @@ die() {

echo "Waiting for /dev/xvda* devices..."
while ! [ -e /dev/xvda ]; do sleep 0.1; done

# prefer partition if exists
if [ -b /dev/xvda1 ]; then
# Fix up partition tables
if /usr/sbin/gptfix fix /dev/xvda; then
while ! [ -e /dev/xvda1 ]; do sleep 0.01; done
if [ -d /dev/disk/by-partlabel ]; then
ROOT_DEV=$(readlink "/dev/disk/by-partlabel/Root\\x20filesystem")
ROOT_DEV=${ROOT_DEV##*/}
else
ROOT_DEV=$(grep -l "PARTNAME=Root filesystem" /sys/block/xvda/xvda*/uevent |\
ROOT_DEV=$(grep -l "PARTNAME=Root filesystem" /sys/block/xvda/xvda*/uevent |
grep -o "xvda[0-9]")
fi
if [ -z "$ROOT_DEV" ]; then
# fallback to third partition
ROOT_DEV=xvda3
fi
while ! [ -b "/dev/$ROOT_DEV" ]; do sleep 0.01; done
else
ROOT_DEV=xvda
case $? in
(1|2) # EIO, ENOMEM, or bug. Fatal.
die 'Fatal error reading partition table';;
(4|5|8) # Bad or no partition table
ROOT_DEV=xvda;;
(*)
# TODO: what should be done?
# - "Partition table not supported"
# - "Disk truncated"
die 'GPT cannot be fixed or disk truncated';;
esac
fi

SWAP_SIZE_GiB=1
Expand Down
3 changes: 2 additions & 1 deletion dracut/simple/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ install() {
rmdir \
sleep \
sfdisk \
mkswap
mkswap \
gptfix
}

0 comments on commit 3fbb214

Please sign in to comment.