INIT(8)

NAME
init - system initialization

SYNOPSIS
init [--target=init-target] [--] [chain-init ...]

DESCRIPTION
init is the first program run after system startup and is responsible for initializing the operating system and starting the specified init-target. This is normally a login screen, a root shell, or a dedicated special purpose program.

The kernel(7) starts the system in a temporary environment with a root filesystem backed by system memory and extracts the initrd(7) into it. The kernel runs the /sbin/init program of the system memory root filesystem as the first process. If the system is on bootable cdrom, then the initrd will be a fully functional system and init will start a live environment or an operating system installer. If the system is installed on a harddisk, then the initrd is a minimal system made with update-initrd(8) that will search for the actual root filesystem and chain init it. The next stage init will recognize it as the intended system and complete the system startup.

  Initialization Target
init first determines its target from the --target option if specified or /etc/init/target otherwise. Supported targets are:

chain
    mount real root filesystem and run its init.
chain-merge
    like chain but run /sysmerge/sbin/init with the merge target.
merge
    finish a sysmerge(8) upgrade and then execute the real init with its default target.
multi-user
    boot to login(8).
single-user
    boot to root shell without password (not secure).
sysinstall
    boot to operating system installer (not secure).
sysupgrade
    boot to operating system upgrader (not secure).

It is a full system compromise if unauthenticated users are able to boot the wrong target. The kernel command line can specify the path to init and its arguments. Unprivileged users can change the kernel command line from the bootloader command line if it hasn't been password protected. Likewise unprivileged users can use their own replacement bootloader by booting a portable device under their control if the firmware configuration has not been password protected.

  Cleanup of /tmp and /var/run
init deletes everything inside of /tmp if it exists, otherwise it is created with mode 1777.

init creates /var with mode 755 if it doesn't exist. init deletes everything inside of /var/run if it exists, otherwise it is created with mode 755.

  Partition Creation
init will scan every block device for valid partition tables and create the corresponding partition devices in /dev.

  Chain Initialization
The chain target mounts the root filesystem as in /etc/fstab (see fstab(5)) and runs the next init program. This is used by update-initrd(8) to make a bootstrap initrd(7).

Every block device and partition is scanned to determine if it is the root filesystem. It is checked for consistency if necessary. It is mounted at /tmp/fs.XXXXXX and the /dev filesystem directory is bound at /tmp/fs.XXXXXX/dev.

Finally the /sbin/init program (or chain-init if specified) of the target root filesystem is run inside a chroot.

  Configuration
Once the init of the real root filesystem runs, it will process basic configuration files and apply them:

/etc/hostname
    set hostname (see hostname(5))
/etc/kblayout
    set keyboard layout (see kblayout(5))
/etc/videomode
    set graphics resolution (see videomode(5))

  Mountpoints
init mounts all the filesystems according to fstab(5).

  Random Seed
init will write 256 bytes of randomness to /boot/random.seed, which serves as the initial entropy for the kernel(7) on the next boot. The file is also written on system shutdown where the system has the most entropy.

  Merge
The merge target completes a delayed system upgrade by invoking the sysmerge(8) at /sysmerge/sbin/sysmerge with the --booting option. If the upgrade succeeds, the temporary init deinitializes the system and invokes the real (now upgraded) init which will restart system initialization in the normal fashion.

  Session
Finally init will start the target program according to its initialization target. This will be a login screen, a root shell, or something else. If the process exits abnormally init will automatically restart it. init will exit with the same exit status as the process if it exits normally. The kernel decides whether to power off, reboot or halt based on this exit status.

ENVIRONMENT
init sets the following environment variables.

HOME
    root's home directory

INIT_PID
    init's process id

LOGNAME
    root

PATH
    /bin:/sbin

SHELL
    root's shell

TERM
    sortix

USER
    root

FILES
/boot/random.seed
    initial kernel entropy
/etc/init/target
    default initialization target
/etc/fstab
    filesystem table (see fstab(5))
/etc/hostname
    hostname (see hostname(5))
/etc/kblayout
    keyboard layout (see kblayout(5))
/etc/videomode
    graphics resolution (see videomode(5))

EXIT STATUS
init exits 0 if the kernel should power off, exits 1 if the kernel should reboot, or exits 2 if the boot failed and the kernel should halt with a complaint about an init fatality. Any other exit by the initial init will cause the kernel to halt with a complaint about an unexpected exit code. init exits with the same exit status as its target session if it terminates normally.

SEE ALSO
fstab(5), hostname(5), kblayout(5), videomode(5), initrd(7), kernel(7), login(8), sysmerge(8), update-initrd(8)