Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ OnFailureJobMode=isolate

# Since we are mounting /boot, require the device first. This isn't strictly
# necessary since we run late, but on principle let's make clear the dependency.
Requires=dev-disk-by\x2dlabel-boot.device
After=dev-disk-by\x2dlabel-boot.device

# Requires=dev-disk-by\x2dlabel-boot.device
# After=dev-disk-by\x2dlabel-boot.device

After=boot-part-discovered.target
ConditionFileNotEmpty=/run/coreos/boot-partition-status

# Start after Ignition has finished
After=ignition-files.service
# As above, this isn't strictly necessary, but on principle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ mkdir -p "${UNIT_DIR}/coreos-ignition-setup-user.service.d"
mkdir -p "${UNIT_DIR}/coreos-copy-firstboot-network.service.d"
cat > "${UNIT_DIR}/coreos-ignition-setup-user.service.d/diskful.conf" <<EOF
[Unit]
Requires=dev-disk-by\x2dlabel-boot.device
After=dev-disk-by\x2dlabel-boot.device
After=boot-part-discovered.target
ConditionFileNotEmpty=/run/coreos/boot-partition-status
EOF
cp "${UNIT_DIR}/coreos-ignition-setup-user.service.d/diskful.conf" \
"${UNIT_DIR}/coreos-copy-firstboot-network.service.d/diskful.conf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ Before=ignition-diskful.target
# iSCSI, but we still run.
After=coreos-copy-firstboot-network.service

Requires=dev-disk-by\x2dlabel-boot.device
After=dev-disk-by\x2dlabel-boot.device
# Requires=dev-disk-by\x2dlabel-boot.device
# After=dev-disk-by\x2dlabel-boot.device

After=boot-part-discovered.target
ConditionFileNotEmpty=/run/coreos/boot-partition-status

# And since the boot device may be on multipath; optionally wait for it to
# appear via the dynamic target.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ OnFailure=emergency.target
OnFailureJobMode=isolate

# That's a weak dependency, so service won't fail if boot dissaperears
Wants=dev-disk-by\x2dlabel-boot.device
After=dev-disk-by\x2dlabel-boot.device
# Wants=dev-disk-by\x2dlabel-boot.device
# After=dev-disk-by\x2dlabel-boot.device

# TODO(Johan-Liebert1): We won't reach diskful.target
After=boot-part-discovered.target
ConditionFileNotEmpty=/run/coreos/boot-partition-status

# Start after ignition has finished with disks but before mounting them
After=ignition-disks.service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ After=systemd-udevd.service
# And since the boot device may be on multipath; optionally wait for it to
# appear via the dynamic target.
After=coreos-multipath-wait.target
Requires=dev-disk-by\x2dlabel-boot.device
After=dev-disk-by\x2dlabel-boot.device
# Requires=dev-disk-by\x2dlabel-boot.device
# After=dev-disk-by\x2dlabel-boot.device

After=boot-part-discovered.target
ConditionFileNotEmpty=/run/coreos/boot-partition-status

# Run before services that modify/use `boot` partition
Before=coreos-gpt-setup.service coreos-boot-edit.service

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ add_requires sysroot-var.mount initrd-root-fs.target
# https://github.com/coreos/fedora-coreos-tracker/issues/1423
add_requires coreos-enable-network.service initrd-root-fs.target

mkdir -p "${UNIT_DIR}/ostree-prepare-root.service.d"
cat > "${UNIT_DIR}/ostree-prepare-root.service.d/10-live.conf" <<EOF
# With live PXE there's no ostree= argument on the kernel command line, so
# we need to find the tree path and pass it to ostree-prepare-root. But
# ostree-prepare-root only knows how to read the path from
# /proc/cmdline, so we need to synthesize the proper karg and bind-mount
# it over /proc/cmdline.
mkdir -p "${UNIT_DIR}/coreos-root-setup.service.d"
cat > "${UNIT_DIR}/coreos-root-setup.service.d/10-live.conf" <<EOF
# With live PXE there's no ostree=/composefs= argument on the kernel command line, so
# we need to find the tree path and pass it to (ostree|bootc)-prepare-root. But
# they only knows how to read the path from /proc/cmdline, so we need to synthesize
# the proper karg and bind-mount it over /proc/cmdline.
# https://github.com/ostreedev/ostree/issues/1920

