4

I figured that I would need a kernel image and a bootloader (grub), but is there anything else needed to boot a linux system?

3 Answers3

3

In the most minimal case just bootloader, kernel and file system.

Bootloader is sometimes part of firmware (recent Linux kernels may be loaded directly by EFI on x86). You also have to tell the kernel what file system to mount as /, e.g. with the root= parameter (for Linux). It will subsequently try to load init as the last step to hand control over to userspace. In the case of Linux you might want to check kernel_init_() in init/main.c for the order of binaries which are tried.

Stephen Kitt
  • 434,908
peterph
  • 30,838
  • As of 2022, if no user command was specified in the boot options (init=…), the following are tried, in order: /sbin/init, /etc/init, /bin/init, /bin/sh. (Note: the function is now kernel_init() instead of init_post()) Finally, from the linked code: “See Linux Documentation/admin-guide/init.rst” – Jim Grisham Aug 22 '22 at 23:51
  • 1
    @JimGrisham We check the path in CONFIG_DEFAULT_INIT before those if it is set since my changes in 5.8. – Chris Down Aug 24 '22 at 11:03
1

You need a kernel image and somehow to make it available to the system, whether it's on permanent storage or shared over the network, or transferred over some serial connection, etc, and some code whether the machine's firmware or some bootloader (which would have to be made available as well), to load that kernel into the system's memory.

After loading and initialising, the kernel would normally create a first process in which it would load an init command, that can be supplied via some initramfs or ramdisk whose image would also need to be loaded in memory (and extracted by the kernel for initramfs), or from some network or on-permanent-storage file system.

Generally, the initramfs if any is only used temporarily at early boot time to setup and transition to the real system, but doesn't have to be, it can be all there is.

The kernel could also be modified to not run init and implement whatever the system is meant to do in kernel code.

For instance, a simple firewall/router does not have to run any user-space process as all the routing and packet filtering is done in the kernel, though in practice, you'll still want some user space tools and a filesystem to manage it, do the logging, etc.

1

Yes you need the system to know what to mount and where. The loader will look for an image and the system binaries. A good documentation to play around is Linux From Scratch book, take a look here.

vfbsilva
  • 3,697