Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up GPT partition tables automatically #119

Merged
merged 3 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
checks:tests:
after_script:
- (cd qrexec-lib; gcov *.c || :)
- (cd gptfixer; gcov *.c || :)
- ./ci/codecov-wrapper --gcov
before_script:
- sudo dnf install -y python3-pip 'pkgconfig(icu-uc)' sequoia-sqv
Expand All @@ -11,16 +12,11 @@ checks:tests:
- python3 -m coverage run -m unittest discover -v imgconverter -p test.py
- export CFLAGS="--coverage -DCOVERAGE" LDFLAGS=--coverage
- make -C qrexec-lib check NO_REBUILD_TABLE=1
- gptfixer/test.sh
stage: checks
tags:
- docker
include:
- file: /r4.1/gitlab-base.yml
project: QubesOS/qubes-continuous-integration
- file: /r4.1/gitlab-dom0.yml
project: QubesOS/qubes-continuous-integration
- file: /r4.1/gitlab-vm.yml
project: QubesOS/qubes-continuous-integration
- file: /r4.2/gitlab-base.yml
project: QubesOS/qubes-continuous-integration
- file: /r4.2/gitlab-host.yml
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
SBINDIR ?= /usr/sbin
LIBDIR ?= /usr/lib64
SCRIPTSDIR ?= /usr/lib/qubes
SYSLIBDIR ?= /usr/lib
INCLUDEDIR ?= /usr/include
CFLAGS ?= -Wall -Wextra -Werror -O3 -g3 -Werror=format=2
CC ?= gcc

export LIBDIR SCRIPTSDIR SYSLIBDIR INCLUDEDIR
.PHONY: all selinux install install-selinux install-fedora-kernel-support install-debian-kernel-support clean
Expand Down Expand Up @@ -35,6 +38,14 @@ install-debian-kernel-support:
$(MAKE) -C dracut install
$(MAKE) -C grub install-debian

install-gptfix: gptfixer/gpt
install -D gptfixer/gpt $(DESTDIR)$(SBINDIR)/gptfix
gptfixer/gpt_LDLIBS := -lz
gptfixer/gpt_CFLAGS := -D_GNU_SOURCE -fno-strict-aliasing -fno-delete-null-pointer-checks -fno-strict-overflow
%: %.c Makefile
$(CC) $($(@)_CFLAGS) -o $@ $< $(CFLAGS) -MD -MP -MF [email protected] $($(@)_LDLIBS)
-include gptfixer/*.dep

clean:
$(MAKE) -C qrexec-lib clean
$(MAKE) -C qmemman clean
Expand Down
1 change: 1 addition & 0 deletions archlinux/PKGBUILD.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ package_qubes-vm-kernel-support() {
install -m 611 "${srcdir}/${_pkgnvr}/archlinux/PKGBUILD-initcpio-hook.sh" "${pkgdir}/usr/lib/initcpio/hooks/qubes"
install -m 755 "${srcdir}/${_pkgnvr}/dracut/full-dmroot/qubes_cow_setup.sh" "${pkgdir}/usr/lib/qubes/qubes_cow_setup.sh"
install -m 0644 "${srcdir}/${_pkgnvr}/grub/grub.qubes-kernel-vm-support" "${pkgdir}/etc/default/grub.qubes-kernel-vm-support"
make install-gptfix SBINDIR=/usr/bin "DESTDIR=$pkgdir"
}
3 changes: 2 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Build-Depends:
libxen-dev,
pkg-config,
python3-setuptools,
libicu-dev
libicu-dev,
libz-dev,
Standards-Version: 4.4.0.1
Homepage: https://www.qubes-os.org
Vcs-Git: https://github.com/QubesOS/qubes-linux-utils.git
Expand Down
1 change: 1 addition & 0 deletions debian/qubes-kernel-vm-support.install
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ usr/lib/dracut/modules.d/90qubes-vm-modules/*
usr/lib/dracut/modules.d/90qubes-vm-simple/*
usr/lib/dracut/modules.d/80xen-scrub-pages/*
etc/default/grub.d/30-qubes-kernel-vm-support.cfg
usr/sbin/gptfix
1 change: 1 addition & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ override_dh_auto_build:
override_dh_auto_install:
make install LIBDIR=/usr/lib DEBIANBUILD=1 PYTHON_PREFIX_ARG=--install-layout=deb
make install-debian-kernel-support LIBDIR=/usr/lib DEBIANBUILD=1
make install-gptfix SBINDIR=/usr/sbin

override_dh_install:
dh_install --fail-missing
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
}
Loading