Compiled kernel asks for rootfs; is it possible to mount it manually?

milk_cool

New Member
Joined
Nov 25, 2023
Messages
1
Reaction score
0
Credits
13
Hello everyone,

I am making a custom Linux distribution and I want to mount the rootfs manually using an executable from initramfs and then load into a shell from that rootfs. However, it seems like there's no such option in the kernel configuration tool. Is it possible to do that?

Current kernel configuration

Current grub.cfg
 


To be clearer about what is being discussed here, this is the proposed menuentry for the current grub.cfg from the pastebin:
Code:
default=0
timeout=5
 
menuentry 'znix' {
        insmod gzio
        insmod part_gpt
        echo 'Loading znix kernel'
        linux /boot/bzImage init=/bin/init acpi=off
        echo 'Loading initramfs'
        initrd /boot/initramfs.cpio.gz
}

Here are some thoughts.

Traditionally init is run from /sbin/init, not /bin/init, though in modern merged filesystems of these executable directories, it's /usr/sbin and /usr/bin. That's not to say that one can't make peculiar changes to conventions, but what would be the point?

/usr/sbin/init in modern systemd systems is a link to /lib/systemd/systemd. In SysVinit systems, init is configured in /etc/inittab which determines the runlevel to start the system which starts up a number of programs from scripts usually in the subdirectories of /etc/rc.d. Which init system is being proposed here?

If the system is to start with a manual mounting of the rootfs, then one can use the kernel option /bin/sh, which will start a root shell on boot, but won't load the initramfs. Rather, /bin/sh, with a rw option, can run from the rootfs and use the programs in place there. This approach is usually used when the user wants to get access to the system to correct something like changing a password or altering a config file.

If the kernel configuration puts all the relevant modules for the system inside itself, the initramfs can be omitted altogether.

If it's of interest, inside the initramfs on this machine, running debian, the init command is actually just "init" with /usr/sbin/init being empty.
Code:
lsinitramfs -l /boot/initrd.img-6.5.0-4-amd64 | grep init

-rw-r--r--   1 root     root         1583 Jun 21  2022 conf/initramfs.conf
-rwxr-xr-x   1 root     root         6556 Apr 11  2022 init
drwxr-xr-x   2 root     root            0 Nov 19 11:43 scripts/init-bottom
-rw-r--r--   1 root     root           77 Nov 19 11:43 scripts/init-bottom/ORDER
-rwxr-xr-x   1 root     root          611 Sep 21 00:44 scripts/init-bottom/udev
drwxr-xr-x   2 root     root            0 Nov 19 11:43 scripts/init-top
-rw-r--r--   1 root     root          314 Nov 19 11:43 scripts/init-top/ORDER
-rwxr-xr-x   1 root     root          396 Apr 11  2022 scripts/init-top/all_generic_ide
-rwxr-xr-x   1 root     root          296 Sep  1  2020 scripts/init-top/blacklist
-rwxr-xr-x   1 root     root          167 Sep  1  2020 scripts/init-top/keymap
-rwxr-xr-x   1 root     root          568 Sep 21 00:44 scripts/init-top/udev
-rw-r--r--   1 root     root         2048 Jul  5 00:44 usr/lib/firmware/ene-ub6250/ms_init.bin
-rw-r--r--   1 root     root         2048 Jul  5 00:44 usr/lib/firmware/ene-ub6250/sd_init1.bin
-rw-r--r--   1 root     root         2048 Jul  5 00:44 usr/lib/firmware/ene-ub6250/sd_init2.bin
-rw-r--r--   1 root     root        68331 Nov  3 15:15 usr/lib/modules/6.5.0-4-amd64/kernel/drivers/scsi/initio.ko
-rwxr-xr-x 257 root     root            0 Oct  7 03:07 usr/sbin/run-init
-rwxr-xr-x 257 root     root            0 Oct  7 03:07 usr/sbin/init

Rob Landley is a wiz on these matters, e.g. https://www.landley.net/writing/rootfs-howto.html, so it may be worth following up his articles from his sites and in the kernel docs.
 
Last edited:
wrong answer, I am sorry
Perhaps you misread the post. It clearly mentioned it was only "some thoughts", and was able to point to more elaborating references. :)

The OP ticked a like, so perhaps there was something useful in it. Thanks milk_cool.
 
Last edited:
No, he's not contradicting you mate, he put in an answer and then edited it, but his current text confuses.

Cheers
Wiz
 

Members online


Latest posts

Top