Sunday, August 28, 2016

Managing Boot Targets

If you’re familiar with runlevels under init, then working with runlevels under systemd is fairly easy to understand. The commands you use to manage runlevels are different under systemd, but the concepts are similar. One of the key things to remember is the fact that systemd uses the concept of boot targets, which function in a similar way as runlevels. Each boot target is represented by a file in /usr/lib/systemd/system with an extension of .target. In the following list, traditional init runlevels are shown with their equivalent systemd boot target files: 
runlevel 3 = multi-user.target or runlevel3.target
runlevel 5 = graphical.target or runlevel5.target 
Notice that there are two target files for each runlevel. Be aware that runlevel3.target is actually just a symbolic link that points to the multi-user.target file. Likewise, the runlevel5.target file is a symbolic link that points to the graphical.target file
On a system uses systemd, you use the systemctl command to manage services and runlevels. Instead of using init, chkconfig, or service, you use systemctl to manage most aspects of a systemd system. For example, to change runlevels you run systemctl and point to a particular boot target. The syntax is systemctl isolate boot_target
For example, if I wanted to switch to the systemd equivalent of runlevel 5, I could enter either of the following commands: 
systemctl isolate runlevel 5.target 
systemctl isolate graphical.target 
And just as with the traditional init process, changing boot targets on the fly with systemd only changes the current runlevel. If you reboot the system, it will boot back into the default runlevel. With systemd, you no longer use the inittab file to set the default runlevel. Instead, the /etc/ systemd/system/default.target file controls the default boot target. As you can see in the following example, this file is actually a symbolic link that points back to the boot target file that should be used by default: 
openSUSE:/etc/systemd/system # ls -l default.target
lrwxrwxrwx 1 root root 40 Nov 12 09:05 default.target -> /usr/lib/systemd/system/runlevel5.target

To modify the default boot target, you need to modify the boot file that this symbolic link points to. This is done using the systemctl set-default boot_target command. For example, to set the default boot target to graphical mode, you would enter systemctl set-default graphical .target or systemctl set-default runlevel 5.target
If you want to view the current runlevel, enter systemctl get-default. An example is shown here: 
openSUSE:/etc/systemd/system # systemctl get-default
runlevel5.target



No comments:

Post a Comment