Exercise 3 – Change Runlevels and Shutdown or Reboot System

A run level on a Linux system is the definition of what all services are running on the system. To run each service, relevant parameters need to be initialised in the init file. Therefore, each level defines the state of various parameters in the init file. Each run levels is referred to by a number. You can change between run levels to activate or shutdown various services, as required.

Note: You can manage the services individually as well, without changing between the run levels.

In this exercise, you will understand how to change runlevels to shutdown or reboot systems.
Please refer to your course material or use your favourite search engine to research for more information about this topic.

Task 2 – Configure a Runlevel

You can add, delete, and manage services to configure a runlevel. In this task, you will configure a runlevel on the Fedora Linux machine on the lab.

To configure a runlevel, perform the following steps:

Step 1

Clear the screen by entering the following command:

clear

Note: The clear command is used before every step to enable the learners to get a clear view of the output of each command. Otherwise, it is not mandatory to use the clear command before every command.

To view the list of services running on the system, enter the following command:

chkconfig --list

Note: The list parameter requires a double dash (–). If you attempt it with a single dash, you will be prompted with an error.

NOTE: Ubuntu no longer use "chkconfig", try " systemctl list-units --type target --all".
$ systemctl list-units –type target –all (Fedora 29)
Ubuntu 18.10.2

Note: In this Cybrary practice labs, keep shows “chkconfig” command but I wrote about “systemctl” commands.

You should install “chkconfig” to use that commands in Ubuntu linux.

the relationship between runlevels numbers and targets.

  • Run level 0 is matched by poweroff.target (and runlevel0.target is a symbolic link to poweroff.target).
  • Run level 1 is matched by rescue.target (and runlevel1.target is a symbolic link to rescue.target).
  • Run level 3 is emulated by multi-user.target (and runlevel3.target is a symbolic link to multi-user.target).
  • Run level 5 is emulated by graphical.target (and runlevel5.target is a symbolic link to graphical.target).
  • Run level 6 is emulated by reboot.target (and runlevel6.target is a symbolic link to reboot.target).
  • Emergency is matched by emergency.target.

How to View Current target (run level) in Systemd

When the system boots, by default systemd activates the default.target unit. It’s main work is to activate services and other units by pulling them in via dependencies.

To view the default target, type the command below.

#systemctl get-default 

graphical.target

To set the default target, run the command below.

# systemctl set-default multi-user.target  

How to Change the target (runlevel) in Systemd

While the system is running, you can switch the target (run level), meaning only services as well as units defined under that target will now run on the system.

To switch to runlevel 3, run the following command.

# systemctl isolate multi-user.target 

To change the system to runlevel 5, type the command below.

# systemctl isolate graphical.target

Task 4 – Shutdown and Reboot the System from the Command Line

To shutdown and reboot the system from the command line, perform the following steps:

Step 1

Verify the default runlevel of the system by entering the following command at the command shell prompt:

runlevel

Step 2

To configure the system shutdown in next 10 minutes, enter the following command:

shutdown -h +10

You are prompted with a message confirming the schedule for the shutdown.

Step 3

Press Ctrl + c to break the command.

Step 4

To cancel the scheduled shutdown, enter the following command:

shutdown -c

Notice that output message confirms that the scheduled shutdown is cancelled.

Step 5

You can also configure the system to shutdown automatically at a specific time. For example, to configure the system to shutdown automatically at 11:00 AM, enter the following command:

shutdown -r 11:00

A confirmation message appears.

Step 6

You can also reboot a system from the command prompt. This helps avoid a hard reboot.

To reboot a system, enter the following command:

reboot

Note that system reboot is initiated.

Task 5 – Alert Users Before Switching Runlevels or Other Major System Events

Alerting users before switching runlevels or other major system events can help avoid any disturbing last minute surprises or unscheduled data loss. To alert users, perform the following steps:

Step 1

Enter the following command to broadcast the message to users:

wall “This system will be rebooted at 11:00 AM”

Notice that the message appears on the screen. A similar message appears on the screen of each user alerting them about the scheduled shutdown.

Task 6 – Manage Services

To manage services, perform the following steps:

Step 1

Using the open command shell enter the following command to stop a service. For demonstration purpose, vmware-tools service is being stopped:

service vmware-tools stop

Notice a message appears confirming stopping of the specified service.

Step 2

Once a service is stopped, you can restart it.

To start the stopped service, enter the following command:

service vmware-tools start

Notice a message appears confirming starting of the specified service.

Task 7 – Understand Terms and Utilities

To understand the terms and utilities, perform the following steps:

Step 1

To review the default runlevels in the inittab, enter the following command:

cat /etc/inittab


Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s