-
Notifications
You must be signed in to change notification settings - Fork 52
Integration for GrubCC and SystemdBoot #1113
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b05cb68
Add Bootloader enum
Johan-Liebert1 1b9b19e
efi: Filter components by bootloader
Johan-Liebert1 a8be4e9
bios/efi: Handle bootloader support
Johan-Liebert1 e613340
Handle installs for bootloaders
Johan-Liebert1 40fc00f
grub-cc: Handle statefile
Johan-Liebert1 3a68754
efi: Do not unmount if mountpoint was already mounted
Johan-Liebert1 484a06c
state: Handle state file for GrubCC
Johan-Liebert1 2cee598
Handle generate metadata and Bootloader Updates
Johan-Liebert1 9bdfa59
Fix builds for powerpc and s390x
Johan-Liebert1 b4019aa
component: Reduce use of `dyn Component`
Johan-Liebert1 6a0f8ba
metadata: Set default bootloader
Johan-Liebert1 615a6b3
install: Make `--bootloader` argument optional
Johan-Liebert1 2e05ff3
jenkinsfile: Don't install grub2-minimal
Johan-Liebert1 fa2b4f0
Explicitly handle composefs root
Johan-Liebert1 14467cc
ci: Test grubcc
Johan-Liebert1 00ec302
bootloader: Add SystemdBoot enum variant
Johan-Liebert1 9763156
ci: Add tests for grub-cc and systemd-boot
Johan-Liebert1 fcfd22c
filetree: Skip extra bootloaders
Johan-Liebert1 a6c877a
Introduce `#[cfg(efi_arch)]`
Johan-Liebert1 0447372
Introduce `ComponentType` enum
Johan-Liebert1 e93be0f
Minor refactors
Johan-Liebert1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| # Dockerfile to test GrubCC and systemd-boot | ||
| # Build from the current git into a fedora44 container image. | ||
|
|
||
| ARG base=quay.io/fedora/fedora-bootc:44 | ||
|
|
||
| FROM $base as build | ||
| # This installs our package dependencies, and we want to cache it independently of the rest. | ||
| # Basically we don't want changing a .rs file to blow out the cache of packages. | ||
| RUN <<EORUN | ||
| set -xeuo pipefail | ||
| dnf -y install cargo git openssl-devel | ||
| EORUN | ||
| # Now copy the source | ||
| COPY . /build | ||
| WORKDIR /build | ||
| # See https://www.reddit.com/r/rust/comments/126xeyx/exploring_the_problem_of_faster_cargo_docker/ | ||
| # We aren't using the full recommendations there, just the simple bits. | ||
| RUN --mount=type=cache,target=/build/target --mount=type=cache,target=/var/roothome \ | ||
| make && make install-all DESTDIR=/out | ||
|
|
||
|
|
||
| # Get the latest GrubCC binary | ||
| FROM quay.io/fedora/eln:latest AS grub-cc-download | ||
| RUN --mount=type=tmpfs,target=/run --mount=type=tmpfs,target=/tmp <<EOF | ||
| set -eux | ||
|
|
||
| # There isn't a generic grub2-efi-cc package that DNF can automatically resolve | ||
| case "$(uname -m)" in | ||
| x86_64) | ||
| dnf download grub2-efi-x64-cc | ||
| ;; | ||
| aarch64) | ||
| dnf download grub2-efi-aa64-cc | ||
| ;; | ||
| *) | ||
| echo "Unsupported architecture: $(uname -m)" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| mv ./*.rpm grub-cc.rpm | ||
|
|
||
| EOF | ||
|
|
||
| FROM $base | ||
| # Clean out the default to ensure we're using our updated content | ||
| RUN rpm -e bootupd | ||
| COPY --from=build /out/ / | ||
| COPY --from=grub-cc-download /grub-cc.rpm /var/grub-cc.rpm | ||
| # Install bootc from copr | ||
| RUN --mount=type=tmpfs,target=/run --mount=type=tmpfs,target=/tmp <<EORUN | ||
| set -xeuo pipefail | ||
| dnf -y install dnf-plugins-core bootc systemd-boot tree | ||
| dnf clean all | ||
| rm -rf /var/log | ||
| rm -rf /var/lib | ||
| rm -rf /var/cache | ||
| rm -rf /run/rhsm | ||
| rm -rf /tmp/* | ||
| EORUN | ||
|
|
||
| # Install systemd-boot | ||
| RUN --mount=type=tmpfs,target=/run --mount=type=tmpfs,target=/tmp <<EOF | ||
| set -eux | ||
| # epoch for systemd-boot-unsigned is "(none)" | ||
| evr=$(rpm -q --qf '%{EPOCH}:%{VERSION}-%{RELEASE}\n' systemd-boot-unsigned) | ||
| rpm -ql systemd-boot-unsigned | ||
|
|
||
| . /etc/os-release | ||
|
|
||
| # Create the expected directory structure at /usr/lib/efi/systemd-boot/<evr>/EFI/fedora/ | ||
| mkdir -p "/usr/lib/efi/systemd-boot/${evr}/EFI/$ID" | ||
|
|
||
| if [[ $(uname -m) == x86_64 ]]; then | ||
| grubName="grubx64.efi" | ||
| else | ||
| grubName="grubaa64.efi" | ||
| fi | ||
|
|
||
| cp /usr/lib/systemd/boot/efi/systemd-boot*.efi "/usr/lib/efi/systemd-boot/${evr}/EFI/$ID/$grubName" | ||
|
|
||
| EOF | ||
|
|
||
| # Install grub-cc | ||
| RUN --mount=type=tmpfs,target=/run --mount=type=tmpfs,target=/tmp <<EOF | ||
|
|
||
| set -eux | ||
|
|
||
| cleanup() { | ||
| # Clean up temporary files | ||
| rm -rvf /var/grub-cc* | ||
| } | ||
|
|
||
| # Extract and install grub-cc at the correct path | ||
| mkdir /var/grub-cc | ||
| rpm2archive /var/grub-cc.rpm | tar -xvz -C /var/grub-cc | ||
| file=$(find /var/grub-cc -name '*.efi') | ||
|
|
||
| # Get the EVR from the RPM filename | ||
| evr=$(rpm -qp --qf '%{EPOCH}:%{VERSION}-%{RELEASE}' /var/grub-cc.rpm) | ||
|
|
||
| . /etc/os-release | ||
|
|
||
| if [[ $(uname -m) == x86_64 ]]; then | ||
| grubName="grubx64.efi" | ||
| else | ||
| grubName="grubaa64.efi" | ||
| fi | ||
|
|
||
| # Create the expected directory structure at /usr/lib/efi/grub-cc/<evr>/EFI/fedora/ | ||
| mkdir -p "/usr/lib/efi/grub-cc/${evr}/EFI/$ID/" | ||
| cp "$file" "/usr/lib/efi/grub-cc/${evr}/EFI/$ID/$grubName" | ||
|
|
||
| cleanup | ||
|
|
||
| # Regenerate metadata | ||
| bootupctl backend generate-update-metadata -vvv | ||
|
|
||
| # Set grub as default | ||
| bootupctl backend set-default-bootloader grub | ||
|
|
||
| EOF | ||
|
|
||
| # Sanity check this too | ||
| RUN bootc container lint --fatal-warnings | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| fn main() { | ||
| println!("cargo::rustc-check-cfg=cfg(efi_arch)"); | ||
|
|
||
| if cfg!(any( | ||
| target_arch = "x86_64", | ||
| target_arch = "aarch64", | ||
| target_arch = "riscv64" | ||
| )) { | ||
| println!("cargo:rustc-cfg=efi_arch"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -eux | ||
|
|
||
| IMG_NAME=$1 | ||
| BOOTLOADER=$2 | ||
|
|
||
| case $BOOTLOADER in | ||
| systemd) | ||
| EFI_DIR_NAME=systemd-boot | ||
| ;; | ||
| grub-cc) | ||
| EFI_DIR_NAME=grub-cc | ||
| ;; | ||
| grub) | ||
| EFI_DIR_NAME=grub2 | ||
| ;; | ||
|
Johan-Liebert1 marked this conversation as resolved.
|
||
| *) | ||
| echo "Unknown bootloader $BOOTLOADER" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| cat <<-EOF > sfdisk-buf | ||
| label: gpt | ||
| label-id: 65be9332-59ba-11f1-9b26-6a8e2ab625e4 | ||
| size=1Gib, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, name="EFI-SYSTEM" | ||
| type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, name="root" | ||
| EOF | ||
|
|
||
| truncate -s4G "${BOOTLOADER}-test.img" | ||
|
|
||
| cat sfdisk-buf | sfdisk --wipe=always "${BOOTLOADER}-test.img" | ||
|
|
||
| mkdir -p /var/mnt | ||
|
|
||
| # Also update kernel partition tables | ||
| loopdev=$(losetup --find --show --partscan "${BOOTLOADER}-test.img") | ||
| sleep 1 | ||
|
|
||
| mkfs.vfat "${loopdev}p1" | ||
| mkfs.ext4 "${loopdev}p2" | ||
|
|
||
| mount "${loopdev}p2" /var/mnt | ||
|
|
||
| ESP="/var/mnt/efi" | ||
|
|
||
| mkdir -p $ESP | ||
| mount "${loopdev}p1" $ESP | ||
|
|
||
|
|
||
| # Test installing the bootloader | ||
| podman run --rm --net=host --privileged --pid=host \ | ||
| --privileged \ | ||
| --security-opt label=type:unconfined_t \ | ||
| --env RUST_LOG=trace \ | ||
| -v /dev:/dev \ | ||
| -v /var/mnt:/var/mnt \ | ||
| "$IMG_NAME" \ | ||
| bootupctl backend install --bootloader "$BOOTLOADER" /var/mnt -vvvv | ||
|
|
||
| # Make sure bootupd-state.json is in the esp | ||
| test -f "$ESP/bootupd-state.json" | ||
|
|
||
| cat "$ESP/bootupd-state.json" | jq | ||
|
|
||
| version=$(cat "$ESP/bootupd-state.json" | jq -r ".installed.EFI.meta.version") | ||
|
|
||
| if [[ $version != *shim* ]]; then echo "shim not found in version"; exit 1; fi | ||
| if [[ $version != *"$EFI_DIR_NAME"* ]]; then echo "$BOOTLOADER not found in version"; exit 1; fi | ||
|
|
||
| # Test if the correct binary has been installed | ||
| actualShasum=$(podman run --rm "$IMG_NAME" find "/usr/lib/efi/$EFI_DIR_NAME" -type f -exec sha512sum {} + | awk '{print $1}') | ||
| actualShasum="sha512:$actualShasum" | ||
|
|
||
| if [[ $(uname -m) == "x86_64" ]]; then | ||
| grubName="grubx64.efi" | ||
| else | ||
| grubName="grubaa64.efi" | ||
| fi | ||
|
|
||
| # TODO: Remove hardcoded "fedora" once we have support in centos | ||
| storedShasum=$(cat "$ESP/bootupd-state.json" | jq -r --arg grub "$grubName" '.installed.EFI.filetree.children["fedora/\($grub)"].sha512') | ||
|
|
||
| test "$actualShasum" == "$storedShasum" | ||
|
|
||
| efiBinShasum=$(find "$ESP" -type f -name "$grubName" -exec sha512sum {} + | awk '{print $1}') | ||
| efiBinShasum="sha512:$efiBinShasum" | ||
|
|
||
| test "$efiBinShasum" == "$actualShasum" | ||
|
|
||
| umount -Rl /var/mnt | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, is this really required? I guess it must be - it's us taking over
bootctl installandbootctl update.That feels...unnecessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I spend a bit of time on this, is this case actually "install systemd-boot pretending to be grub" so it gets chainloaded by shim? That looks like what this is.
That feels like a clearly distinct case of things here and really worth clearly documenting.
OK right, and we're doing the same with grub-cc?
Hmmm, I guess it's kind of an assumption woven into things here that we're using shim, which is probably the right one by default, but I think we do ultimately need to handle non-shim cases too.
I guess this isn't blocking per se, but we should have a note about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that's what it is. We will probably hardlink the actual systemd-boot binary at
/usr/lib/efi/systemd-boot/**so that all bootloader live in the same placeyes
We do. On a call with @travier we decided to handle that case later
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the EFI binary loaded by shim is hardcoded in shim: https://src.fedoraproject.org/rpms/shim-unsigned-x64/blob/rawhide/f/shim-unsigned-x64.spec#_154
There are options to change it but they have a lot of downsides: #1080 (comment)
Pretending to be
grub$arch.efiis apparently the simplest option.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We settled (at least for now) on leaving standalone systemd-boot (or potentially standalone grub-cc) support to systemd's bootctl as we don't need all the complexity from bootupd for those cases: #1080 (comment)