[Unit]
Expand Down Expand Up @@ -210,8 +209,8 @@ RequiresMountsFor=/run/ephemeral
ConditionPathExists=/usr/lib/initrd-release
ConditionPathExists=!/run/ephemeral/var
# We want to run after ostree is set up
After=ostree-prepare-root.service
Requires=ostree-prepare-root.service
After=coreos-root-setup.service
Requires=coreos-root-setup.service

[Service]
Type=oneshot
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bootc-initramfs-setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[Unit]
Description=CoreOS Root Setup

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this is effectively a generic synchronization point between "ostree or composefs" right? I think we could just add this to bootc upstream as say bootc-root-setup.target - which then we ensure via a generator depends on the right service.

The bash code executed here is just reimplementing the upstream services which I think we don't want.

Documentation=man:bootc(1)
DefaultDependencies=no
ConditionKernelCommandLine=|composefs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally...we don't hardcode this because I'd like the ability to change it in the future. That already came up because e.g. not having a . makes the Linux kernel emit a warning i.e. I'd like to switch to composefs.digest or so.

But also, maybe we actually switch to key based mounting per composefs/composefs-rs#226

So...how about ConditionPathExists=|/sysroot/composefs ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So...how about ConditionPathExists=|/sysroot/composefs ?

This sounds good to me, but I don't know if systemd will OR this with the kernel cmdline condition. I'll need to check

ConditionKernelCommandLine=|ostree
ConditionPathExists=/etc/initrd-release
After=sysroot.mount
Requires=sysroot.mount
Before=initrd-root-fs.target

OnFailure=emergency.target
OnFailureJobMode=isolate

[Service]
Type=oneshot
ExecStart=/usr/libexec/coreos-root-setup
StandardInput=null
StandardOutput=journal
StandardError=journal+console
RemainAfterExit=yes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

have_karg() {
local arg="$1"
IFS=" " read -r -a cmdline <<< "$(</proc/cmdline)"
local i
for i in "${cmdline[@]}"; do
if [[ "$i" =~ "$arg=" ]]; then
return 0
fi
done
return 1
}

if have_karg composefs; then
/usr/lib/bootc/initramfs-setup setup-root
elif have_karg ostree; then
/usr/lib/ostree/ostree-prepare-root /sysroot
else
echo "Neither ostree nor composefs found in cmdline"
exit 1
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

check() {
return 0
}

depends() {
return 0
}

