Tag: OS shutdown

What is the difference between “systemctl reboot” and “reboot” and “systemctl poweroff” and “poweroff”

What's the difference between

sudo systemctl reboot

And

sudo reboot

Is it true that the use of commands depends on the operating system, and that one will execute a shorthand version, the other will use systemctl?

Answer:

The halt, poweroff, reboot commands are implemented to maintain basic compatibility with the original SysV commands. Verbs

  • systemctl halt
  • systemctl poweroff
  • systemctl reboot

provide the same functionality with some additional features.

That is, reboot is now also systemctl. You can verify this:

which reboot
/usr/sbin/reboot

file /usr/sbin/reboot
/usr/sbin/reboot: symbolic link to /bin/systemctl

That is, the reboot command is actually a symbolic link to systemctl.

In turn, the command

systemctl reboot

is an abbreviation for

systemctl start reboot.target --job-mode=replace-irreversibly --no-block

That is

reboot

this is exactly the same as

systemctl reboot

as well as

systemctl start reboot.target --job-mode=replace-irreversibly --no-block

This is true for distributions that have switched to systemd (for example, Arch Linux, the entire Debian family, including Ubuntu). That is, for most modern distributions, except for those on which SysV remained.

In some cases, the reboot command does not work – see Error “Failed to talk to init daemon” for details. In this case, to restart the computer, you must add the -f option:

reboot -f

The shutdown command is:

poweroff -f

Even if these commands did not help, then use the options with the double option -f.

To turn off your computer do:

poweroff -f -f

Or restart your computer with the command:

reboot -f -f

The -f option means forced immediate stop, shutdown, or reboot. When specified once, this results in an immediate but clean shutdown by the system manager. If specified twice, it results in an immediate shutdown without contacting the system manager.

When using the -f option with systemctl halt, systemctl poweroff, systemctl reboot, or systemctl kexec, the selected operation is performed without shutting down all units. However, all processes will be forcibly terminated, and all file systems will be unmounted or remounted read-only. Therefore, it is a radical, but relatively safe option to request an immediate restart. If you specify --force twice for these operations (except for kexec), they will be executed immediately, without killing any processes or unmounting any filesystems. Warning: specifying --force twice for any of these operations can result in data loss. Note that if you specify --force twice, the selected operation is performed by systemctl itself and is not associated with the system manager. This means that the command must be executed even if the system manager fails.

How to restart computers in PowerShell

Restart-Computer Cmdlet

The Restart-Computer cmdlet restarts the operating system on a local or remote computer.

The following command will reboot the local computer:

Restart-Computer

You can use Restart-Computer with various parameters to trigger restart operations, to specify authentication levels and alternate credentials, to restrict operations to be performed simultaneously, and to restart immediately.

Starting with Windows PowerShell 3.0, you can wait until the reboot is complete before running the next command. Specify the timeout and request interval and wait for certain services to be available on the rebooted computer. This feature makes it practical to use Restart-Computer in scripts and functions.

Restart-Computer only works on Windows computers and requires WinRM and WMI to shut down the system, including the local one.

Example of restarting multiple computers:

Restart-Computer -ComputerName Server01, Server02, localhost

The -ComputerName <String[]> option specifies a single computer name or an array of computer names separated by commas. Restart-Computer accepts ComputerName objects from a pipeline or variables.

Enter the NetBIOS name, IP address, or fully qualified domain name of the remote computer. To specify the local computer, enter the computer name, period “.” or “localhost”.

This parameter is independent of PowerShell remoting. You can use the -ComputerName parameter even if your computer is not configured to run remote commands.

If the -ComputerName parameter is not specified, Restart-Computer restarts the local computer.

If you are restarting a remote computer, you will most likely need the -Credential <PSCredential> option, which specifies a user account that has permission to perform this action. By default, this is the current user.

Enter a username, such as User01 or Domain01\User01, or enter the PSCredential object generated by the Get-Credential cmdlet. If you enter a username, you will be prompted for a password.

The credentials are stored in the PSCredential object (/dotnet/api/system.management.automation.pscredential) and the password is stored as SecureString (/dotnet/api/system.security.securestring).

The following example reboots computers whose names are obtained from a text file:

Get-Content -Path C:\Domain01.txt | Restart-Computer

Get-Content uses the -Path parameter to get a list of computer names from the Domain01.txt text file. Computer names are sent down the pipeline. Restart-Computer restarts every computer.

Forced restart of computers listed in the text file:

$Names = Get-Content -Path C:\Domain01.txt
$Creds = Get-Credential
Restart-Computer -ComputerName $Names -Credential $Creds -Force

Get-Content uses the -Path parameter to get a list of computer names from the Domain01.txt text file. Computer names are stored in the $Names variable. Get-Credential prompts you for a username and password and stores the values in the $Creds variable. Restart-Computer uses the -ComputerName and -Credential parameters with their variables. The -Force option causes each computer to restart immediately.

Restarting the remote computer and waiting for it to turn on to execute PowerShell:

Restart-Computer -ComputerName Server01 -Wait -For PowerShell -Timeout 300 -Delay 2

Restart-Computer uses the -ComputerName parameter to restart Server01. The -Wait parameter makes the command wait for the restart to complete. -For sets PowerShell to run commands on the remote computer. The -Timeout parameter sets a five minute wait. The -Delay parameter polls the remote computer every two seconds to determine if it has restarted.

Restarting your computer using WsmanAuthentication:

Restart-Computer -ComputerName Server01 -WsmanAuthentication Kerberos

Restart-Computer uses the -ComputerName parameter to restart the Server01 remote computer. The -WsmanAuthentication parameter specifies the Kerberos authentication method.

Error “Unable to initiate a system shutdown because the computer is being used by other users”

When restarting a remote computer, for example:

Restart-Computer -ComputerName Win-Server-Core -Credential Administrator

an error may occur

Restart-Computer: Failed to restart the computer Win-Server-Core with the following error message: System shutdown cannot be initiated because the computer is in use by other users.

This error occurs if any user is logged in to the remote computer, use the -Force option to force reboot:

Restart-Computer -ComputerName Win-Server-Core -Credential Administrator -Force

Restarting the computer without PowerShell

Without PowerShell, you can restart your computer with the following command:

shutdown /r

You will be shown a warning and the computer will restart after 30 seconds.

To restart your computer immediately, run the command:

shutdown /r /t 0

You can add the /f option to the command, which means forcibly closing running applications without warning users. The /f parameter is implied if the /t parameter is set to a value greater than 0.

Error “Failed to talk to init daemon” (SOLVED)

You can use command line to shutdown Linux computer, following command will shutdown computer:

shutdown -h now
systemctl halt

To reboot, you can use the following command:

systemctl restart

They usually work fine, but on some distributions they require elevated privileges, which means they need to be run with sudo.

But in single user mode, these commands result in the following error:

System has not been booted with systemd as init system (PID 1). Can’t operate.
Failed to connect to bus: Host is down
Failed to talk to init daemon.

Linux single user mode is used, for example, to reset a forgotten password for the root user or any other user. The operation of the computer in this mode is different from normal and, as you can see from the error message, the system was not booted with systemd as the init of the system, so it cannot connect to the bus and cannot send commands to the init daemon.

Related: How to reset a forgotten login password in Linux

However, there is still a way to turn off the computer.

To log out safely, type:

sync
umount /

These commands instruct the OS to write the changes made to the file system (for optimization purposes, they can be stored in the cache), and then unmount the root file system.

After that, to turn off the computer, run:

poweroff -f

Or restart your computer with the command:

reboot -f

Even if these commands did not help, then use the double -f options.

To turn off your computer run:

poweroff -f -f

Or restart your computer with the command:

reboot -f -f

The -f option means forced immediate stop, shutdown, or reboot. When specified once, this results in an immediate but clean shutdown by the system manager. If specified twice, it results in an immediate shutdown without contacting the system manager.

When using the -f option with systemctl halt, systemctl poweroff, systemctl reboot, or systemctl kexec, the selected operation is performed without shutting down all units. However, all processes will be forcibly terminated, and all file systems will be unmounted or remounted read-only. Therefore, it is a radical, but relatively safe option to request an immediate restart. If you specify --force twice for these operations (except for kexec), they will be executed immediately, without killing any processes or unmounting any filesystems. Warning: specifying --force twice for any of these operations can result in data loss. Note that if you specify --force twice, the selected operation is performed by systemctl itself and is not associated with the system manager. This means that the command must be executed even if the system manager fails.

Loading...
X