Skip to content

Commit

Permalink
initramfs: fix initramfs to work with hardlinked init
Browse files Browse the repository at this point in the history
Change cb6ff20 ("NOMMU: Support XIP on
initramfs") seems to have broken booting from initramfs with /sbin/init
being a hardlink.

It seems like the logic required for XIP on nommu, i.e.  ftruncate to
reported cpio header file size (body_len) is broken for hardlinks, which
have a reported size of 0, and the truncate thus nukes the contents of the
file (in my case busybox), making boot impossible and ending with runaway
loop modprobe binfmt-0000 - and of course 0000 is not a valid binary
format.

My fix is to only call ftruncate if size is non-zero which fixes things
for me, but I'm not certain whether this will break XIP for those files on
nommu systems, although I would guess not.

Signed-off-by: Randy Robertson <[email protected]>
Acked-by: David Howells <[email protected]>
Acked-by: Paul Mundt <[email protected]>
Acked-by: H. Peter Anvin <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Randy Robertson authored and torvalds committed Apr 13, 2009
1 parent f1671f6 commit d20d5a7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion init/initramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ static int __init do_name(void)
if (wfd >= 0) {
sys_fchown(wfd, uid, gid);
sys_fchmod(wfd, mode);
sys_ftruncate(wfd, body_len);
if (body_len)
sys_ftruncate(wfd, body_len);
vcollected = kstrdup(collected, GFP_KERNEL);
state = CopyFile;
}
Expand Down

0 comments on commit d20d5a7

Please sign in to comment.