CentOS / RHEL 7 : How to set default target (default runlevel)

Within Oracle Linux 7 introduction of systemd (systemd uses ‘targets’).The file /etc/inittab is no longer used to set the default run level. Editing /etc/inittab file with the same manner under Oracle Linux 5/6 will have no effect in Oracle Linux 7. Target units have a .target extension. Target units allow you to start a system with only the services that are required for a specific purpose.

To list the predefined systemd run level target units :

# find / -name "runlevel*.target"
/usr/lib/systemd/system/runlevel4.target
/usr/lib/systemd/system/runlevel5.target
/usr/lib/systemd/system/runlevel6.target
/usr/lib/systemd/system/runlevel1.target
/usr/lib/systemd/system/runlevel2.target
/usr/lib/systemd/system/runlevel3.target
/usr/lib/systemd/system/runlevel0.target

Comparision of SysV Run Levels and Target Units

The table below shows the system-state targets which are equivalents of run-levels.

Run Level Target Units Description
0 runlevel0.target, poweroff.target Shut down and power off
1 runlevel1.target, rescue.target Set up a rescue shell
2,3,4 runlevel[234].target, multi- user.target Set up a nongraphical multi-user shell
5 runlevel5.target, graphical.target Set up a graphical multi-user shell
6 runlevel6.target, reboot.target Shut down and reboot the system

To Check current default target

# systemctl get-default

The default target unit is represented by the /etc/systemd/system/default.target file. This file is a symbolic link to the default target unit file currently set.

# ls -l /etc/systemd/system/default.target
lrwxrwxrwx. 1 root root 40 Oct 11 02:02 /etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target

Use the runlevel command to view the SysV runlevel.

# runlevel
N 5

Set a default target

To set a default target :

# systemctl set-default [new target]

for example :

# systemctl set-default multi-user.target
rm '/etc/systemd/system/default.target'
ln -s '/usr/lib/systemd/system/multi-user.target' '/etc/systemd/system/default.target'
Note that changing the default target unit removes the existing default.target symbolic link and re-creates the symbolic link, which points to the new default target unit file.

Verify

Use the ls –l command to confirm that the default.target file is now a symbolic link to the multi-user.target file.

# ls -l /etc/systemd/system/default.target
lrwxrwxrwx. 1 root root 41 Mar 24 01:53 /etc/systemd/system/default.target -> /usr/lib/systemd/system/multi-user.target

Set current target to default

When you set the default target unit, the current target remains unchanged until next reboot. To change the current target unit to default wihtout reboot use :

# systemctl default

or

# systemctl isolate default.target
Related Post