Linux study notes - shutdown and restart command

1.13. Shutdown and restart command

For systems using systemd there is no difference because halt, poweroff, reboot, telinit, shutdown are all symlinked to /bin/systemctl.

E.g:

[root@localhost ~]# ll /usr/sbin/poweroff

lrwxrwxrwx. 1 root root 16 Apr 22 16:00 /usr/sbin/poweroff -> ../bin/systemctl

1.13.1.shutdown

shutdown command

The data will be saved correctly until it is shut down or restarted.

Note: Do not shut down the server easily, and avoid going to the computer room to start it

 

    Some users will use direct power off to shut down linux, which is very dangerous. Because linux is different from windows, there are many processes running in the background, so forced shutdown may cause data loss of the process, make the system in an unstable state, and even damage hardware devices in some systems. And using the shutdown command before the system shuts down, the system administrator will notify all logged in users that the system will be shut down. And the login command will be frozen, that is, new users can no longer log in. It is possible to shut down directly or delay the shutdown for a certain period of time, and it is also possible to restart. This is determined by all processes (process) will receive the signal sent by the system (signal). This gives programs like vi time to store the document currently being edited, while programs like mail and news can leave normally, and so on.

     shutdown does its job by sending a signal to the init program, asking it to change the runlevel. Runlevel 0 is used to halt [halt], runlevel 6 is used to restart [reboot] the system, and runlevel 1 is used to bring the system into a state where administrative work can proceed; this is the default, assuming no -h There is also no -r parameter to shutdown. To understand what actions are taken during a shutdown (halt) or reboot (reboot), you can see the information about these runlevels in the file /etc/inittab.

 

 

Syntax: shutdown [options] time

 

-c cancels the previous shutdown command

-h shutdown

-r restart

 

shut down now

shutdown –h now 

 

restart now

shutdown –r now

 

8 o'clock off

shutdown –h 20:00

 

cancel shutdown

shutdown -c

 

 

1.13.2.halt shutdown

In fact, halt is to call shutdown -h. When halt is executed, the application process is killed, the sync system call is executed, and the kernel is stopped after the file system write operation is completed.

 

This command is not very reliable and can easily cause damage to the system.

I tried it just now, my virtual machine can't be shut down, and the connection can't be connected. Finally, the virtual machine was forced to shut down and restarted before it could be connected.

 

Use this command with caution.

1.13.3.poweroff shutdown

Direct power failure may result in data loss.

Halt and poweroff are equivalent to turning off the computer directly (not recommended)

1.13.4.init 0 shutdown

 

 

system run level

0 shutdown

1 Single user similar to Windows Safe Mode, command line interface

2 Incomplete multi-user, no NFS service, command line interface, NFS may have security risks.

3 fully multi-user

4 Unassigned

5 Graphical interface, like Windows, non-command line

6 Reboot

 

You can view the runlevel in the system

It seems to be used in redhat7

[root@localhost ~]# cat /proc/version

Linux version 3.10.0-693.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Tue Aug 22 21:09:27 UTC 2017

 

 

[root@localhost ~]# cat /etc/inittab

# inittab is no longer used when using systemd.

#

# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.

#

# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target

#

# systemd uses 'targets' instead of runlevels. By default, there are two main targets:

#

# multi-user.target: analogous to runlevel 3

# graphical.target: analogous to runlevel 5

#

# To view current default target, run:

# systemctl get-default

#

# To set a default target, run:

# systemctl set-default TARGET.target

#

[root@localhost ~]#

 

 

View the current runlevel

N represents the last run level.

[root@localhost system]# runlevel

N 3

[root@localhost system]#

 

 

 

1.13.5.reboot

      The reboot process is almost the same as the halt, but it causes the host to reboot, while the halt is a shutdown. Its parameters are similar to halt.

 

From this point of view, reboot is not very reliable.

 

 

 

1.13.6.init 6 reboot

 

 

1.13.7.logout

logout command

Lock the screen to prevent the server from being illegally operated by others.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325959643&siteId=291194637