init: Introduce 'noinitramfs' kernel parameter
diff mbox series

Message ID 1403415685-21455-1-git-send-email-ezequiel@vanguardiasur.com.ar
State New, archived
Headers show
Series
  • init: Introduce 'noinitramfs' kernel parameter
Related show

Commit Message

Ezequiel Garcia June 22, 2014, 5:41 a.m. UTC
Currently, we have no kernel paramater to avoid loading a configured initial
RAM filesystem. Therefore, if a kernel is built with an appended initramfs,
there's no way to avoid unpacking and mounting it as the rootfs.

This commit adds a new kernel parameter to provide such option, following the
naming of the current 'initrd' which serves a similar purpose, for an initial
RAM disk.

This commit changes the build so noinitramfs.c is unconditionally included.
If the new 'noinitramfs' option is passed in the command line, the kernel
avoids unpacking an initramfs and calls default_rootfs().

Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
---
 Documentation/kernel-parameters.txt |  4 ++++
 include/linux/initrd.h              |  2 ++
 init/Makefile                       |  3 ---
 init/initramfs.c                    | 14 +++++++++++++-
 init/noinitramfs.c                  |  4 +++-
 5 files changed, 22 insertions(+), 5 deletions(-)

Comments

Henrique de Moraes Holschuh June 22, 2014, 2:53 p.m. UTC | #1
On Sun, 22 Jun 2014, Ezequiel Garcia wrote:
> This commit adds a new kernel parameter to provide such option, following the
> naming of the current 'initrd' which serves a similar purpose, for an initial
> RAM disk.

How does it interact with the early initramfs?

Maybe we should have the options to ignore both, ignore just the early
initramfs (to skip microcode updates and ACPI table updates), and ignore
just the main initramfs?
Ezequiel Garcia June 22, 2014, 9:30 p.m. UTC | #2
Hi Henrique,

On 22 Jun 11:53 AM, Henrique de Moraes Holschuh wrote:
> On Sun, 22 Jun 2014, Ezequiel Garcia wrote:
> > This commit adds a new kernel parameter to provide such option, following the
> > naming of the current 'initrd' which serves a similar purpose, for an initial
> > RAM disk.
> 
> How does it interact with the early initramfs?
> 
> Maybe we should have the options to ignore both, ignore just the early
> initramfs (to skip microcode updates and ACPI table updates), and ignore
> just the main initramfs?
> 

I must admit I don't have much experience with any "earlier" initramfs.
Maybe you can point me at some links about this?

Unless I'm missing something, this "early" initramfs is an userspace artifact
in the construction of the initramfs, so the kernel has no way to distinguish
one from the other. Thus, we cannot mount one and not the other.
Henrique de Moraes Holschuh June 23, 2014, 12:08 a.m. UTC | #3
On Sun, 22 Jun 2014, Ezequiel Garcia wrote:
> On 22 Jun 11:53 AM, Henrique de Moraes Holschuh wrote:
> > On Sun, 22 Jun 2014, Ezequiel Garcia wrote:
> > > This commit adds a new kernel parameter to provide such option, following the
> > > naming of the current 'initrd' which serves a similar purpose, for an initial
> > > RAM disk.
> > 
> > How does it interact with the early initramfs?
> > 
> > Maybe we should have the options to ignore both, ignore just the early
> > initramfs (to skip microcode updates and ACPI table updates), and ignore
> > just the main initramfs?
> > 
> 
> I must admit I don't have much experience with any "earlier" initramfs.
> Maybe you can point me at some links about this?

Search for kernel code that includes the linux/earlycpio.h header file.  The
implementation is at lib/earlycpio.c.

I am sorry I don't have a better reference to point you to.

> Unless I'm missing something, this "early" initramfs is an userspace artifact
> in the construction of the initramfs, so the kernel has no way to distinguish

No, it is an uncompressed cpio archive which is parsed extremely early, for
critical system firmware (currently: processor microcode updates and ACPI
table overrides).

Documentation of its two current users is at:

Documentation/x86/early-microcode.txt
Documentation/acpi/initrd_table_override.txt

Patch
diff mbox series

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 8849049..a8cb75e 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -102,6 +102,7 @@  parameter is applicable:
 	PPT	Parallel port support is enabled.
 	PS2	Appropriate PS/2 support is enabled.
 	RAM	RAM disk support is enabled.
+	RAMFS	Initial RAM filesystem support is enabled.
 	S390	S390 architecture is enabled.
 	SCSI	Appropriate SCSI support is enabled.
 			A lot of drivers have their options described inside
@@ -2211,6 +2212,9 @@  bytes respectively. Such letter suffixes can also be entirely omitted.
 
 	noisapnp	[ISAPNP] Disables ISA PnP code.
 
+	noinitramfs	[RAMFS] Tells the kernel not to load any configured
+			initial RAM filesystem.
+
 	noinitrd	[RAM] Tells the kernel not to load any configured
 			initial RAM disk.
 
diff --git a/include/linux/initrd.h b/include/linux/initrd.h
index 55289d2..f627ce6 100644
--- a/include/linux/initrd.h
+++ b/include/linux/initrd.h
@@ -17,4 +17,6 @@  extern int initrd_below_start_ok;
 extern unsigned long initrd_start, initrd_end;
 extern void free_initrd_mem(unsigned long, unsigned long);
 
+extern int default_rootfs(void);
+
 extern unsigned int real_root_dev;
diff --git a/init/Makefile b/init/Makefile
index 7bc47ee..692b91f 100644
--- a/init/Makefile
+++ b/init/Makefile
@@ -3,11 +3,8 @@ 
 #
 
 obj-y                          := main.o version.o mounts.o
-ifneq ($(CONFIG_BLK_DEV_INITRD),y)
 obj-y                          += noinitramfs.o
-else
 obj-$(CONFIG_BLK_DEV_INITRD)   += initramfs.o
-endif
 obj-$(CONFIG_GENERIC_CALIBRATE_DELAY) += calibrate.o
 
 ifneq ($(CONFIG_ARCH_INIT_TASK),y)
diff --git a/init/initramfs.c b/init/initramfs.c
index a8497fa..cae8cee 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -580,9 +580,21 @@  static void __init clean_rootfs(void)
 }
 #endif
 
+static int __initdata skip_initramfs;
+static int __init noinitramfs_param(char *str)
+{
+	skip_initramfs = 1;
+	return 1;
+}
+__setup("noinitramfs", noinitramfs_param);
+
 static int __init populate_rootfs(void)
 {
-	char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
+	char *err;
+
+	if (skip_initramfs)
+		return default_rootfs();
+	err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
 	if (err)
 		panic("%s", err); /* Failed to decompress INTERNAL initramfs */
 	if (initrd_start) {
diff --git a/init/noinitramfs.c b/init/noinitramfs.c
index 267739d..e7e828a 100644
--- a/init/noinitramfs.c
+++ b/init/noinitramfs.c
@@ -25,7 +25,7 @@ 
 /*
  * Create a simple rootfs that is similar to the default initramfs
  */
-static int __init default_rootfs(void)
+int __init default_rootfs(void)
 {
 	int err;
 
@@ -49,4 +49,6 @@  out:
 	printk(KERN_WARNING "Failed to create a rootfs\n");
 	return err;
 }
+#ifndef CONFIG_BLK_DEV_INITRD
 rootfs_initcall(default_rootfs);
+#endif