0

I'm currently studying the boot process and composition of the different aspects of a GNU/Linux system and I can't rationaly explain this thing : you can write init inside an initramfs file as a shell script .

Init is supposed to be the first user-space process and the parent of all processes that are not spawned directly by the kernel . The PID of init is generally 1 which means it comes before everything else in the user space, and in that "everything" there should be your shell too .

#!/bin/sh

Now how things work when inside the init file I'm invoking a shell which is supposed to be a child process of the same process it is creating ?

2
2

A shell based rootfs switch is typically via exec switch_root because exec does not fork. Preserves the assumption of PID 1 is init.

This being Linux, of course that's far from the only way to do things. Each init system, indeed each distro, has their own packaging of initramfs. For example, systemd in initramfs.

5
  • if I understand this correctly : it runs inside the kernel memory space ? My scripts will basically have 100% access to all the "sensitive" areas inside the kernel . I'm assuming that kexec is also what lets systemd or sysvinit start . – user2485710 Jun 7 '20 at 7:46
  • You can start anything at boot from the kernel, it does not have to be init. Typically the bootloader reads the kernel and initramfs from the disk, and then executes the first process, which then prepares the file system mounts and switches into the "real" system by switching root. – hargut Jun 7 '20 at 11:03
  • What is started by the kernel can be defined using the kernel parameters (config) or boot flags such as init=/your/program/to/exec/as/pid/1. This can be directly a shell or systemd or a sysv init script. kernel.org/doc/html/latest/admin-guide/kernel-parameters.html – hargut Jun 7 '20 at 11:08
  • Further it is as well possible to completely avoid initramfs as this is not required. Such configurations are not common with popular linux distribution, but technically it is not a must. – hargut Jun 7 '20 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.