Linux notes (v) Correct shutdown method (Shutdown,reboot,init,halt)

Source: Internet
Author: User

Because under Linux, every program (or service) runs in the background, so there may be quite a few people working on your console at the same time behind a screen you can't see, and if you just press the power switch to shut down, it could cause other people's data to be interrupted. In addition, the biggest problem is that if the abnormal shutdown, due to the late to write data back to the file, which may cause the file system damage. Therefore, the correct Linux system shutdown posture is very important.

Under normal circumstances, there are a few things to keep in mind when shutting down:

    • Observe the status of the system: if you want to see who is currently online, you can use the WHO directive, if you want to see the online status of the network, you can use netstat-a this command, to see the background execution of the program can be used ps-aux this command.
    • Notify online users of the moment of shutdown: to give online users some time to end their work before shutting down, this can be done using shutdown's special instructions.
    • The correct shutdown instructions are used: for example shutdown and reboot.

    • Instructions for synchronizing data to the hard disk: Sync
    • Customary shutdown instruction: shutdown
    • Restart, shutdown: Reboot,halt,poweroff
    • Data synchronously written to disk: Sync

In the Linux system, in order to speed up the data read speed, so, in the default case, some data will not be directly written to the hard disk, but the first in memory. But that's what happens when you restart the computer, or if it is powered off, or if it is an abnormal power outage, the data is not being updated because the data has not been written to the hard drive. At this point, the Sync command is required to write the data. Enter sync directly under the text interface, then the data that has not been updated in memory is written to the hard disk. (Note: This command can only be performed by Root)

    • Customary shutdown instruction: shutdown

Because there are various limiting factors in the shutdown, only Root has the power to shut down the machine. What we use more often is the shutdown directive, which notifies each program within the system (processes) and shuts down some of the services within the Run-level in the notification system.

[[email protected] ~]# shutdown [-t time] [-ARKHNCFF] [TIME] [WARNING] parameter:-T sec:-Thenumber of seconds followed by "shutdown after a few seconds" means -k< c3/>: Not really shutdown, just send a warning message out -R       : Restart the system after the service is stopped -h: Shut down the      system immediately after the shutdown-n      : Shut down directly with shutdown function without the init program -F      : After shutting down and powering on, force a disk check over fsck -F     : Force fsck to disk check after system reboot -C     

In addition, it is important to note that the time parameter must be added, otherwise it will automatically jump to Run-level1 (that is, the single-person maintenance log in the case)

 [[email protected] ~]# shutdown-h now shuts down [[email protected]  ~] # shutdown-h 20 :  The system shuts down at 20:25 today [[email protected]  ~]# shutdown-h +10   The system automatically shuts down after 10 minutes [[email protected]  ~]# shutdown-r now system restarts immediately [[email  Protected]  ~] #shutdown-R +30   " Span style= "color: #800000;" >the system will reboot   "  in 30 minutes, it restarts. and displays the following message [[email protected]  ~]# shutdown-k now  " this system would reboot   "  issue only warning messages  
    • Restart, shutdown: Reboot,halt,poweroff

These three instructions are about the same, and the use is a little different. Reboot is almost the same as Shutdown-r now. However, it is recommended that the data backfill instructions be released once before shutting down the machine or by using sync.

    • Troubleshooting problems with the boot process
The problem of sector confusion
    • If the root directory is not corrupted: Assuming that the disk sector where the error occurred is/DEV/HDA7, the screen should tell you when it is powered on: Press root pass word or ctrl+d: this time Please enter the root password login system:
    1. Enter the root password at the cursor login system, for single stand-alone maintenance work;
    2. Input FSCK/DEV/HDA7 (fsck is the instruction,/DEV/HDA7 is the wrong disk block, according to the situation to release parameters), then the screen will show the start to repair the hard disk information, if any errors are found, will display clear[y/n], the query information, directly enter Y.
    3. The repair is completed to restart the reboot.
    • If the root directory is damaged: General beginners like to divide their hard disk into only a large chunk, that is, only the root directory. That hard disk block confusion must be the root directory problem. At this point, you can unplug the hard drive to another Linux system computer, and do not mount (Mount) the hard disk, and then perform fsck/dev/hdb1 as root (/dev/hdb1 refers to the name of the hard drive device, according to the actual situation to set).
    • If the entire hard drive is broken: it is really bad to change one, if you do not want to change the hard disk, the re-irrigation of Linux, and in the time of the re-irrigation in the format project, select the [Error check] project, so that the format will be very slow, and when it will be broken and uncertain. It's better to change one.

Linux notes (v) Correct shutdown method (Shutdown,reboot,init,halt)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.