SoFunction
Updated on 2025-03-04

Reboot, shutdown command and reboot dead problem solution under Linux system

Linux switch

In Linux, we often use shutdown, reboot, poweroff, halt, etc. to shut down or restart

In addition, it is to directly use init to modify the cycle level, such as: init 0, init 6, etc.

The functions of each command:

reboot restart

The parameters that can be connected are as follows:

Reboot the system.

     --help      Show this help
     --halt      Halt the machine
  -p --poweroff  Switch off the machine   
     --reboot    Reboot the machine
  -f --force     Force immediate halt/power-off/reboot  
  -w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
  -d --no-wtmp   Don't write wtmp record
     --no-wall   Don't send wall message before halt/power-off/reboot

Here we mainly talk about `reboot -f`, forced restart

During the process of using the `reboot` command, I encountered reboot dead in CentOS8.2 system, and I waited for a while.

After 30mins, the problem was solved after the command was modified to `reboot -f`.

Shutdown process:

  • 1. Notify all running processes: The system will send a SIGTERM signal to all running processes to notify them that the system will be shut down soon.
  • 2. Stop all running processes: The system will terminate all running processes one by one until there are no remaining processes.
  • 3. Close all open files: The system will close all open files to ensure that all data is correctly written to disk.
  • 4. Stop all devices: The system will stop all devices from running, including disks, network devices and other hardware devices.
  • 5. Close the kernel: The system will release all resources occupied by the kernel and exit the kernel running state.
  • 6. Restart the computer: The system will send a restart command to the computer, the computer will restart and load the operating system.

Similar reboot commands:

system reboot
shutdown -r now
init 6

shutdown shutdown

[root@localhost ~]# shutdown --help
shutdown [OPTIONS...] [TIME] [WALL...]

Shut down the system.

     --help      Show this help
  -H --halt      Halt the machine
  -P --poweroff  Power-off the machine
  -r --reboot    Reboot the machine
  -h             Equivalent to --poweroff, overridden by --halt
  -k             Don't halt/power-off/reboot, just send warnings
     --no-wall   Don't send wall message before halt/power-off/reboot
  -c             Cancel a pending shutdown

poweroff is used to shut down the computer

halt is used to shut down the computer or enter a down state. Some systems call shutdown -h or poweroff

Let’s take a closer look at the differences in system operation levels:

First, let’s clarify that the runlevel runlevel of the Linux/redhat system is different from the runlevel of the debian system.

The runlevel definition of the redhat system is as follows:

  • runlevel 0: halt system downtime, the system default running level cannot be set to 0, otherwise it cannot start normally
  • runlevel 1: single user single user working status, root permissions, used for system maintenance, prohibit remote login
  • runlevel 2: multiuser without network multiuser status (no NFS)
  • runlevel 3: multiuser is fully multiuser state (with NFS), log in and enter the console command line mode
  • runlevel 4: unuse The system is not used, reserved
  • runlevel 5: x11 X11 console, log in and enter the graphics GUI mode
  • runlevel 6: The reboot system is shut down and restarted normally. The default run level cannot be set to 6, otherwise it cannot start normally

In debian/ubuntu, the definition of runlevel is:

0 - Halt
1 - Single
2 - Full multi-user with display manager (GUI)
3 - Full multi-user with display manager (GUI)
4 - Full multi-user with display manager (GUI)
5 - Full multi-user with display manager (GUI)
6 - Reboot

You can find that there is no difference between level 2 and 5.

The default running level of Ubuntu system is 2.

Therefore, we can use init 0 to perform halt shutdown and init 6 to perform reboot.

In fact, the shutdown command is also after executing a series of operations, such as closing the process/service one by one, calling sync to write data to disk, etc., and then calling init0 or init6 to perform shutdown or restart. Halt actually calls shutdown -h now. You can ignore the current state of the system and shut down directly. However, in some systems, halt will not turn off the power, but only turn off os.

Problem description

Reboot has hanged dead. Reboot was stuck when it was shut down for nearly half an hour before it could shut down. There was no abnormality in the restart power-on process.

environment:

CentOS Stream release 8
Linux 4.18.0-500.el8.x86_64
systemd 239 (239-76.el8)

Problem solving attempt

First of all, of course, I started with the system. I checked the content recorded on /var/log/messages and found that there was no error message.

I didn't care too much, I'll use it directlyyum updateUpdated my system and tried again

1. Baidu seeks medical treatment and asks for medicine, modify /etc/systemd/, modify system parameters, but it has not improved. This plan does not apply to my situation.

2. If you try other reboot solutions, the command will be as follows:

system reboot
shutdown -r now
init 6

3. Finally try to usereboot -f,The system reboot is normal at this time, and no restart is found to be dead

20230914 The reboot shutdown was solved, and the solution is as follows:

1. Create /etc/systemd/system/ and write it

	[Unit]
	Description=/etc// Compatibility
	ConditionFileIsExecutable=/etc//
	After=
	[Service]
	Type=forking
	ExecStart=/etc// start
	TimeoutSec=5
	RemainAfterExit=yes

2. Backup /etc/systemd/

cp -a /etc/systemd/ /etc/systemd/system.conf_bak

3. Modify the file

sed -i 's/#DefaultTimeoutStopSec=90s/DefaultTimeoutStopSec=30s/g' /etc/systemd/

4. Reload

systemctl daemon-reload

What is the difference between these commands?

Only know at presentreboot -fIt will forcefully restart the computer and do not call the shutdown command function. It looks different from the ordinary restart operation. It may cause data loss. Judging from the description, many actions have been done.

The actions of the reboot command OS:

1. End all running processes: The system will send a SIGTERM signal to all running processes to notify them that the system will be restarted soon.

2. Save the current system status: The system will save the current system status to the /var/log/wtmp file, including the system's running time, user login information, etc.

3. Stop all devices: The system will stop all devices from running, including disks, network devices and other hardware devices.

4. Restart the computer: The system will send a restart command to the computer, the computer will restart and load the operating system.

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.