Skip to content

This is a repository that contains my custom initramfs. It uses the latest version of busybox, the linux kernel and a custom init script.

License

Notifications You must be signed in to change notification settings

michele13/initramfs

Repository files navigation

My Custom Initramfs

Linux Kernel: 6.12.1 Busybox: 1.36.1

1. Goals

  • Statically compiled busybox
  • Simple directory structure and init scripts
  • Easily rebuild the initramfs after booting the system
  • Easily customisable with its autorun script

2. Minimal Directory structure

/live
/tmp (chmod 1777)
/dev
/sys
/proc
/bin/busybox
/bin/rebuild-initramfs
/bin/sh -> busybox
/bin/init -> /init
/bin/applets/(busybox applets)

optional lib dirs you might want to create

/usr -> / (optional usr)
/lib
/lib64 -> /lib

other directories could be a symlink from other directories

/etc -> /data/etc
/home -> /data/home

3. Startup

3.1 First stage init (/init)

The main init executable is /init. It is a script run form the system shell and it's the firt process of the system (PID 1). Its job is to mount /proc, /sys and /dev and check if the kernel command line has the rescue argument: if it does it drops you to a shell (RESCUE MODE), else it reads /rc.init where the rest of the magic happens.

3.2 Second stage init (/rc.init)

/rc.init is a text file that is sourced from /init. We still are PID 1.

From the kernel documentation:

The kernel parses parameters from the kernel command line up to “–”; if it doesn’t recognize a parameter and it doesn’t contain a ‘.’, the parameter gets passed to init: parameters with > ‘=’ go into init’s environment, others are passed as command line arguments to init. Everything after “–” is passed as an argument to init.

  1. If we pass the parameter live=/dev/sda1, live=LABEL=(disk-label) or live=UUID=(part UUID) to the kernel command line, the specified partitio will be mounted under /live.

  2. If the script /live/$distro/boot/autostart.sh exists, it will be read and executed.

    • if the $distro environment variable is not passed using the kernel commandline, init.rc will look for /live/boot/autostart.sh
  3. It runs a root shell

Interesting Projects

Other interesting readings

About

This is a repository that contains my custom initramfs. It uses the latest version of busybox, the linux kernel and a custom init script.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages