6 terminal commands for restarting and shutting down Linux system

Time:2020-3-25

In the Linux administrator’s schedule, there are many tasks to be performed, including system restart and shutdown. The following are the steps that I implemented with the electronic fish sail-imx6q development board.

For Linux administrators, rebooting and shutting down the system is one of many risky operations. Sometimes, for some reasons, these operations may be irreparable, and they need more time to troubleshoot.

We can perform these tasks in Linux command line mode. Many times, Linux administrators are more likely to do these tasks at the command line because they are familiar with the command line.

There are not many linux commands to restart and shut down the system. Users need to select appropriate commands to complete the task according to their needs.

All of the following commands have their own characteristics and are allowed to be used by Linux administrators

At the beginning of system restart and shutdown, all logged in users and processes will be notified. Of course, if the time parameter is used, the system will refuse new user login.

Before you do this, I recommend that you stick to the review because you only get a few tips to make sure it works.

Here are some steps:

Make sure you have a console that can handle failures in case of problems later. VMware can access virtual machines, while IPMI, ILO, and idracs can access physical servers.
You need to go through the company’s process and apply for the right to modify or fail until you get permission.
For security reasons, back up important configuration files and save them to other servers
Verify log file (check in advance)
Communicate with related teams, such as database management team, application team, etc.
Notify database and application service personnel to shut down the service and get a definite reply.
Verify the work by using the appropriate command to redo the operation.
Finally, restart the system.
Verify the log file. If everything goes well, carry out the next operation. If any problems are found, troubleshoot them.
Whether it is a fallback version or a running program, inform the relevant team to apply.
Keep an appropriate watch on the operation and feed back to the team what is expected
Use the following command to perform this task.

Shutdown, halt, poweroff, reboot command: used to stop, restart or cut off the power supply
Init command: short for “initialization”, which is the first process started by the system.
Systemctl command: SYSTEMd is the hypervisor of Linux system and server.

Scenario 1: how to use the shutdown command to shut down and restart the Linux system

The shutdown command is used to power down or restart local and remote Linux machines. It provides multiple options for efficiently completing jobs. If the time parameter is used, the / run / nologin file is created five minutes before the system shuts down to ensure that subsequent logins are denied.

The general syntax is as follows:

shutdown [OPTION] [TIME] [MESSAGE]

Run the following command to shut down the Linux machine immediately. It immediately kills all processes and shuts down the system.

shutdown -h now

-h: If you do not specifically refer to the – halt option, this is equivalent to the – poweroff option.
In addition, we can use the shutdown command with the – halt option to shut down the device immediately.

shutdown –halt now

perhaps

shutdown -H now

-H. — halt: stop the equipment
In addition, we can use the shutdown command with the poweroff option to shut down the device immediately.

shutdown –poweroff now

perhaps

shutdown -P now

-P. — poweroff: power off (default).
If you do not use the time option to run the following command, it will give the following results.

shutdown -h

Usage: shutdown [-akrhPHfFnc] [-t sec] time [warning message]

              -a:      use /etc/shutdown.allow
              -k:      don't really shutdown, only warn.
              -r:      reboot after shutdown.
              -h:      halt after shutdown.
              -P:      halt action is to turn off power.
              -H:      halt action is to just halt.
              -f:      do a 'fast' reboot (skip fsck).
              -F:      Force fsck on reboot.
              -n:      do not go through "init" but go down real fast.
              -c:      cancel a running shutdown.
              -t secs: delay between warning and kill signal.
              ** the "time" argument is mandatory! (try "now") **

Add a time parameter if you want to shut down or restart after N seconds. Here, you can add custom broadcast messages for all logged in users. For example, we will restart the device in five minutes.

[email protected]:~# shutdown -r +5 “To activate the latest Kernel”

Broadcast message from [email protected] (ttymxc0) (Fri Jun 30 11:51:34 2000):To
activate the latest Kernel
The system is going DOWN for reboot in 5 minutes!
Run the following command to restart the Linux machine immediately. It immediately kills all processes and restarts the system.

shutdown -r now

-r. — reboot: restart the device.

Scheme 2: how to shut down and restart Linux system through reboot command

The reboot command is used to shut down and restart local or remote devices. The reboot command has two practical options.

It can shut down and restart devices gracefully (as simple as thinking about the restart option in the system menu).

Execute the reboot command without any parameters to restart the Linux machine.

reboot

Execute the reboot command with the – P parameter to power down the Linux machine.

reboot -p

-p. — poweroff: call the halt or poweroff command to power off the device.
Execute the reboot command with the – f parameter to force a reboot of the Linux device (similar to pressing the power key on the machine).

reboot -f

-f. — force: immediately force the interruption, power off or restart.

Solution 3: how to shut down and restart Linux system with init command

Init (short for initialization) is the first process the system starts.

It will check the / etc / inittab file and determine the Linux run level. At the same time, users are allowed to shut down or restart Linux devices. There are seven levels of operation from 0 to 6.

Recommended reading:

How to check all running services on Linux
Perform the following init command to shut down the system.

init 0

0: shutdown – shut down the system.
Run the following init command to restart the device:

init 6

6: Restart – restart the device.
Scheme 4: how to shut down and restart Linux system with halt command

The halt command is used to power off or shut down a remote Linux machine or local host. Interrupt all processes and shut down the CPU.

halt

Scheme 5: how to shut down and restart Linux system with poweroff command

The poweroff command is used to power off or shut down a remote Linux machine or local host. Poweroff is much like halt, but it turns off the device hardware (lights and other things on the PC). It will send ACPI command to the main board, and then the signal will be sent to the power supply to cut off the power supply.

poweroff

Solution 6: how to shut down and restart Linux system with systemctl command

SYSTEMd is a new init system and system manager for all major Linux hairstyles, rather than the traditional SYSV init system.

SYSTEMd is compatible with SYSV and LSB initialization scripts. It can replace the SYSV init system. SYSTEMd is the first process started by the kernel and holds the process PID with sequence number 1.