Linux——(Chapter 4) Shutdown, Restart and User Login and Logout

Table of contents

1. Shutdown and restart commands

2. User login and logout


1. Shutdown and restart commands

        In general, server shutdown operations are rarely encountered.

basic grammar

  • sync : Synchronize data from memory to hard disk (this command is executed before restarting and shutting down).
  • halt : Shut down immediately and shut down the system without powering off.
  • poweroff : shutdown, power off.
  • reboot : Restart immediately, equivalent to shutdown -r now
  • shutdown [options] parameter
    • [ options ]:
      • - H : Equivalent to -- halt, shutdown
      • -r : -r =reboot
    • Parameters :
      • now : shut down immediately
      • Time : How long to wait before shutting down (time unit is minutes)

Note :

In order to improve the reading and writing efficiency of the disk in the Linux system, the "read ahead and write later" operation method         is adopted for the disk . When a user saves a file, the Linux kernel does not necessarily write the saved data to the physical disk immediately. Instead, it saves the data in the buffer and then writes it to the disk when the buffer is full. This method can greatly improve the disk performance. The efficiency of writing data. However, it also brings security risks. If the system loses power or other serious problems occur before the data is written to the disk, data will be lost. Use the sync command to write the buffer's data to disk immediately.

        Why do I have to wait for one minute when using shutdown? Because shutdown also has the function of synchronizing data, the data needs to be synchronized to the hard disk before shutting down.

Grammar example :

(1) Shut down immediately

        shutdown -h now

(2) Shut down after one minute

        shutdown -h 1

(3) Restart immediately

        shutdown -r now

(4) Shut down after two minutes

        shutdown -r 2

(5) Synchronize data from memory to hard disk

        sync

(6) Uninterruptible power supply during shutdown

        halt

2. User login and logout

        When logging in, avoid using the root account (system administrator). The system administrator has greater authority to avoid operational errors. You can log in as an ordinary user. After logging in, use the " su - username" command to switch to the system administrator identity.

Enter logout          at the prompt  to log out the user [different shell commands may be different (exit)]

        The logout command has no effect at the image run level and is valid under run level 3 .

        There are 7 runlevels in Linux systems: the commonly used ones are level 3 and level 5.

  • Run level 0: The system is in shutdown state. The default run level of the system cannot be set to 0, otherwise it will not start normally.
  • Run level 1: single-user working state, root authority, used for system maintenance, remote login is prohibited.
  • Runlevel 2: Multi-user state (no NFS), no networking support.
  • Run level 3: Complete multi-user state (with NFS), enter console command mode after logging in.
  • Run level 4: The system is not in use and reserved.
  • Run level 5: X11 console, enter graphical GUI mode after logging in.
  • Run level 6: The system shuts down and restarts normally. The default run level cannot be set to 6, otherwise it will not function normally.        

Guess you like

Origin blog.csdn.net/m0_45447650/article/details/131932757