Make CONFIG_DEVTMPFS_MOUNT apply to initramfs/initmpfs.
Subsystems (3)
PATCH 1/1 Make CONFIG_DEVTMPFS_MOUNT apply to initramfs/initmpfs.
From: Rob Landley <[email protected]>
Make CONFIG_DEVTMPFS_MOUNT apply to initramfs/initmpfs.
Update help text, slightly improve error reporting, move /dev/console open down after devtmpfs mount, don't check IS_ENABLED(CONFIG_TMPFS) before mounting devtmpfs (it's always there, even if just a ramfs alias), and report whether we think we're using tmpfs or ramfs for rootfs.
---
drivers/base/Kconfig | 10 ++++++---- drivers/base/devtmpfs.c | 3 ++- init/do_mounts.c | 7 +++---- init/main.c | 17 ++++++++++------- 4 files changed, 21 insertions(+), 16 deletions(-)
drivers/base/Kconfig +6 -4
@@ -45,16 +45,18 @@ config DEVTMPFS file system will be used instead. config DEVTMPFS_MOUNT - bool "Automount devtmpfs at /dev, after the kernel mounted the rootfs" + bool "Automount devtmpfs at /dev" depends on DEVTMPFS help This will instruct the kernel to automatically mount the devtmpfs filesystem at /dev, directly after the kernel has mounted the root filesystem. The behavior can be overridden with the commandline parameter: devtmpfs.mount=0|1. - This option does not affect initramfs based booting, here - the devtmpfs filesystem always needs to be mounted manually - after the rootfs is mounted. + + In an initramfs based system, this can create the /dev directory + as well. Other root filesystems require a /dev directory to exist + to act as a mount point. + With this option enabled, it allows to bring up a system in rescue mode with init=/bin/sh, even when the /dev directory on the rootfs is completely empty.
drivers/base/devtmpfs.c +2 -1
@@ -356,7 +356,8 @@ int devtmpfs_mount(const char *mntdir) err =sys_mount ("devtmpfs" , (char *)mntdir,"devtmpfs" ,MS_SILENT ,NULL );if (err) -printk (KERN_INFO "devtmpfs: error mounting %i\n" , err); +printk (KERN_ERR "devtmpfs: error %i mounting on %s\n" , + err, mntdir);else printk (KERN_INFO "devtmpfs: mounted\n" );return err;
init/do_mounts.c +3 -4
@@ -599,7 +599,6 @@ void __init prepare_namespace(void)mount_root (); out: -devtmpfs_mount ("dev" );sys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL );sys_chroot ("." ); }
@@ -614,8 +613,9 @@ static struct dentry *rootfs_mount(struct file_system_type *fs_type,if (test_and_set_bit (0 , &once))return ERR_PTR (-ENODEV ); -if (IS_ENABLED (CONFIG_TMPFS ) && is_tmpfs) +if (is_tmpfs) fill = shmem_fill_super; +printk (KERN_INFO "rootfs is %s\n" , is_tmpfs ?"tmpfs" :"ramfs" );return mount_nodev (fs_type, flags, data, fill); }
@@ -637,9 +637,8 @@ int __init init_rootfs(void) (!root_fs_names || strstr(root_fs_names, "tmpfs"))) { err =shmem_init (); is_tmpfs = true; - } else { + } else err =init_ramfs_fs (); - }if (err)unregister_filesystem (&rootfs_fs_type);
init/main.c +10 -7
@@ -1007,12 +1007,6 @@ static noinline void __init kernel_init_freeable(void)do_basic_setup (); -/* Open the /dev/console on the rootfs, this should never fail */ -if (sys_open ((const char __user *)"/dev/console" ,O_RDWR ,0 ) <0 ) -pr_err ("Warning: unable to open an initial console.\n" ); - - (void )sys_dup (0 ); - (void )sys_dup (0 );/* * check if there is an early userspace init. If yes, let it do all * the work
@@ -1024,7 +1018,16 @@ static noinline void __init kernel_init_freeable(void)if (sys_access ((const char __user *) ramdisk_execute_command,0 ) !=0 ) { ramdisk_execute_command =NULL ;prepare_namespace (); - } + }else if (config_enabled (CONFIG_DEVTMPFS_MOUNT )) +sys_mkdir ("/dev" ,0755 ); +devtmpfs_mount ("dev" ); + +/* Open the /dev/console on the rootfs, this should never fail */ +if (sys_open ((const char __user *)"/dev/console" ,O_RDWR ,0 ) <0 ) +pr_err ("Warning: unable to open an initial console.\n" ); + + (void )sys_dup (0 ); + (void )sys_dup (0 );/* * Ok, we have completed the initial bootup, and
Greg KH
maintainerQuoted 8 lines · Rob Landley
From: Rob Landley <[email protected]>
Make
CONFIG_DEVTMPFS_MOUNTapply to initramfs/initmpfs.Update help text, slightly improve error reporting, move
/dev/consoleopen down after devtmpfs mount, don't checkIS_ENABLED(CONFIG_TMPFS)before mounting devtmpfs (it's always there, even if just a ramfs alias), and report whether we think we're using tmpfs or ramfs for rootfs.
That's a lot of different things to be doing all at once in the same patch. Can you please break these out into individual logical changes?
thanks,
greg k-h
Rich Felker
maintainerQuoted 10 lines · Rob Landley
From: Rob Landley <[email protected]>
Make
CONFIG_DEVTMPFS_MOUNTapply to initramfs/initmpfs.Update help text, slightly improve error reporting, move
/dev/consoleopen down after devtmpfs mount, don't checkIS_ENABLED(CONFIG_TMPFS)before mounting devtmpfs (it's always there, even if just a ramfs alias), and report whether we think we're using tmpfs or ramfs for rootfs.Signed-off-by Rob Landley <[email protected]>
Comments below:
Quoted 40 lines
---
drivers/base/Kconfig | 10 ++++++---- drivers/base/devtmpfs.c | 3 ++- init/do_mounts.c | 7 +++---- init/main.c | 17 ++++++++++------- 4 files changed, 21 insertions(+), 16 deletions(-)drivers/base/Kconfig +6
-4@@ -45,16 +45,18 @@ config DEVTMPFS file system will be used instead. config DEVTMPFS_MOUNT - bool "Automount devtmpfs at /dev, after the kernel mounted the rootfs" + bool "Automount devtmpfs at /dev" depends on DEVTMPFS help This will instruct the kernel to automatically mount the devtmpfs filesystem at /dev, directly after the kernel has mounted the root filesystem. The behavior can be overridden with the commandline parameter: devtmpfs.mount=0|1. - This option does not affect initramfs based booting, here - the devtmpfs filesystem always needs to be mounted manually - after the rootfs is mounted. + + In an initramfs based system, this can create the /dev directory + as well. Other root filesystems require a /dev directory to exist + to act as a mount point. + With this option enabled, it allows to bring up a system in rescue mode with init=/bin/sh, even when the /dev directory on the rootfs is completely empty.drivers/base/devtmpfs.c +0
-0
drivers/base/devtmpfs.c int devtmpfs_mount(const char *mntdir) · line 360
Quoted 6 lines
drivers/base/devtmpfs.c +2
-1@@ -356,7 +356,8 @@ int devtmpfs_mount(const char *mntdir) err =sys_mount ("devtmpfs" , (char *)mntdir,"devtmpfs" ,MS_SILENT ,NULL );if (err) -printk (KERN_INFO "devtmpfs: error mounting %i\n" , err); +printk (KERN_ERR "devtmpfs: error %i mounting on %s\n" , + err, mntdir);
Could stand on its own as:
"Fix loglevel for devtmpfs mounting error message."
Quoted 16 lines
drivers/base/devtmpfs.c +0
-0else printk (KERN_INFO "devtmpfs: mounted\n" );return err;init/do_mounts.c +0
-1@@ -599,7 +599,6 @@ void __init prepare_namespace(void)mount_root (); out: -devtmpfs_mount ("dev" );sys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL );sys_chroot ("." ); }
init/do_mounts.c static struct dentry *rootfs_mount(struct file_system_type *fs_type, · line 617
Quoted 6 lines
init/do_mounts.c +1
-1@@ -614,8 +613,9 @@ static struct dentry *rootfs_mount(struct file_system_type *fs_type,if (test_and_set_bit (0 , &once))return ERR_PTR (-ENODEV ); -if (IS_ENABLED (CONFIG_TMPFS ) && is_tmpfs) +if (is_tmpfs) fill = shmem_fill_super;
Perhaps independent, as:
"Fix incorrect use of CONFIG_TMPFS"?
Can you describe the problem this change is fixing? I believe it's correct (since tmpfs exists with or without CONFIG_TMPFS, and CONFIG_TMPFS is always disabled for nommu) but it would be nice to understand the motivation.
init/do_mounts.c int __init init_rootfs(void) · line 642
Quoted 12 lines
init/do_mounts.c +2
-2+printk (KERN_INFO "rootfs is %s\n" , is_tmpfs ?"tmpfs" :"ramfs" );return mount_nodev (fs_type, flags, data, fill); }@@ -637,9 +637,8 @@ int __init init_rootfs(void) (!root_fs_names || strstr(root_fs_names, "tmpfs"))) { err =shmem_init (); is_tmpfs = true; - } else { + } else err =init_ramfs_fs (); - }
This is gratuitous and could be dropped.
Quoted 20 lines
init/do_mounts.c +0
-0if (err)unregister_filesystem (&rootfs_fs_type);init/main.c +0
-6@@ -1007,12 +1007,6 @@ static noinline void __init kernel_init_freeable(void)do_basic_setup (); -/* Open the /dev/console on the rootfs, this should never fail */ -if (sys_open ((const char __user *)"/dev/console" ,O_RDWR ,0 ) <0 ) -pr_err ("Warning: unable to open an initial console.\n" ); - - (void )sys_dup (0 ); - (void )sys_dup (0 );/* * check if there is an early userspace init. If yes, let it do all * the work
init/main.c static noinline void __init kernel_init_freeable(void) · line 1022
Quoted 6 lines
init/main.c +2
-1@@ -1024,7 +1018,16 @@ static noinline void __init kernel_init_freeable(void)if (sys_access ((const char __user *) ramdisk_execute_command,0 ) !=0 ) { ramdisk_execute_command =NULL ;prepare_namespace (); - } + }else if (config_enabled (CONFIG_DEVTMPFS_MOUNT )) +sys_mkdir ("/dev" ,0755 );
This could probably be a separate change or even omitted. There's no reason the dir entry can't be in the initramfs cpio archive. (On the other hand there _are_ good reasons not to put device nodes in the cpio archive.)
init/main.c static noinline void __init kernel_init_freeable(void) · line 1030
Quoted 8 lines
init/main.c +8
-0+devtmpfs_mount ("dev" ); + +/* Open the /dev/console on the rootfs, this should never fail */ +if (sys_open ((const char __user *)"/dev/console" ,O_RDWR ,0 ) <0 ) +pr_err ("Warning: unable to open an initial console.\n" ); + + (void )sys_dup (0 ); + (void )sys_dup (0 );
Moving this breaks use of a ramdisk_execute_command (see above) -- it runs with no stdin/out/err. It would probably be preferable to leave the console opening where it is, but find some way to open the console device directly without the need for an actual device node in the filesystem.
Rich