Search This Blog

Tuesday, 25 October 2016

How to Set default runlevel in CentOS 7 / RHEL 7

In CentOS 7 / RHE 7,  systemd uses "targets" instead of run-levels.  /etc/inittab is no more used by systemd to change the run levels.

This guide will help you to set up default runlevel in CentOS 7 / RHEL 7.

Default runlevel can be set either by using the systemctl command or making symbolic link of runlevel targets to default target file.

rm '/etc/systemd/system/default.target'
ln -s '/usr/lib/systemd/system/multi-user.target' '/etc/systemd/system/default.target'

Check the current level.

# systemctl get-default 
multi-user.target

Before making the symbolic link, lets list out the files in the systemd directory.

# ls /lib/systemd/system/runlevel*target -l

Output will look like below.

lrwxrwxrwx. 1 root root 15 Aug  3 13:44 /lib/systemd/system/runlevel0.target -> poweroff.target  lrwxrwxrwx. 1 root root 13 Aug  3 13:44 /lib/systemd/system/runlevel1.target -> rescue.target  lrwxrwxrwx. 1 root root 17 Aug  3 13:44 /lib/systemd/system/runlevel2.target -> multi-user.target  lrwxrwxrwx. 1 root root 17 Aug  3 13:44 /lib/systemd/system/runlevel3.target -> multi-user.target  lrwxrwxrwx. 1 root root 17 Aug  3 13:44 /lib/systemd/system/runlevel4.target -> multi-user.target  lrwxrwxrwx. 1 root root 16 Aug  3 13:44 /lib/systemd/system/runlevel5.target -> graphical.target  lrwxrwxrwx. 1 root root 13 Aug  3 13:44 /lib/systemd/system/runlevel6.target -> reboot.target

As per the previous step, current default run level 3. Issue the following command to make symbolic link of runlevel5.target to default.target file.

# ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target

or

# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

Again check the current level.

# systemctl get-default  runlevel5.target

Now the default runlevel is 5 (graphical mode), reboot the server and check it out.

# reboot

No comments:

Post a Comment