Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Six instructions you have to understand about restarting and shutting down the Linux system

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Linux administrators have many tasks to perform on their schedules, including system reboots and shutdowns.

For Linux administrators, restarting and shutting down systems is one of many risky actions that sometimes, for some reason, may not be reversible and they need more time to troubleshoot the problem.

We can perform these tasks in Linux command-line mode. Many times, Linux administrators prefer to do these tasks from the command line because of their familiarity with the command line.

Linux commands to restart and shut down the system are not many, users need to choose the appropriate command 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.

All logged in users and processes are notified when the system restarts and shuts down. Of course, if the time parameter is used, the system will refuse new users to log in.

Before you do this, I suggest you keep reviewing, because you get very few hints to make sure it all goes well.

Here are some steps:

Make sure you have a console that can handle failures in case problems occur later. VMWare can access virtual machines, while IPMI, iLO, and iDRAC can access physical servers.

You need to go through the company's processes and apply for the right to modify or malfunction the execution until permission is obtained.

For security reasons, backup important configuration files and save them to other servers.

Verify log files (check ahead)

Communicate with related teams, such as database management team, application team, etc.

Notify database and application service personnel to shut down services and receive a positive response.

Verify the work by using the appropriate command to duplicate the disk operation.

Finally, restart the system.

Verify the log file, if everything goes well, proceed to the next step, if any problems are found, troubleshoot.

Notify the relevant team to submit a request whether it is a rollback version or a running program.

Watch the operation properly and give feedback to the team that everything is expected to be OK

Use the following command to perform this task.

shutdown, halt, poweroff, reboot commands: used to shut down, restart or cut off power

The init command is short for "initialization" and is the first process that the system starts.

systemctl command: systemd is the hypervisor for Linux systems and servers.

Scenario 1: How to shut down and restart Linux systems using shutdown

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

The common syntax is as follows:

shutdown [OPTION] [TIME] [MESSAGE]

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

shutdown -h now

-h: This is equivalent to the-poweroff option if the-halt option is not specified.

Alternatively, we can use the shutdown command with the-halt option to shut down the device immediately.

shutdown --halt now

or

shutdown -H now

-H, --halt: stop the equipment

Alternatively, we can use the shutdown command with the poweroff option to shut down the device immediately.

shutdown --poweroff now

or

shutdown -P now

-P, --poweroff: Power off (default).

If you run the following command without the time option, it will give the following result.

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 godown real fast. -c: cancel a running shutdown. -t secs: delay betweenwarning 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.

root@imx6qdlsolo:~# shutdown -r +5 "To activate the latestKernel"

Broadcast message from root@imx6qdlsolo(ttymxc0) (Fri Jun 30 11:51:34 2000):To

activate the latest Kernel

The system is going DOWN for reboot in 5minutes!

Run the following command to immediately restart the Linux machine. It will immediately kill all processes and restart the system.

shutdown -r now

-r, --reboot: Restart the device.

Scenario 2: How to shut down and restart Linux systems with the reboot command

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

It gracefully shuts down and restarts devices (as simple as remembering the restart option in the system menu).

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

reboot

Execute the reboot command with the-p argument to power down the Linux machine.

reboot -p

-p, --poweroff: Call the halt or poweroff command to turn off the power to the device.

Execute the reboot command with the-f argument to force a reboot of the Linux device (this is similar to pressing the power button on the machine).

reboot -f

-f, --force: Force an immediate interrupt, power cut or restart.

Scenario 3: How to shut down and restart Linux via the init command

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

It checks the/etc/inittab file and determines the linux runlevel. It also allows users to perform shutdown or restart operations on Linux devices. There are seven levels of operation from 0 to 6.

Recommended reading:

How to check all running services on Linux

Execute the following init command to shut down the system.

init 0

0: Shutdown-Shut down the system.

Restart the device by running the following init command:

init 6

6: Restart-Restart the device.

Scenario 4: How to shut down and restart Linux via halt

The halt command is used to power down or shut down remote Linux machines or local hosts. Interrupt all processes and shut down cpu.

halt

Scenario 5: How to shut down and restart Linux via poweroff

The poweroff command is used to cut power or shut down remote Linux machines or local hosts. Poweroff is a lot like halt, but it turns off device hardware (lights and other things on the PC). It sends ACPI commands to the motherboard, and then signals to the power supply to turn off the power.

poweroff

Scenario 6: How to shut down and restart Linux via systemctl

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 SysV init system. systemd is the first process launched by the kernel and holds the PID of process number 1.

I take the development board of electric fish electronics as an example to achieve the above steps. Interested small partners can have a look and get more detailed information.

www.dianyu.net

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report