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

mkosi-initrd: protect old initrd image against errors #3589

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aafeijoo-suse
Copy link
Contributor

When copy_tree() ends up calling cp, if it fails because there is not enough space, it leaves and incomplete initrd image in the output directory. If we are writing the initrd image directly where a bootloader entry has an initrd configured, the system will fail to boot. So, backup the old initrd image before calling copy_tree(), and restore it if that function throws an exception.

Copy link
Contributor

@DaanDeMeyer DaanDeMeyer left a comment

Choose a reason for hiding this comment

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

This is very messy., there's no guarantee we can put the backup back in place when copying the new one fails. We should copy the new initrd to a temporary file next to the initrd we're replacing and then use rename() to atomically replace the old one.

Copy link
Contributor

@behrmann behrmann left a comment

Choose a reason for hiding this comment

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

I agree with @DaanDeMeyer on how this should be implemented, but generally I do want to see this feature. I've had the exact thing this is supposed to prevent happen to me with dracut a few times. :)

@aafeijoo-suse
Copy link
Contributor Author

We should copy the new initrd to a temporary file next to the initrd we're replacing and then use rename() to atomically replace the old one.

With this approach we are always invalidating an amount of space equal to the initrd size, but ok, I see your point.

@aafeijoo-suse aafeijoo-suse force-pushed the initrd-backup-and-restore-on-error branch from f156f96 to 4f690b5 Compare March 13, 2025 14:24
When `copy_tree()` ends up calling `cp`, if it fails because there is not enough
space, it leaves an incomplete initrd image in the output directory. If we are
writing the initrd image directly where a bootloader entry has an initrd
configured, the system will fail to boot. So, instead of copying the initrd
image directly to the output, copy it next to it in the same output directory,
and if the copy is successful, replace it.
@aafeijoo-suse aafeijoo-suse force-pushed the initrd-backup-and-restore-on-error branch from 4f690b5 to c4a23ff Compare March 13, 2025 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants