How to shutdown linux terminal

6 Commands to Shutdown/Reboot the Linux system from Terminal

Linux administrator performing many tasks in their routine work. The system Shutdown and Reboot task also included in that.It’s one of the risky task for them because some times it wont come back due to some reasons and they need to spend more time on it to troubleshoot.

These task can be performed through CLI in Linux. Most of the time Linux administrator prefer to perform these kind of tasks via CLI because they are familiar on this.

There are few commands are available in Linux to perform these tasks and user needs to choose appropriate command to perform the task based on the requirement.

All these commands has their own feature and allow Linux admin to use it.

When the system is initiated for Shutdown or Reboot. It will be notified to all logged-in users and processes. Also, it wont allow any new logins if the time argument is used.

I would suggest you to double check before you perform this action because you need to follow few prerequisites to make sure everything is fine.

Those steps are listed below.

  • Make sure you should have a console access to troubleshoot further in case any issues arise. VMWare access for VMs and IPMI/iLO/iDRAC access for physical servers.
  • You have to create a ticket as per your company procedure either Incident or Change ticket and get approval
  • Take the important configuration files backup and move to other servers for safety
  • Verify the log files (Perform the pre-check)
  • Communicate about your activity with other dependencies teams like DBA, Application, etc
  • Ask them to bring down their Database service or Application service and get a confirmation from them.
  • Validate the same from your end using the appropriate command to double confirm this.
  • Finally reboot the system
  • Verify the log files (Perform the post-check), If everything is good then move to next step. If you found something is wrong then troubleshoot accordingly.
  • If it’s back to up and running, ask the dependencies team to bring up their applications.
  • Monitor for some time, and communicate back to them saying everything is working fine as expected.
Читайте также:  Linux удалить строку до символа

This task can be performed using following commands.

  • shutdown Command: shutdown command used to halt, power-off or reboot the machine.
  • halt Command: halt command used to halt, power-off or reboot the machine.
  • poweroff Command: poweroff command used to halt, power-off or reboot the machine.
  • reboot Command: reboot command used to halt, power-off or reboot the machine.
  • init Command: init (short for initialization) is the first process started during booting of the computer system.
  • systemctl Command: systemd is a system and service manager for Linux operating systems.

Method-1: How to Shutdown and Reboot the Linux system using Shutdown Command

shutdown command used to power-off or reboot a Linux remote machine or local host. It’s offering
multiple options to perform this task effectively. If the time argument is used, 5 minutes before the system goes down the /run/nologin file is created to ensure that further logins shall not be allowed.

# shutdown [OPTION] [TIME] [MESSAGE]

Run the below command to shutdown a Linux machine immediately. It will kill all the processes immediately and will shutdown the system.

Alternatively we can use the shutdown command with halt option to bring down the machine immediately.

# shutdown --halt now or # shutdown -H now

Alternatively we can use the shutdown command with poweroff option to bring down the machine immediately.

# shutdown --poweroff now or # shutdown -P now

Run the below command to shutdown a Linux machine immediately. It will kill all the processes immediately and will shutdown the system.

If you run the below commands without time parameter, it will wait for a minute then execute the given command.

# shutdown -h Shutdown scheduled for Mon 2018-10-08 06:42:31 EDT, use 'shutdown -c' to cancel. [email protected]# Broadcast message from [email protected] (Mon 2018-10-08 06:41:31 EDT): The system is going down for power-off at Mon 2018-10-08 06:42:31 EDT!

All other logged in users can see a broadcast message in their terminal like below.

[[email protected] ~]$ Broadcast message from [email protected] (Mon 2018-10-08 06:41:31 EDT): The system is going down for power-off at Mon 2018-10-08 06:42:31 EDT!
# shutdown -H Shutdown scheduled for Mon 2018-10-08 06:37:53 EDT, use 'shutdown -c' to cancel. [email protected]# Broadcast message from [email protected] (Mon 2018-10-08 06:36:53 EDT): The system is going down for system halt at Mon 2018-10-08 06:37:53 EDT!
# shutdown -P Shutdown scheduled for Mon 2018-10-08 06:40:07 EDT, use 'shutdown -c' to cancel. [email protected]# Broadcast message from [email protected] (Mon 2018-10-08 06:39:07 EDT): The system is going down for power-off at Mon 2018-10-08 06:40:07 EDT!

This can be cancelled by hitting shutdown -c option on your terminal.

# shutdown -c Broadcast message from [email protected] (Mon 2018-10-08 06:39:09 EDT): The system shutdown has been cancelled at Mon 2018-10-08 06:40:09 EDT!

All other logged in users can see a broadcast message in their terminal like below.

[[email protected] ~]$ Broadcast message from [email protected] (Mon 2018-10-08 06:41:35 EDT): The system shutdown has been cancelled at Mon 2018-10-08 06:42:35 EDT!

Add a time parameter, if you want to perform shutdown or reboot in N seconds. Here you can add broadcast a custom message to logged-in users. In this example, we are rebooting the machine in another 5 minutes.

# shutdown -r +5 "To activate the latest Kernel" Shutdown scheduled for Mon 2018-10-08 07:13:16 EDT, use 'shutdown -c' to cancel. [[email protected] ~]# Broadcast message from [email protected] (Mon 2018-10-08 07:08:16 EDT): To activate the latest Kernel The system is going down for reboot at Mon 2018-10-08 07:13:16 EDT!

Run the below command to reboot a Linux machine immediately. It will kill all the processes immediately and will reboot the system.

Читайте также:  Обновление драйверов nvidia linux mint

Method-2: How to Shutdown and Reboot the Linux system using reboot Command

reboot command used to power-off or reboot a Linux remote machine or local host. Reboot command comes with two useful options.

It will perform a graceful shutdown and restart of the machine (This is similar to your restart option which is available in your system menu).

Run “reboot’ command without any option to reboot Linux machine.

Run the “reboot” command with -p option to power-off or shutdown the Linux machine.

Run the “reboot” command with -f option to forcefully reboot the Linux machine (This is similar to pressing the power button on the CPU).

Method-3: How to Shutdown and Reboot the Linux system using init Command

init (short for initialization) is the first process started during booting of the computer system.

It will check the /etc/inittab file to decide the Linux run level. Also, allow users to perform shutdown and reboot the Linux machine. There are seven runlevels exist, from zero to six.

Run the below init command to shutdown the system .

Run the below init command to reboot the system .

Method-4: How to Shutdown the Linux system using halt Command

halt command used to power-off or shutdown a Linux remote machine or local host.
halt terminates all processes and shuts down the cpu.

Method-5:How to Shutdown the Linux system using poweroff Command

poweroff command used to power-off or shutdown a Linux remote machine or local host. Poweroff is exactly like halt, but it also turns off the unit itself (lights and everything on a PC). It sends an ACPI command to the board, then to the PSU, to cut the power.

Method-6: How to Shutdown and Reboot the Linux system using systemctl Command

Systemd is a new init system and system manager which was implemented/adapted into all the major Linux distributions over the traditional SysV init systems.

Читайте также:  Linux tar and untar

systemd is compatible with SysV and LSB init scripts. It can work as a drop-in replacement for sysvinit system. systemd is the first process get started by kernel and holding PID 1.

It’s a parent process for everything and Fedora 15 is the first distribution which was adapted systemd instead of upstart.

systemctl is command line utility and primary tool to manage the systemd daemons/services such as (start, restart, stop, enable, disable, reload & status).

systemd uses .service files Instead of bash scripts (SysVinit uses). systemd sorts all daemons into their own Linux cgroups and you can see the system hierarchy by exploring /cgroup/systemd file.

# systemctl halt # systemctl poweroff # systemctl reboot # systemctl suspend # systemctl hibernate

Источник

How do I shut down or reboot from a terminal?

Appendix: If your keyboard is «locked up», so you can’t enter a command like «reboot» which would run from «su» anyway, use the keyboard: hold down Alt + PrintScreen/SysRq , buttons and type «REISUB». It doesn’t have to be capital letters. It will restart your computer gently. http://blog.kember.net/articles/reisub-the-gentle-linux-restart/

@NicolasRaoul nopes, for me i see this without sudo . Failed to set wall message, ignoring: Interactive authentication required. Failed to reboot system via logind: Interactive authentication required. Failed to open /dev/initctl: Permission denied Failed to talk to init daemon.

Open your terminal with CTRL + ALT + T and do these following commands

& one more command for restart:

Another way as one of the user mentioned.

You can get more info on the shutdown command by using one of the following:

Can anyone explain why sudo halt might not perform shutdown in some cases, whereas sudo halt -p does?

Hate passwords ( sudo ) and love one-liners?

For Ubuntu 15.04 and later

This is due to Ubuntu’s shift in using systemd instead of Upstart

systemctl poweroff systemctl reboot systemctl suspend systemctl hibernate systemctl hybrid-sleep 

Since hibernate is normally disabled by default in Ubuntu systems, you can enable this by checking this answer.

For Ubuntu 14.10 or earlier

/usr/bin/dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop 
/usr/bin/dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart 

Other commands you may like:

/usr/bin/dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend 

Hibernate: (if enabled on your system)

/usr/bin/dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate 

On 16.04 no need of sudo

sudo shutdown -h (time) (message) 

This will shutdown your computer and halt it. That is what the -h is for. Then, in the time area you can choose the shutdown delay (in minutes) and if you want you can send a broadcast message in the message area (like goodbye, or I’m shutting the thing down :P).

To restart the computer, type

sudo shutdown -r (time) (message) 

Now, instead of shutting it down and halting it, you will restart your computer once it’s shutdown. 🙂

Источник

Оцените статью
Adblock
detector