-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
Deterministic initramfs #21273
Deterministic initramfs #21273
Conversation
@joachifm, thanks for your PR! By analyzing the history of the files in this pull request, we identified @abbradar, @edolstra and @alexanderkjeldaas to be potential reviewers. |
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.
Not sure what the Perl change does, so can't review it.
@@ -39,7 +39,7 @@ mkdir -p $out | |||
for PREP in $prepend; do | |||
cat $PREP >> $out/initrd | |||
done | |||
(cd root && find * -print0 | cpio -o -H newc -R 0:0 --null | perl $cpioClean | $compressor >> $out/initrd) | |||
(cd root && find * -print0 | sort -z | cpio -o -H newc -R 0.0 --null | perl $cpioClean | $compressor > $out/initrd) |
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.
Why is >>
changed to >
here? Also, why change :
to .
(though this shouldn't change semantics)? BTW, from cpio
documentation:
To avoid the lookup and ensure that arguments are treated as numeric values, prefix them with a plus
sign, e.g.: -R +0:+0.
Can't hurt either.
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.
Thanks. I failed to notice those minute differences while squashing; I'll ensure that the squashed version is in line with the modern code.
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.
Actually the change from >>
to >
would break the prepend stuff. Nice catch!
Seems good to me now! I also vaguely get what does the Perl code do now -- seems OK for my limited understanding. Personally I'm glad we finally started to work on merging this big PR, at least parts -- thanks! EDIT: ninja'd you -- your description matches mine thoughts. |
@abbradar as far as I can tell, the change to clean-cpio is to make explicit that entries are assigned sequential inode numbers based on input order and not taking into account hardlinking at all. If |
Then again #2281 (comment) mentions boot problems due to inode reassignment. Hrm, I can't see any addendum to that comment (but the thread is large, so I might be missing something). |
Nevermind, I think I simply misunderstood the linked comment. |
This comment is bad news, either we need to ask @alexanderkjeldaas what boot problems did he have with that patch, or do extensive testing by ourselves. I'm willing to volunteer and cherry-pick it later when I have time, but maybe you need some complex initrd to bump into those problems. From your description I'm not sure what would "having hardlinks have different inode numbers" mean in CPIO. If those were files, that would mean you have essentially made a copy (if I'm incorrect, please point that out!). Would it work that way here automatically, just by changing inode number in some map? I'm pointing to that because if there are indeed problems maybe it has something to do with them. (to the new comment) Why do you think you have misunderstood it? It seems to mean boot problems with this patch to me. |
Regarding inode numbers, https://github.com/libarchive/libarchive/wiki/ManPageCpio5 says
Thus, setting different It also says
My reading of that is that the only difference is in the archive header, not the actual payload. (In the description of the new ascii header format it says hardlinked files are handled by setting the filesize to 0; I assume they're referring to the filesize header field and that the actual files themselves are still included as before). (EDIT: ofc, seeing as we're creating files using the new ascii header format, it seems like messing with inos to avoid stuff being marked as hardlinks would be the wrong way to go about it, but then I guess that's not the primary purpose of the remapping). |
Anyway, I think it's prudent to hold off on this until somebody gives a proper explanation. |
The I might remember wrong, but I think I first tried setting So the question is just whether having a slightly invalid cpio file with I don't remember exactly at which point I had boot issues, and whether they were exactly related to this issue. |
No, this line: only allocates a new inode number if none has been allocated for That's the idea, at least. |
@alexanderkjeldaas Thank you for your answers! Between this and re-reading the code again after a fresh sleep this seems pretty safe to me. |
@alexanderkjeldaas cool, but just so I can understand better: is it just about sequential numbering? I figured it had to do with hardlinking due to the mention of nlink. How does nlink figure into it? |
Have you tried |
|
1fa4957
to
2f726ab
Compare
Anyway, I've cleaned up the commits, so if we're happy with this, it should be ready to go. |
@alexanderkjeldaas the original commit message said "Do not set nlink when cleaning cpio archives", I assumed it referred to the |
Ok, so I probably set that as well, and I'm guessing it was unneeded (it
shouldn't be needed if the `ino` renumbering deals with hardlinks).
I think this might have been a squashed commit.
…On Mon, Dec 19, 2016 at 11:31 PM, Joachim F. ***@***.***> wrote:
@alexanderkjeldaas <https://github.com/alexanderkjeldaas> the original
commit message said "Do not set nlink when cleaning cpio archives", I
assumed it referred to the nlink field.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#21273 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAUtqQEKztz2HouPv90zRLvfaCPgq0bUks5rJwXbgaJpZM4LQQUM>
.
|
Taken from NixOS@1462666 This allows ```sh nix-build nixos --check --arg configuration '{ ... }: { }' -A config.system.build.initialRamdisk ``` to succeed. Note that `cpio --reproducible` (which implies `--renumber-inodes`) in combination with the previous version of `cpio-clean.pl` also makes the build deterministic, but `--reproducible` by itself appears insufficient. Thus we might as well do the renumbering in perl.
joachifm: the original commits were NixOS@4156801 NixOS@3d28eb3 I squashed them together and updated the commit message. Note that it appears that it is not strictly necessary to sort the files for `nix-build --check` to succeed, but it can't hurt either.
2f726ab
to
97c4437
Compare
@alexanderkjeldaas thank you for clearing that up for me; I interpreted the message to mean that renumbering somehow indirectly affected nlink, hence my confusion :) I have amended the commit message accordingly. |
I guess the remaining part besides
Stolen from https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=845034. |
@dezgeg cool, perhaps you'd care to commit something to that effect, then this PR could be closed in deference to it. |
To achieve reproducible results, `cpio` archive members are added in sorted order and inodes renumbered. The `cpio-clean.pl` script is made obsolete by setting mtimes via `touch` & using `cpio --reproducible`. Suggested by @dezgeg in NixOS#21273 (comment). Note that using `--reproducible` means that initial ramdisk creation now requires at least `cpio` version 2.12 (released in 2015).
@dezgeg I took the liberty of implementing your proposal in a different PR; I'll merge that one instead of this. Hope that's okay, if not feel free to commit your own version :) |
To achieve reproducible results, `cpio` archive members are added in sorted order and inodes renumbered. The `cpio-clean.pl` script is made obsolete by setting mtimes via `touch` & using `cpio --reproducible`. Suggested by @dezgeg in #21273 (comment). Note that using `--reproducible` means that initial ramdisk creation now requires at least `cpio` version 2.12 (released in 2015).
Extracted from #2281, some details in commit messages.