-
Notifications
You must be signed in to change notification settings - Fork 158
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
Add general ignition-ostree module with rootfs replacement #184
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
overlay.d/05core/usr/lib/dracut/modules.d/40ignition-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,46 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
rootdisk=/dev/disk/by-label/root | ||
rootmnt=/sysroot | ||
tmproot=/run/ignition-ostree-rootfs | ||
saved_rootmnt=${tmproot}/orig-sysroot | ||
memdev=/dev/ram0 | ||
|
||
# Note that save & restore run in private mount namespaces, hence why we don't | ||
# bother unmounting things here. | ||
|
||
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. | ||
wipes_rootfs=$(jq '.storage?.filesystems? // [] | map(select(.label == "root" and .wipeFilesystem == true)) | length' < /run/ignition.json) | ||
if [ "${wipes_rootfs}" = "0" ]; then | ||
exit 0 | ||
fi | ||
echo "Detected rootfs replacement in fetched Ignition config: /run/ignition.json" | ||
mkdir "${tmproot}" | ||
;; | ||
save) | ||
size=$(lsblk -bn -o SIZE "${rootdisk}") | ||
sizekbs="$(($size / 1024 + 1))" | ||
modprobe --first-time brd rd_nr=1 rd_size="$sizekbs" max_part=1 | ||
echo "Moving rootfs to RAM..." | ||
dd "if=${rootdisk}" "of=${memdev}" bs=8M | ||
echo "Moved rootfs to RAM, pending redeployment: ${memdev}" | ||
;; | ||
restore) | ||
mount "$rootdisk" $rootmnt | ||
echo "Restoring rootfs from RAM..." | ||
mkdir "${saved_rootmnt}" | ||
mount "${memdev}" "${saved_rootmnt}" | ||
rsync -aXHA "${saved_rootmnt}/" "${rootmnt}" | ||
umount $saved_rootmnt | ||
rmmod brd | ||
rm -rf "${tmproot}" | ||
;; | ||
*) | ||
echo "Unsupported operation: ${1:-}" 1>&2; exit 1 | ||
;; | ||
esac |
18 changes: 18 additions & 0 deletions
18
...d/05core/usr/lib/dracut/modules.d/40ignition-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 |
17 changes: 17 additions & 0 deletions
17
.../05core/usr/lib/dracut/modules.d/40ignition-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,17 @@ | ||
[Unit] | ||
Description=Ignition OSTree: restore rootfs | ||
DefaultDependencies=false | ||
After=ignition-disks.service | ||
Before=ignition-ostree-growfs.service | ||
Before=ignition-ostree-mount-firstboot-sysroot.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 restore |
15 changes: 15 additions & 0 deletions
15
...y.d/05core/usr/lib/dracut/modules.d/40ignition-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 |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside: I am still leaning towards "rootfs reprovisioning must add a root= kernel argument" (UUID is a sane default, but it doesn't have to be that). That way we avoid all races with changing the meaning of
/dev/disk/by-label/root
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think I agree with this. I feel like we should spend some time to write up some of the complex root device options we want to support (e.g. at least starting with multipath, RAID, and LUKS) and see how it fits into one cohesive picture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done in #503.