Skip to content

Commit

Permalink
30ignition-coreos: Add coreos-boot-edit.{service,sh}
Browse files Browse the repository at this point in the history
`coreos-boot-edit.service` will run late in the initrd process after
Ignition is completed successfully and temporarily mount /boot read-only
to make edits in /boot (e.g. removing firstboot networking configuration
files if necessary).
  • Loading branch information
kelvinfan001 committed Nov 19, 2020
1 parent 9df08be commit 7e684bf
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This unit will run late in the initrd process after Ignition is completed
# successfully and temporarily mount /boot read-only to make edits in /boot
# (e.g. removing firstboot networking configuration files if necessary).

[Unit]
Description=CoreOS Boot Edit
ConditionPathExists=/usr/lib/initrd-release
ConditionPathExists=/run/coreos-copy-firstboot-network.stamp
OnFailure=emergency.target
OnFailureJobMode=isolate

# Since we are mounting /boot, require the device first
Requires=dev-disk-by\x2dlabel-boot.device
After=dev-disk-by\x2dlabel-boot.device
# Start after Ignition has finished
After=ignition-files.service

[Service]
Type=oneshot
ExecStart=/usr/sbin/coreos-boot-edit
RemainAfterExit=yes
# MountFlags=slave is so the umount of /boot is guaranteed to happen.
# /boot will only be mounted for the lifetime of the unit.
MountFlags=slave
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -euo pipefail

# For a description of how this is used, see `coreos-boot-edit.service`.

# Clean up firstboot networking config files if the user copied them into the
# installed system (most likely by using `coreos-installer install --copy-network`).
bootmnt=/mnt/boot_partition
mkdir -p ${bootmnt}
bootdev=/dev/disk/by-label/boot
firstboot_network_dir_basename="coreos-firstboot-network"
initramfs_firstboot_network_dir="${bootmnt}/${firstboot_network_dir_basename}"

# Mount /boot. Note that we mount /boot but we don't unmount it because we
# are run in a systemd unit with MountFlags=slave so it is unmounted for us.
mount -o rw ${bootdev} ${bootmnt}

rm -vrf ${initramfs_firstboot_network_dir}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ install() {
# units only started when we have a boot disk
# path generated by systemd-escape --path /dev/disk/by-label/root
install_ignition_unit coreos-gpt-setup.service ignition-diskful.target

inst_script "$moddir/coreos-boot-edit.sh" \
"/usr/sbin/coreos-boot-edit"
# Only start when the system has disks since we are editing /boot.
install_ignition_unit "coreos-boot-edit.service" \
"ignition-diskful.target"

}

0 comments on commit 7e684bf

Please sign in to comment.