In Linux systems, the runlevel specifies the set of processes that run during system startup and shutdown. This concept is particularly relevant for Linux distributions using the System V init system.
To change the default runlevel in Linux, you can modify the relevant initialization configuration file. Different Linux distributions may employ different approaches, and I will outline the steps for changing the default runlevel in both System V init and systemd-based systems.
System V init
For systems using System V init (e.g., older versions of Debian or CentOS), the default runlevel is defined in the /etc/inittab file. Follow these steps to change it:
- Open a terminal.
- Open the
/etc/inittabfile using a text editor. Use the following command:
bashsudo vi /etc/inittab
- Locate a line similar to the following in the file:
shellid:3:initdefault:
Here, the number 3 indicates the current default runlevel.
4. Change the number to your desired runlevel. For example, to boot into the graphical interface by default, set it to 5.
5. Save and close the file.
6. Reboot the system to apply the changes.
systemd
For systems using systemd (e.g., recent versions of Fedora, CentOS, Debian, Ubuntu), changing the default runlevel is achieved by modifying the default target. The steps are as follows:
- Open a terminal.
- Use the
systemctlcommand to set the default target. For example, to change the default runlevel to the graphical interface, run:
bashsudo systemctl set-default graphical.target
Here, graphical.target corresponds to the traditional runlevel 5.
3. To view the current default target, use:
bashsystemctl get-default
- Reboot the system to apply the changes.
By following these steps, you can configure the Linux system to boot into the desired runlevel or target state. In production environments, proper configuration of the runlevel is crucial for ensuring system security and efficient operation.