• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

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

By admin

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

Filed Under: Linux

Some more articles you might also be interested in …

  1. Understanding The /etc/sysconfig Directory
  2. How to mount USB flash drive in Linux
  3. CentOS / RHEL 7 : How to Enable the Old ethX Style Network Interfaces Names
  4. Sample /etc/multipath.conf file
  5. CentOS / RHEL : iptables troubleshooting guide
  6. How to Provide Credentials From a File While Mounting CIFS Share in Linux
  7. Managing MySQL Using Systemd As A Non Root User
  8. CentOS / RHEL 6,7 : How to enable or disable XDMCP service (GDM)
  9. Using vmstat to troubleshoot performance issues in Linux
  10. CentOS / RHEL : Move a Physical Volume from an existing Volume Group to another Volume Group

You May Also Like

Primary Sidebar

Recent Posts

  • How to disable ICMP redirects on CentOS/RHEL
  • What are Oracle Key Vault Roles
  • What Is Oracle Key Vault
  • Auditing with Oracle Database Vault Reports
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary