Tag: Systemd

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.

Do services need to be restarted when updating packages

Package configuration: whether to restart the service

During the installation of package updates and their configuration, the apt program may ask you to restart the service:

There are services installed on your system which need to be restarted when certain libraries, such as libpam, libc, and libssl, are upgraded. Since these restarts may cause interruptions of service for the system, you will normally be prompted on each upgrade for the list of services you wish to restart. You can choose this option to avoid being prompted; instead, all necessary restarts will be done for you automatically so you can avoid being asked questions on each library upgrade. Restart services during package upgrades without asking?

This message can be confusing, especially the phrase “cause interruptions of service for the system”. In fact, the essence is quite simple – the binaries have been updated and you need to restart the services that use them so that they start using the updated versions of the files.

The name of the package that requires the service to be restarted is in the upper left corner, in the screenshot it is libc6, i.e. “GNU C Library: Shared libraries”. It contains the standard libraries that are used by nearly all programs on the system. This package includes shared versions of the standard C library and the standard math library, as well as many others.

What kind of interruptions can a service restart cause?

Examples of the consequences of restarting services:

  • at the time of restarting the web server service, sites will be unavailable to users
  • when restarting the caching proxy server, the cache stored in RAM will be deleted
  • restarting network services can lead to connection drops (but in practice this does not always happen)

That is, the possible consequences of restarting services on the home computer are insignificant – you can safely restart.

As far as restarting services on a server, for example, restarting the SSH server usually doesn't break the connection. You need to evaluate the consequences of restarting other services based on your situation.

See also:

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