Sortix
Sortix Download Manual Development Source Code News Blog More
current nightly

NAME

init — system initialization

SYNOPSIS

init [--target=init-target]

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 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
complete a sysmerge(8) upgrade during a chain boot
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.

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 nessesary. It is mounted at /tmp/fs.XXXXXX and the /dev filesystem directory is bound at /tmp/fs.XXXXXX/dev.
Finally the /sbin/init program 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))

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

/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. Any other exit by the initial init will trigger a kernel panic. 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)
Copyright 2011-2025 Jonas 'Sortie' Termansen and contributors.
Sortix's source code is free software under the ISC license.
#sortix on irc.sortix.org
@sortix_org