Skip to content

Commit

Permalink
init/initramfs: Add dump_initrd command line option
Browse files Browse the repository at this point in the history
Add a dump_initrd option to allow dumping /initrd.image after successful
unpack.

Require BLK_DEV_RAM=y.

Change-Id: I77a41867afa7b4a51604a5153792a49efbab6189
Signed-off-by: Jeffy Chen <[email protected]>
  • Loading branch information
JeffyCN authored and rkhuangtao committed Dec 18, 2018
1 parent b41c3c7 commit ff12055
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions init/initramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,17 @@ static int __init retain_initrd_param(char *str)
}
__setup("retain_initrd", retain_initrd_param);

static int __initdata do_dump_initrd;

static int __init dump_initrd_param(char *str)
{
if (*str)
return 0;
do_dump_initrd = 1;
return 1;
}
__setup("dump_initrd", dump_initrd_param);

extern char __initramfs_start[];
extern unsigned long __initramfs_size;
#include <linux/initrd.h>
Expand Down Expand Up @@ -642,6 +653,9 @@ static int __init populate_rootfs(void)
err = unpack_to_rootfs((char *)initrd_start,
initrd_end - initrd_start);
if (!err) {
if (do_dump_initrd)
goto dump;

free_initrd();
goto done;
} else {
Expand All @@ -650,6 +664,7 @@ static int __init populate_rootfs(void)
}
printk(KERN_INFO "rootfs image is not initramfs (%s)"
"; looks like an initrd\n", err);
dump:
fd = sys_open("/initrd.image",
O_WRONLY|O_CREAT, 0700);
if (fd >= 0) {
Expand Down

0 comments on commit ff12055

Please sign in to comment.