Understand runlevels or targets in Linux

0
27

When linux based system start booting. Kernel select one of available target and load services accordingly.
A target is a mode in Centos 7 and Red hat enterprise . systemd is responsible to select the target. A systemd target is same a runlevels in centos6.
systemd target is replacement of “System V init” system. systemd is a system daemon
systemd is designed for better handling of dependencies and has ability to handle more work in parallel at system startup
There are 7 target or levels available in Centos7

Run-level Target Explanation
0 poweroff.target This run level/target is used by systemd to power-off or halt the system
1 rescue.target This run level/target is used by systemd to boot the system in rescue or recovery mode. It is very helpful if some goes wrong you can change the configuration in that mode
2 multi-user.target This run level/target is used by systemd to boot system into multi-user environment so user can work in parallel
3 multi-user.target
4 multi-user.target
5 graphical.target This run level/target is used by systemd to boot system into multi-user graphical environment so user can work in parallel in graphical mode
6 reboot.target This run level/target is used by systemd to reboot the system

 

How to get list to available Targets

[kmehmood@svn-dev ~]$ systemctl list-units --type=target

Note: Above statement will only share list of active available target

Output of above statement

How to get list of available target including inactive

[kmehmood@svn-dev ~]$ systemctl list-units --type=target --all

Note: Above statement will only share list of all available targets

There are two type of default targets
1: multi-user.target
2: graphical.target

How to find default target

[kmehmood@svn-dev ~]$ systemctl get-default
graphical.target

Output of above statement

How to change default mode
Syntax: systemctl set-default target_name

[root@svn-dev ~]# systemctl set-default multi-user.target

Confirm the default runlevel.

[root@svn-dev ~]# systemctl get-default
multi-user.target

Reboot and check it out.

[root@svn-dev ~]# reboot

we can also check target levels available

[kmehmood@svn-dev ~]$ ls /lib/systemd/system/runlevel*target -l
lrwxrwxrwx. 1 root root 15 Jan 23 19:10 /lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Jan 23 19:10 /lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 Jan 23 19:10 /lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Jan 23 19:10 /lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Jan 23 19:10 /lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 Jan 23 19:10 /lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 Jan 23 19:10 /lib/systemd/system/runlevel6.target -> reboot.target

output

LEAVE A REPLY

Please enter your comment!
Please enter your name here