# Runlevels in SysVinit
- each runlevel represents a specific system state
- the system transitions through these runlevels during the boot process
- 0 - halt
- 1 - single-user mode
- 2 - multi-user mode w/o NFS
- 3 - full multi-user mode w/o GUI
- 4 - unused
- 5 - full multi-user mode w/ GUI
- 6 - reboot system
- `sudo runlevel` returns current runlevel for system ![[images/Pasted image 20250802204143.png]]
- runlevels - represent different system states
- 0 = halt state
- 1 = single-user mode
- 5 = default multi-user mode
- how runlevels work:
- boot process: when system boots it starts at a low runlevel (typically 1)
- transitioning runlevels
- services scripts: for each runlevel, there are scripts loaded in `/etc/init.d`
- SysVinit executes scripts in the proepr sequence
- these scripts define the actions to be taken when entering or exiting a particular runlevel
- scripts include instructions for starting, stopping, and restarting the associated service
- typically named after the services they control such as apache2, mysql, sshd
- runlevel switching: the `init` process, which is responsible for managing runlevels, can be instructed to switch to a different runlevel using the `telinit` command or by issuing a specific signal
- `teleinit 1` or `sudo init 1` will start/transition system in single-user mode
# Boot Targets in Systemd
- replace runlevels
- targets are a powerful mechanism for managing system state
- targets represent groups of services that should be started/stopped together
- how targets work:
- dependency mgmt: automatically determine dependencies b/t services and starts them in correct order
- target activation: starts all the services associated with the target and its dependencies
- targets deactivation: stops all associated services and dependencies
- common targets:
- `multi-user.target`
- `graphical.target`
- `rescue.target`
- `emergency.target`
- manually managing startup process:
- enabling a service: `sudo systemctl enable service_name`
- disabling a service: `sudo systemctl disable service_name`
- starting a service: : `sudo systemctl start service_name`
- stopping a service: : `sudo systemctl stop service_name`
- checking a service: : `sudo systemctl status service_name`
- restarting a service: : `sudo systemctl restart service_name`
- reloading a service config: : `sudo systemctl reload service_name`