2017-06-03 15:27:30 -04:00
|
|
|
.Dd October 5, 2015
|
2015-07-23 20:24:49 -04:00
|
|
|
.Dt INIT 8
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm init
|
|
|
|
.Nd system initialization
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.Nm init
|
|
|
|
.Op Fl \-target Ns "=" Ns Ar init-target
|
2017-02-25 17:25:53 -05:00
|
|
|
.Op Fl \-
|
|
|
|
.Op Ar chain-init ...
|
2015-07-23 20:24:49 -04:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
.Nm
|
|
|
|
is the first program run after system startup and is responsible for
|
|
|
|
initializing the operating system and starting the specified
|
|
|
|
.Ar init-target .
|
|
|
|
This is normally a login screen, a root shell, or a dedicated special purpose
|
|
|
|
program.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Xr kernel 7
|
|
|
|
starts the system in a temporary environment with a root filesystem
|
|
|
|
backed by system memory and extracts the
|
|
|
|
.Xr initrd 7
|
2017-02-15 16:56:28 -05:00
|
|
|
into it.
|
|
|
|
The kernel runs the
|
2015-07-23 20:24:49 -04:00
|
|
|
.Pa /sbin/init
|
2017-02-15 16:56:28 -05:00
|
|
|
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
|
2015-07-23 20:24:49 -04:00
|
|
|
.Nm
|
2017-02-15 16:56:28 -05:00
|
|
|
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
|
2015-07-23 20:24:49 -04:00
|
|
|
.Xr update-initrd 8
|
2017-02-15 16:56:28 -05:00
|
|
|
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.
|
2015-07-23 20:24:49 -04:00
|
|
|
.Ss Initialization Target
|
|
|
|
.Nm
|
|
|
|
first determines its target from the
|
|
|
|
.Fl \-target
|
|
|
|
option if specified or
|
|
|
|
.Pa /etc/init/target
|
2017-02-15 16:56:28 -05:00
|
|
|
otherwise.
|
|
|
|
Supported targets are:
|
2015-07-23 20:24:49 -04:00
|
|
|
.Pp
|
|
|
|
.Bl -tag -width "single-user" -compact -offset indent
|
2016-08-21 17:03:33 -04:00
|
|
|
.It Sy chain
|
2015-07-23 20:24:49 -04:00
|
|
|
mount real root filesystem and run its
|
2016-08-21 17:03:33 -04:00
|
|
|
.Nm .
|
|
|
|
.It Sy chain-merge
|
|
|
|
like
|
|
|
|
.Sy chain
|
|
|
|
but run
|
|
|
|
.Pa /sysmerge/sbin/init
|
|
|
|
with the
|
|
|
|
.Sy merge
|
|
|
|
target.
|
|
|
|
.It Sy merge
|
|
|
|
finish a
|
2016-02-18 16:16:02 -05:00
|
|
|
.Xr sysmerge 8
|
2016-08-21 17:03:33 -04:00
|
|
|
upgrade and then execute the real
|
|
|
|
.Nm
|
|
|
|
with its default target.
|
|
|
|
.It Sy multi-user
|
2015-07-23 20:24:49 -04:00
|
|
|
boot to
|
2016-08-21 17:03:33 -04:00
|
|
|
.Xr login 8 .
|
|
|
|
.It Sy single-user
|
|
|
|
boot to root shell without password (not secure).
|
|
|
|
.It Sy sysinstall
|
|
|
|
boot to operating system installer (not secure).
|
|
|
|
.It Sy sysupgrade
|
|
|
|
boot to operating system upgrader (not secure).
|
2015-07-23 20:24:49 -04:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
It is a full system compromise if unauthenticated users are able to boot the
|
2017-02-15 16:56:28 -05:00
|
|
|
wrong target.
|
|
|
|
The kernel command line can specify the path to
|
|
|
|
.Nm
|
|
|
|
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
|
2015-07-23 20:24:49 -04:00
|
|
|
password protected.
|
2017-04-19 09:56:53 -04:00
|
|
|
.Ss Cleanup of /tmp
|
|
|
|
.Nm
|
|
|
|
deletes everything inside of
|
|
|
|
.Pa /tmp
|
|
|
|
if it exists, otherwise it is created with mode 1777.
|
2015-07-23 20:24:49 -04:00
|
|
|
.Ss Partition Creation
|
|
|
|
.Nm
|
|
|
|
will scan every block device for valid partition tables and create the
|
|
|
|
corresponding partition devices in
|
|
|
|
.Pa /dev .
|
|
|
|
.Ss Chain Initialization
|
2016-08-21 17:03:33 -04:00
|
|
|
The
|
|
|
|
.Sy chain
|
|
|
|
target mounts the root filesystem as in
|
2015-07-23 20:24:49 -04:00
|
|
|
.Pa /etc/fstab
|
2016-02-15 09:09:21 -05:00
|
|
|
(see
|
2017-02-25 17:25:53 -05:00
|
|
|
.Xr fstab 5 )
|
|
|
|
and runs the next
|
2016-02-15 09:09:21 -05:00
|
|
|
.Nm
|
2017-02-15 16:56:28 -05:00
|
|
|
program.
|
|
|
|
This is used by
|
2016-02-15 09:09:21 -05:00
|
|
|
.Xr update-initrd 8
|
|
|
|
to make a bootstrap
|
|
|
|
.Xr initrd 7 .
|
2015-07-23 20:24:49 -04:00
|
|
|
.Pp
|
2016-02-15 09:09:21 -05:00
|
|
|
Every block device and partition is scanned to determine if it is the root
|
2017-02-15 16:56:28 -05:00
|
|
|
filesystem.
|
|
|
|
It is checked for consistency if necessary.
|
|
|
|
It is mounted at
|
2015-07-23 20:24:49 -04:00
|
|
|
.Pa /tmp/fs.XXXXXX
|
|
|
|
and the
|
|
|
|
.Pa /dev
|
|
|
|
filesystem directory is bound at
|
|
|
|
.Pa /tmp/fs.XXXXXX/dev .
|
|
|
|
.Pp
|
|
|
|
Finally the
|
|
|
|
.Pa /sbin/init
|
2017-02-25 17:25:53 -05:00
|
|
|
program (or
|
|
|
|
.Ar chain-init
|
|
|
|
if specified) of the target root filesystem is run inside a chroot.
|
2015-07-23 20:24:49 -04:00
|
|
|
.Ss Configuration
|
|
|
|
Once the
|
|
|
|
.Nm
|
|
|
|
of the real root filesystem runs, it will process basic configuration files and
|
|
|
|
apply them:
|
|
|
|
.Pp
|
|
|
|
.Bl -tag -width "/etc/videomode" -compact -offset indent
|
|
|
|
.It Pa /etc/hostname
|
|
|
|
set hostname (see
|
|
|
|
.Xr hostname 5 )
|
|
|
|
.It Pa /etc/kblayout
|
|
|
|
set keyboard layout (see
|
|
|
|
.Xr kblayout 5 )
|
|
|
|
.It Pa /etc/videomode
|
|
|
|
set graphics resolution (see
|
|
|
|
.Xr videomode 5 )
|
|
|
|
.El
|
2016-08-19 21:17:29 -04:00
|
|
|
.Ss Mountpoints
|
|
|
|
.Nm
|
|
|
|
mounts all the filesystems according to
|
|
|
|
.Xr fstab 5 .
|
2016-08-19 20:27:33 -04:00
|
|
|
.Ss Random Seed
|
|
|
|
.Nm
|
|
|
|
will write 256 bytes of randomness to
|
|
|
|
.Pa /boot/random.seed ,
|
|
|
|
which serves as the initial entropy for the
|
|
|
|
.Xr kernel 7
|
2017-02-15 16:56:28 -05:00
|
|
|
on the next boot.
|
|
|
|
The file is also written on system shutdown where the system has the most
|
|
|
|
entropy.
|
2016-08-21 17:03:33 -04:00
|
|
|
.Ss Merge
|
|
|
|
The
|
|
|
|
.Sy merge
|
|
|
|
target completes a delayed system upgrade by invoking the
|
|
|
|
.Xr sysmerge 8
|
|
|
|
at
|
|
|
|
.Pa /sysmerge/sbin/sysmerge
|
|
|
|
with the
|
|
|
|
.Ar --booting
|
2017-02-15 16:56:28 -05:00
|
|
|
option.
|
|
|
|
If the upgrade succeeds, the temporary
|
2016-08-21 17:03:33 -04:00
|
|
|
.Nm
|
|
|
|
deinitializes the system and invokes the real (now upgraded)
|
|
|
|
.Nm
|
|
|
|
which will restart system initialization in the normal fashion.
|
2015-07-23 20:24:49 -04:00
|
|
|
.Ss Session
|
|
|
|
Finally
|
|
|
|
.Nm
|
2017-02-15 16:56:28 -05:00
|
|
|
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
|
2015-07-23 20:24:49 -04:00
|
|
|
.Nm
|
|
|
|
will automatically restart it.
|
|
|
|
.Nm
|
2017-02-15 16:56:28 -05:00
|
|
|
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.
|
2015-07-23 20:24:49 -04:00
|
|
|
.Sh ENVIRONMENT
|
|
|
|
.Nm
|
|
|
|
sets the following environment variables.
|
|
|
|
.Bl -tag -width "INIT_PID"
|
|
|
|
.It Ev HOME
|
|
|
|
root's home directory
|
|
|
|
.It Ev INIT_PID
|
|
|
|
.Nm Ns 's
|
|
|
|
process id
|
|
|
|
.It Ev LOGNAME
|
|
|
|
root
|
|
|
|
.It Ev PATH
|
|
|
|
.Pa /bin:/sbin
|
|
|
|
.It Ev SHELL
|
|
|
|
root's shell
|
|
|
|
.It Ev TERM
|
|
|
|
sortix
|
|
|
|
.It Ev USER
|
|
|
|
root
|
|
|
|
.El
|
|
|
|
.Sh FILES
|
2016-08-19 20:27:33 -04:00
|
|
|
.Bl -tag -width "/boot/random.seed" -compact
|
|
|
|
.It Pa /boot/random.seed
|
|
|
|
initial kernel entropy
|
2015-07-23 20:24:49 -04:00
|
|
|
.It Pa /etc/init/target
|
|
|
|
default initialization target
|
|
|
|
.It Pa /etc/fstab
|
|
|
|
filesystem table (see
|
|
|
|
.Xr fstab 5 )
|
|
|
|
.It Pa /etc/hostname
|
|
|
|
hostname (see
|
|
|
|
.Xr hostname 5 )
|
|
|
|
.It Pa /etc/kblayout
|
|
|
|
keyboard layout (see
|
|
|
|
.Xr kblayout 5 )
|
|
|
|
.It Pa /etc/videomode
|
|
|
|
graphics resolution (see
|
|
|
|
.Xr videomode 5 )
|
|
|
|
.El
|
|
|
|
.Sh EXIT STATUS
|
|
|
|
.Nm
|
|
|
|
exits 0 if the kernel should power off, exits 1 if the kernel should reboot, or
|
2017-05-21 16:20:28 -04:00
|
|
|
exits 2 if the boot failed and the kernel should halt with a complaint about an
|
|
|
|
.Nm
|
|
|
|
fatality.
|
2017-02-15 16:56:28 -05:00
|
|
|
Any other exit by the initial
|
2015-07-23 20:24:49 -04:00
|
|
|
.Nm
|
2017-05-21 16:20:28 -04:00
|
|
|
will cause the kernel to halt with a complaint about an unexpected exit code.
|
2015-07-23 20:24:49 -04:00
|
|
|
.Nm
|
|
|
|
exits with the same exit status as its target session if it terminates normally.
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr fstab 5 ,
|
|
|
|
.Xr hostname 5 ,
|
|
|
|
.Xr kblayout 5 ,
|
|
|
|
.Xr videomode 5 ,
|
|
|
|
.Xr initrd 7 ,
|
|
|
|
.Xr kernel 7 ,
|
|
|
|
.Xr login 8 ,
|
2016-02-18 16:16:02 -05:00
|
|
|
.Xr sysmerge 8 ,
|
2015-07-23 20:24:49 -04:00
|
|
|
.Xr update-initrd 8
|