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-write
to make edits in (e.g. removing firstboot networking configuration
files if necessary).
  • Loading branch information
kelvinfan001 committed Nov 23, 2020
1 parent 277f841 commit 993697e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ firstboot_network_dir_basename="coreos-firstboot-network"
initramfs_firstboot_network_dir="${bootmnt}/${firstboot_network_dir_basename}"
initramfs_network_dir="/run/NetworkManager/system-connections/"
realroot_firstboot_network_dir="/boot/${firstboot_network_dir_basename}"
copy_firstboot_network_stamp="/run/coreos-copy-firstboot-network.stamp"

# Mount /boot. Note that we mount /boot but we don't unmount boot because we
# are run in a systemd unit with MountFlags=slave so it is unmounted for us.
Expand All @@ -28,7 +29,7 @@ if [ -n "$(ls -A ${initramfs_firstboot_network_dir} 2>/dev/null)" ]; then
cp -v ${initramfs_firstboot_network_dir}/* ${initramfs_network_dir}/
# Drop stamp file in /run to indicate that there are firstboot networking
# configuration files in /boot that should be cleaned up after Ignition.
touch /run/coreos-copy-firstboot-network.stamp
touch ${copy_firstboot_network_stamp}
else
echo "info: no files to copy from ${initramfs_firstboot_network_dir}. skipping"
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This unit will run late in the initrd process after Ignition is completed
# successfully and temporarily mount /boot read-write to make edits
# (e.g. removing firstboot networking configuration files if necessary).

[Unit]
Description=CoreOS Boot Edit
ConditionPathExists=/usr/lib/initrd-release
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,22 @@
#!/bin/bash
set -euo pipefail

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

# 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.
bootmnt=/mnt/boot_partition
mkdir -p ${bootmnt}
bootdev=/dev/disk/by-label/boot
mount -o rw ${bootdev} ${bootmnt}

# Clean up firstboot networking config files if the user copied them into the
# installed system (most likely by using `coreos-installer install --copy-network`).
firstboot_network_dir_basename="coreos-firstboot-network"
initramfs_firstboot_network_dir="${bootmnt}/${firstboot_network_dir_basename}"
copy_firstboot_network_stamp="/run/coreos-copy-firstboot-network.stamp"
if [ -f ${copy_firstboot_network_stamp} ]; then
rm -vrf ${initramfs_firstboot_network_dir}
else
echo "info: no firstboot networking config files to clean from /boot. skipping"
fi
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 993697e

Please sign in to comment.