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

30ignition-coreos: Add coreos-boot-edit.{service,sh} #743

Merged
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
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 @@ -26,10 +27,9 @@ if [ -n "$(ls -A ${initramfs_firstboot_network_dir} 2>/dev/null)" ]; then
echo "info: copying files from ${initramfs_firstboot_network_dir} to ${initramfs_network_dir}"
mkdir -p ${initramfs_network_dir}
cp -v ${initramfs_firstboot_network_dir}/* ${initramfs_network_dir}/
# If we make it to the realroot (successfully ran ignition) then
# clean up the files in the firstboot network dir
echo "R ${realroot_firstboot_network_dir} - - - - -" > \
/run/tmpfiles.d/15-coreos-firstboot-network.conf
# Drop stamp file in /run to indicate that there are firstboot networking
# configuration files in /boot that should be cleaned up after Ignition.
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
Comment on lines +11 to +13
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that's needed with After=ignition-files.service. But this probably does not hurt either.

# 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"
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this should probably be /usr/libexec instead, but not worth a respin! :)

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

}