INIT(8)

NAME
init - system initialization

SYNOPSIS
init [-qsv] [--prefix=prefix] [--static-prefix=static-prefix] [--target=default-daemon] [--] [chain-init ...]

DESCRIPTION
init is the first program run after system startup and is responsible for initializing the operating system.

Each daemon(7) is started in order as its dependencies become ready per its init(5) configuration. The default daemon is automatically started and its recursive dependencies constitute the operating system. The default daemon's single dependency is referred to as the target.

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 itself as the intended system and complete the system startup.

The options are as follows:

-p, --prefix=prefix
    Boot the system inside the prefix rather than the root directory. This option is not officially supported and does not chroot(2) and is not communicated to the descendant processes, which by default would continue to use many files such as the passwd(5) of the root directory. Use chroot(8) to as the supported way to spawn a recursive init.

-P, --static-prefix=static-prefix
    Boot the operating system using the static data (programs, libraries, and default configuration) from the static-prefix rather than the --prefix. This option is supported and sets the PATH environment variable and others accordingly. It is designed for sysmerge(8) to run a new system with a new ABI using the local configuration files during the operating system upgrade.

-q, --quiet
    Write status updates to the terminal only about failed daemons. This behavior is the default.

-s, --silent
    Never write status updates about daemons to the terminal.

-t, --target=default-daemon
    Boot default-daemon as the target. The default daemon configuration is changed to only require the default-daemon dependency with the exit-only flag.

-v, --verbose
    Write all status updates about daemons starting and stopping to the terminal

  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
If the target is chain or chain-sysmerge, then the real operating system is chain initialized.

The root filesystem is mounted per /etc/fstab (see fstab(5)). This configuration file is a copy of the real file made by update-initrd(8) when it makes the bootstrap initrd(7).

The root filesystem is found by searching each block device and partition. It is checked for consistency if necessary and mounted read-only if the check fails. 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. If the target is chain-sysmerge, then the --static-prefix=/sysmerge --target=merge options are passed to the next init.

  Mountpoints
init mounts all the filesystems according to fstab(5). The filesystems are checked for consistency if necessary and mounted read-only if the check fails.

  Logging
Logging to /var/log begins once the filesystems are mounted and init writes the log entries from early boot to its /var/log/init.log.

  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.

  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))

  Merge
If the target is merge, then a delayed system upgrade is completed by invoking sysmerge(8) at /sysmerge/sbin/sysmerge with the --booting option.

If the upgrade succeeds, the temporary /sysmerge/sbin/init deinitializes the system and invokes the real (now upgraded) /sbin/init, which will restart system initialization in the normal fashion.

  Daemons
The default daemon(7) is started per its /etc/init/default init(5) configuration file, which constitutes the operating system, and once it exits then init exits with the same error code and the kernel shuts down the machine. The default daemon is meant to be a virtual daemon depending on a single top level daemon (the target), which provide the desired operating system functionality (e.g. booting to a single user shell or a multi user login screen).

The daemons are configured per init(5) where /etc/init contains the installation's local configuration, which overrides the operating system's default configuration in /share/init. The daemons are started in order as their dependencies become ready and are stopped in order when they are no longer required.

The local daemon is meant to start the installation's local daemon requirements.

ENVIRONMENT
init sets the following environment variables.

HOME
    root's home directory

LOGNAME
    root

PATH
    /bin:/sbin

SHELL
    root's shell

TERM
    sortix

USER
    root

FILES
/boot/random.seed
    Initial kernel entropy
/etc/init/
    Daemon configuration for the local system (first in search path) (see init(5))
/etc/init/default
    Configuration for the default daemon (see init(5))
/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))
/share/init/
    Default daemon configuration provided by the operating system (second in search path) (see init(5))
/var/log/
    Daemon log files (see init(5))
/var/log/init.log
    init's own log.

ASYNCHRONOUS EVENTS

SIGTERM
    Request system poweroff, normally sent by poweroff(8).

SIGINT
    Request system reboot, normally sent by reboot(8).

SIGQUIT
    Request system halt, normally sent by halt(8).

SIGHUP
    Request system reinitialization.

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), init(5), kblayout(5), videomode(5), daemon(7), initrd(7), kernel(7), halt(8), login(8), poweroff(8), reboot(8), service(8), shutdown(8), sysmerge(8), update-initrd(8)

SECURITY CONSIDERATIONS
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.