7 Methods to Reboot Linux Using the Terminal

7 Methods to Reboot Linux Using the Terminal

Restarting Linux from the terminal can seem intimidating at first glance, but it becomes a breeze once you familiarize yourself with the essential commands. Regularly rebooting Linux is crucial for applying updates, resolving issues, or performing maintenance. This practice not only ensures that changes take effect but also stabilizes the system. For system administrators managing remote Linux servers, knowing how to restart Linux from the terminal is paramount. Whether you need an immediate reboot, a scheduled shutdown, or a forceful restart, you’ll find methods tailored to every circumstance. Let’s explore various approaches to restarting Linux using the terminal effectively.

1. The Reboot Command

The reboot command is the go-to for gracefully terminating all running processes. This command ensures that open tasks are closed safely, thereby preserving data integrity and system stability. If you want to initiate an immediate restart of your Linux system, you can execute:

sudo reboot

After entering the command, provide your user password and press Enter to proceed with the restart:

Reboot

If you need to force an immediate reboot, you can use the -f option with the reboot command:

sudo reboot -f

This command will reboot your system immediately, overriding any running processes or scheduled shutdowns.

2. The Shutdown Command

The shutdown command is versatile, enabling both immediate reboots and scheduled restarts. By utilizing the -r option, you can instruct the system to restart instantly:

sudo shutdown -r now

For a delayed reboot, say after two hours, you would enter:

sudo shutdown -r +120

Scheduled Reboot

If you decide to cancel a scheduled restart, use the -c option:

sudo shutdown -c

Cancel Scheduled Reboot

3. Employing the systemctl Command

For modern Linux distributions utilizing systemd, the recommended method to restart is:

sudo systemctl reboot

This command ensures that all processes are properly handled before executing the restart.

4. Using the init Command

Older Linux distributions that rely on SysVinit can perform a restart using:

sudo init 6

Executing init 6 shifts the system to runlevel 6, preparing it for a reboot by shutting down processes and unmounting filesystems. While this command remains functional on some setups, it is advisable to use systemctl reboot for compatibility with newer systems.

5. The telinit Command

The telinit 6 command prompts the system to transition to runlevel 6, initiating a safe reboot:

sudo telinit 6

This method guarantees the system restarts via the prescribed shutdown protocol.

6. Utilizing the REISUB Key Sequence

If your Linux system becomes unresponsive, you can safely reboot using the REISUB key sequence (an acronym for the actions).This method leverages the SysRq (System Request) feature and prevents data corruption during restart. Here’s how it works: hold down the Alt + SysRq (Print Screen) keys while following this key sequence:

  • R: Switch the keyboard to raw mode, disengaging control from applications.
  • E: Sends terminate signals to all running processes.
  • I: Issues kill signals to all processes.
  • S: Forces a disk sync, safeguarding data integrity.
  • U: Remounts all filesystems to read-only, mitigating risks of corruption.
  • B: Initiates an immediate system reboot.

This approach is incredibly useful in scenarios where the system is non-responsive but still responsive to keyboard commands.

7. Restarting Linux via SSH

When managing a Linux server remotely, you can easily restart the system by first connecting via SSH:

ssh user@your-server-ip

Connect Remotely with ssh

Once connected, you can proceed to restart the system immediately:

sudo reboot

Should you wish to set a scheduled reboot instead, you can execute the following:

sudo shutdown -r +10 # Reboots after 10 minutes

Schedule Restart Remotely

You can also cancel a scheduled restart at any time using:

sudo shutdown -c

Cancel Scheduled Restart

Ensure you have the necessary permissions to perform these commands, and you’re set to manage your server efficiently!

Final Thoughts

Mastering the art of restarting Linux from the terminal is invaluable for any user. Whether you require an instant reboot, a timed restart, or need to recover from a locked system, Linux offers a suite of commands to address any situation. While systemctl reboot is ideal for modern distributions, older systems can still rely on init and telinit. For those overseeing Linux remotely, SSH provides a straightforward method for server restarts. With these strategies, you can confidently reboot your system directly from your terminal whenever the need arises.

Frequently Asked Questions

1. What is the difference between the `shutdown` command and the `reboot` command?

The `shutdown` command is more versatile as it allows you to schedule a reboot or power off the system, while the `reboot` command immediately restarts the system without waiting.

2. How can I safely restart an unresponsive Linux system?

In case of an unresponsive system, you can use the REISUB key sequence to safely reboot it. This method ensures that data integrity is maintained during the process.

3. Can I restart a Linux server remotely via SSH?

Absolutely! You can connect to your server using SSH and execute commands like `sudo reboot` or `sudo shutdown -r now` to restart the system remotely.

Source & Images

Leave a Reply

Your email address will not be published. Required fields are marked *