-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add general ignition-ostree module with rootfs replacement
Previously the `40coreos-var` module was "special /var handling for Ignition + OSTree". This new module takes over that, renaming it to `ignition-ostree`, and extends it with support for replacing the root filesystem.
- Loading branch information
Showing
10 changed files
with
145 additions
and
34 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
overlay.d/05core/usr/lib/dracut/modules.d/31ignition-ostree/ignition-ostree-dracut-rootfs.sh
This file contains 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,53 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
rootmnt=/sysroot | ||
tmproot=/run/ignition-ostree-rootfs | ||
|
||
case "${1:-}" in | ||
detect) | ||
# This is obviously crude; perhaps in the future we could change ignition's `fetch` | ||
# stage to write out a file if the rootfs is being replaced or so. But eh, it | ||
# works for now. | ||
has_rootfs=$(jq '.storage?.filesystems? // [] | map(select(.label == "root")) | length' < /run/ignition.json) | ||
if [ "${has_rootfs}" = "0" ]; then | ||
exit 0 | ||
fi | ||
echo "Detected rootfs replacement in fetched Ignition config: /run/ignition.json" | ||
mkdir "${tmproot}" | ||
;; | ||
save) | ||
# This one is in a private mount namespace since we're not "offically" mounting | ||
mount /dev/disk/by-label/root $rootmnt | ||
echo "Moving rootfs to RAM..." | ||
# OSTree added the immutable bit on the deployment root, and | ||
# cosa's create_disk added it to the rootfs | ||
chattr -i ${rootmnt} ${rootmnt}/ostree/deploy/*/deploy/*.0 | ||
for x in boot ostree; do | ||
# TODO; copy instead of mv to avoid writes, since we're just | ||
# about to blow away the whole FS anyways? | ||
mv -Tn ${rootmnt}/${x} ${tmproot}/${x} | ||
done | ||
umount ${rootmnt} | ||
echo "Moved rootfs to RAM, pending redeployment: ${tmproot}" | ||
;; | ||
restore) | ||
# This one is in a private mount namespace since we're not "offically" mounting | ||
mount /dev/disk/by-label/root $rootmnt | ||
if [ -d "${rootmnt}/boot" ] || [ -d "${rootmnt}/ostree" ]; then | ||
echo "ERROR: Detected Ignition rootfs replacement, but filesystem is not empty" 1>&2 | ||
exit 1 | ||
fi | ||
echo "Restoring rootfs from RAM..." | ||
for x in boot ostree; do | ||
mv -Tn ${tmproot}/${x} ${rootmnt}/${x} | ||
done | ||
# And restore the immutable bits | ||
chattr +i ${rootmnt}/ostree/deploy/*/deploy/*.0 ${rootmnt} | ||
echo "...done" | ||
umount $rootmnt | ||
;; | ||
*) | ||
echo "Unsupported operation: ${1:-}" | ||
;; | ||
esac |
This file contains 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
File renamed without changes.
This file contains 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
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
...d/05core/usr/lib/dracut/modules.d/31ignition-ostree/ignition-ostree-rootfs-detect.service
This file contains 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,18 @@ | ||
[Unit] | ||
Description=Ignition OSTree: detect rootfs replacement | ||
DefaultDependencies=false | ||
After=ignition-fetch.service | ||
Before=ignition-disks.service | ||
Before=initrd-root-fs.target | ||
Before=sysroot.mount | ||
ConditionKernelCommandLine=ostree | ||
|
||
# This stage requires udevd to detect disks | ||
Requires=systemd-udevd.service | ||
After=systemd-udevd.service | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
EnvironmentFile=/run/ignition.env | ||
ExecStart=/usr/libexec/ignition-ostree-dracut-rootfs detect |
16 changes: 16 additions & 0 deletions
16
.../05core/usr/lib/dracut/modules.d/31ignition-ostree/ignition-ostree-rootfs-restore.service
This file contains 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,16 @@ | ||
[Unit] | ||
Description=Ignition OSTree: restore rootfs | ||
DefaultDependencies=false | ||
After=ignition-disks.service | ||
Before=sysroot.mount | ||
|
||
ConditionKernelCommandLine=ostree | ||
ConditionPathIsDirectory=/run/ignition-ostree-rootfs | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
EnvironmentFile=/run/ignition.env | ||
# So we can transiently mount sysroot | ||
MountFlags=slave | ||
ExecStart=/usr/libexec/ignition-ostree-dracut-rootfs restore |
15 changes: 15 additions & 0 deletions
15
...y.d/05core/usr/lib/dracut/modules.d/31ignition-ostree/ignition-ostree-rootfs-save.service
This file contains 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,15 @@ | ||
[Unit] | ||
Description=Ignition OSTree: save rootfs | ||
DefaultDependencies=false | ||
After=ignition-ostree-rootfs-detect.service | ||
Before=ignition-disks.service | ||
ConditionKernelCommandLine=ostree | ||
ConditionPathIsDirectory=/run/ignition-ostree-rootfs | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
EnvironmentFile=/run/ignition.env | ||
# So we can transiently mount sysroot | ||
MountFlags=slave | ||
ExecStart=/usr/libexec/ignition-ostree-dracut-rootfs save |
36 changes: 36 additions & 0 deletions
36
overlay.d/05core/usr/lib/dracut/modules.d/31ignition-ostree/module-setup.sh
This file contains 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,36 @@ | ||
#!/bin/bash | ||
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- | ||
# ex: ts=8 sw=4 sts=4 et filetype=sh | ||
|
||
depends() { | ||
echo ignition ostree | ||
} | ||
|
||
install_ignition_unit() { | ||
unit=$1; shift | ||
inst_simple "$moddir/$unit" "$systemdsystemunitdir/$unit" | ||
ln_r "../$unit" "$systemdsystemunitdir/ignition-complete.target.requires/$unit" | ||
} | ||
|
||
install() { | ||
inst_multiple \ | ||
systemd-sysusers \ | ||
systemd-tmpfiles \ | ||
ostree tar chattr \ | ||
jq | ||
|
||
mkdir -p "$initdir/$systemdsystemunitdir/ignition-complete.target.requires" | ||
|
||
install_ignition_unit ignition-ostree-mount-var.service | ||
inst_script "$moddir/ignition-ostree-mount-var.sh" \ | ||
"/usr/sbin/ignition-ostree-mount-var" | ||
|
||
install_ignition_unit ignition-ostree-populate-var.service | ||
inst_script "$moddir/ignition-ostree-populate-var.sh" \ | ||
"/usr/sbin/ignition-ostree-populate-var" | ||
inst_script "$moddir/ignition-ostree-dracut-rootfs.sh" \ | ||
"/usr/libexec/ignition-ostree-dracut-rootfs" | ||
install_ignition_unit ignition-ostree-rootfs-detect.service | ||
install_ignition_unit ignition-ostree-rootfs-save.service | ||
install_ignition_unit ignition-ostree-rootfs-restore.service | ||
} |
29 changes: 0 additions & 29 deletions
29
overlay.d/05core/usr/lib/dracut/modules.d/40coreos-var/module-setup.sh
This file was deleted.
Oops, something went wrong.