乐闻世界logo
搜索文章和话题

How to change the default run level in Linux?

1个答案

1

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:

  1. Open a terminal.
  2. Open the /etc/inittab file using a text editor. Use the following command:
bash
sudo vi /etc/inittab
  1. Locate a line similar to the following in the file:
shell
id: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:

  1. Open a terminal.
  2. Use the systemctl command to set the default target. For example, to change the default runlevel to the graphical interface, run:
bash
sudo systemctl set-default graphical.target

Here, graphical.target corresponds to the traditional runlevel 5. 3. To view the current default target, use:

bash
systemctl get-default
  1. 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.

2024年8月14日 13:09 回复

你的答案