install() {
local service=coreos-root-setup.service

inst_script "$moddir/coreos-root-setup.sh" /usr/libexec/coreos-root-setup

inst "$moddir/bootc-initramfs-setup" /usr/lib/bootc/initramfs-setup

inst_simple "$moddir/${service}" "${systemdsystemunitdir}/${service}"
mkdir -p "${initdir}${systemdsystemconfdir}/initrd-root-fs.target.wants"
ln_r "${systemdsystemunitdir}/${service}" \
"${systemdsystemconfdir}/initrd-root-fs.target.wants/${service}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Unit]
Description=Boot Partition Discovery Complete
Documentation=man:systemd.special(7)
ConditionPathExists=/etc/initrd-release
# After=local-fs-pre.target
# Before=local-fs.target
Requires=boot-part-discovery.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Discover Boot Partition Availability
ConditionPathExists=/etc/initrd-release
Before=boot-part-discovered.target
After=local-fs-pre.target
Before=local-fs.target

[Service]
Type=oneshot
ExecStart=/usr/libexec/boot-part-discovery.sh
RemainAfterExit=yes
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

XBOOTLDR_UUID="BC13C2FF-59E6-4262-A352-B275FD6F7172"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it'd be nice to not write new load-bearing bash code run as root. In this case...can't the GPT auto generator mount this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't the GPT auto generator mount this?

Yes, it could, and would mount /boot if the partuuid follows DPS, which it does after my other PR. This was mainly supposed to be a sync target for a lot of other services that depend on a boot partition being present.

BOOT_STATUS_DIR="/run/coreos"
BOOT_STATUS_FILE="${BOOT_STATUS_DIR}/boot-partition-status"

boot_part_exists() {
LSBLK_JSON="$(lsblk -o name,parttype,uuid,mountpoint,parttypename,label --json)"

while read -r part; do
parttype="$(jq -r '.parttype // empty' <<<"$part" | tr '[:lower:]' '[:upper:]')"
name="$(jq -r '.name' <<<"$part")"

[[ -n "$parttype" ]] || echo "Partition '$name' has no parttype"

if [[ "$parttype" == "$XBOOTLDR_UUID" ]]; then
return 0
fi
done < <(echo "$LSBLK_JSON" | jq -c '.blockdevices[].children[]?')

return 1
}

# Only run when executed directly, not when sourced
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
if boot_part_exists; then
mkdir -p "$BOOT_STATUS_DIR"
echo "available" > "$BOOT_STATUS_FILE"
else
echo "Boot partition not found"
fi
fi
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
Description=Ignition OSTree: Check Root Filesystem Size
Documentation=https://docs.fedoraproject.org/en-US/fedora-coreos/storage/
DefaultDependencies=false
ConditionKernelCommandLine=ostree
ConditionKernelCommandLine=|ostree
ConditionKernelCommandLine=|composefs
ConditionPathExists=!/run/ostree-live
After=ignition-ostree-growfs.service
After=ostree-prepare-root.service
Requires=ostree-prepare-root.service
After=coreos-root-setup.service
Requires=coreos-root-setup.service
# Allow Ignition config to blank out the warning
Before=ignition-files.service

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[Unit]
Description=Ignition OSTree: Grow Root Filesystem
DefaultDependencies=false
ConditionKernelCommandLine=ostree
ConditionKernelCommandLine=|ostree

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I said something like this before in a different PR on this repo but I think this would be a good time to change our logic so that we don't depend on the specific kernel command line at all.

One way we could handle this is in the initramfs we introduce /run/bootc-requested which we synthesize from a generator (like /run/ostree-booted). I think this should only go into the initramfs (unlike the ostree one) because right now we have another way to detect composefs (look at the mount source for /) and anyways the post-boot code should largely be talking to bootc anyways.

This /run/bootc-requested is something we could again do in bootc upstream right now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed this in a 1-1 call. This is a good to have, but not a blocker for now

ConditionKernelCommandLine=|composefs
ConditionPathExists=!/run/ostree-live
Before=initrd-root-fs.target
Before=sysroot.mount
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[Unit]
Description=Mount OSTree /var
DefaultDependencies=false
# We do not need this for composefs
ConditionKernelCommandLine=ostree
ConditionPathExists=!/run/ostree-live

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Before=ignition-ostree-transposefs-restore.service
OnFailure=emergency.target
OnFailureJobMode=isolate

ConditionKernelCommandLine=ostree
ConditionKernelCommandLine=|ostree
ConditionKernelCommandLine=|composefs
# only run if ignition-ostree-growfs ran since that's when pathological cases occur
ConditionPathExists=/run/ignition-ostree-growfs.stamp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ After=ignition-fetch.service
Before=ignition-disks.service
Before=initrd-root-fs.target
Before=sysroot.mount
ConditionKernelCommandLine=ostree
ConditionKernelCommandLine=|ostree
ConditionKernelCommandLine=|composefs
OnFailure=emergency.target
OnFailureJobMode=isolate

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Before=sysroot.mount
OnFailure=emergency.target
OnFailureJobMode=isolate

ConditionKernelCommandLine=ostree
ConditionKernelCommandLine=|ostree
ConditionKernelCommandLine=|composefs
ConditionPathIsDirectory=/run/ignition-ostree-transposefs

[Service]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Description=Ignition OSTree: Save Partitions
DefaultDependencies=false
After=ignition-ostree-transposefs-detect.service
Before=ignition-disks.service
ConditionKernelCommandLine=ostree
ConditionKernelCommandLine=|ostree
ConditionKernelCommandLine=|composefs
ConditionPathIsDirectory=/run/ignition-ostree-transposefs
# Any services looking at mounts need to order after this
# because it causes device re-probing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,32 @@ case "${1:-}" in
if [ -d "${saved_root}" ]; then
echo "Restoring rootfs from RAM..."
mount_and_restore_filesystem_by_label root /sysroot "${saved_root}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussing this live:

For the sealed UKI case let's say we want to do the DPS. Then probably we should detect whether the disk has the DPS root UUID and if the bootloader set the BLI variable.

I think we could make this a clean distinct prep commit right? Basically "support DPS booting".

Questions:

  • Will we need to suppress the generator and redo what it's doing for the Ignition transposefs case? Though this relates to a systemd PR around optimizing the cryptsetup case when we don't need to reinitialize the partition table for the root at all.


chcon -v --reference "${saved_root}" /sysroot # the root of the fs itself
chattr +i $(ls -d /sysroot/ostree/deploy/*/deploy/*/)

cfs_digest=$(karg composefs)

if [[ "$cfs_digest" == "" ]]; then
chattr +i $(ls -d /sysroot/ostree/deploy/*/deploy/*/)
elif [[ ${cfs_digest:0:1} != "?" ]]; then
echo "Re-enabling fsverity on composefs repo..."
# tmpfs has no fsverity, so we need to reenable fsverity
hash_alg=""

if [[ $cfs_digest =~ ^[0-9a-fA-F]{64}$ ]]; then
hash_alg="sha256"
elif [[ $cfs_digest =~ ^[0-9a-fA-F]{128}$ ]]; then
hash_alg="sha512"
else
echo "Bad verity in cmdline '$cfs_digest'"
exit 1
fi

echo "Enabling fs-verity again..."
find /sysroot/composefs/objects -type f -exec fsverity enable {} --hash-alg $hash_alg \;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eeek. This is another thing exactly like ostreedev/ostree#3094

I think at a minimum we could put this in rust in the bootc initramfs setup like bootc-initramfs-setup post-copy /sysroot/composefs ?

Also note that once we have composefs/composefs-rs#268 then the tooling itself will immediately know the expected digest size just looking at the repo.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think at a minimum we could put this in rust in the bootc initramfs setup like bootc-initramfs-setup post-copy /sysroot/composefs ?

agreed. That would be much cleaner

And yes, repo metdata would help here

fi
fi

if [ -d "${saved_boot}" ]; then
echo "Restoring bootfs from RAM..."
mount_and_restore_filesystem_by_label boot /sysroot/boot "${saved_boot}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ Before=ignition-kargs.service
# If we're going to reprovision the bootfs, then there's no need to restamp
ConditionKernelCommandLine=!bootfs.roothash

# TODO(Johan-Lieber1): This
Before=systemd-fsck@dev-disk-by\x2dlabel-boot.service
Requires=dev-disk-by\x2dlabel-boot.device
After=dev-disk-by\x2dlabel-boot.device
# Requires=dev-disk-by\x2dlabel-boot.device
# After=dev-disk-by\x2dlabel-boot.device

# Make sure boot partition actually exists
After=boot-part-discovered.target
ConditionFileNotEmpty=/run/coreos/boot-partition-status

[Service]
Type=oneshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Description=Ignition OSTree: Regenerate Filesystem UUID (root)
# These conditions match those generated in coreos-diskful-generator
DefaultDependencies=false
ConditionKernelCommandLine=ostree
ConditionKernelCommandLine=|ostree
ConditionKernelCommandLine=|composefs
ConditionPathExists=!/run/ostree-live
Before=sysroot.mount initrd-root-fs.target
After=ignition-disks.service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ install() {
rm \
sed \
sfdisk \
find
find \
fsverity

# In some cases we had to vendor gdisk in Ignition.
# If this is the case here use that one.
Expand Down Expand Up @@ -121,5 +122,11 @@ install() {
inst_script "$moddir/ignition-ostree-mount-state-overlays.sh" \
/usr/libexec/ignition-ostree-mount-state-overlays

inst_simple "$moddir/boot-part-discovery.target" "$systemdsystemunitdir/boot-part-discovery.target"

install_ignition_unit boot-part-discovery.service
inst_script "$moddir/boot-part-discovery.sh" \
/usr/libexec/boot-part-discovery.sh

inst_script "$moddir/coreos-relabel" /usr/bin/coreos-relabel
}
Loading