How to Safely Shutdown Raspberry Pi

Some of the most common issues that Raspberry Pi users deal with are caused by improper shutdown practices. 

The Raspberry Pi does not come with a power button and so many people’s first instincts are to yank out the power cord to turn it off. Don’t worry – we’ve all been there! However, this is not good for your Pi and can have very negative effects on your machine.

Pulling out the cord to turn off the power is going to corrupt data on your SD card and file system at some point. 

You will also find that anything chugging away and happily running will be brought to an abrupt stop when you pull out the cord. These forced exits are likely to cause serious data loss because nothing is saved. Depending on what you are running, you may lot lose an extortionate amount of data, but why risk it?

So, you need to find a way that will gently and safely shut down your Raspberry Pi without corrupting anything. Curious? Keep reading to find out how.

How to Safely Shutdown Raspberry Pi

Quick Guide

In a rush but still want to safely shut down your Pi? Look no further!

Use commands sudo halt or sudo shutdown -h now to shut down your Pi. These are classic shutdown commands that should work every time. They both do the same thing – shutdown your Pi and halt the reboot process – but the first is a shorthand version. 

You can safely shut down your Pi to reboot using the commands sudo reboot or sudo reboot -r now. These work in the same way as the shutdown commands but will not halt the reboot process, so your Pi will automatically turn back on.

If you are connected to a monitor, turning off your Pi is super easy. You just need to choose shutdown from the drop-down list under Menu. This will do the same thing as executing the shutdown command.

Need some more information? We have gone into more detail below to help you master your Raspberry Pi.

How to Safely Shut down a Raspberry Pi

There are a couple of ways to get a clean Pi shutdown. You want to try to get a clean shutdown every time as these are safer and are going to keep your file system and Raspberry Pi board safe

Shutdown Command

The first method to get a clean shutdown uses the shutdown command. This is the method we recommend if you have a keyboard and screen connected to your Pi. 

You use a superuser do or power user privileges to do this – ‘superuser do’ is why sudo is used as a prefix for a command. These are always available to any Raspberry Pi user unless you have quite drastically changed your user configuration.

Use this command to shut down safely: sudo halt

This command is the shorthand version. If you want, you can use the following command which is the long-winded version but does the same thing: sudo shutdown -h now

Shutdown Command Explained

If you are a Raspberry Pi newbie, it can be difficult to understand what the different components of a command do. We have broken it down to help you to understand it a little more clearly.

sudo – this notifies your Pi to follow the next command.

shutdown – this is the command meaning it is the thing that you want your Pi to do. In this case, you want your Raspberry Pi to shut down.

—h – this means halt. Including this command will have the system after it has shut down meaning it will not reboot.

now this means that the command will be executed immediately. You can include numbers to have your Pi shut down in a specified number of minutes. You could also give a specific time in 24-hour format with a colon.

For example, 5 will make the Pi execute the shutdown command in 5 minutes. 18:12 will make your Raspberry Pi execute the shutdown command at 18:12 in whatever time zone you have set your Pi.

Once the shutdown command has been issued, a SIGTERM signal is sent out to all processes that are running. All running processes will then be able to save and safely exit. As a side note, SIGTERM is just a generic signal that is used to terminate running programs.

After SIGTERM has been sent a SIGKILL is then issued to immediately terminate any processes that are still running. A SIGKILL is a signal that will cause immediate process termination.

After this, all file systems will be unmounted and then the power cord can be removed. This process is a safe shutdown procedure and should be used every time. 

Reboot Command

You can use this method if you want to shut down and then automatically reboot your Raspberry Pi. When has turning it off and on again ever failed!?

This command also uses the superuser privilege.

The command is: sudo reboot

As with the shutdown command, this is the shorthand version. You can use the longer version of this command for the same result.

The longer command is: sudo shutdown -r now

Reboot Command Explained

The processes of the reboot command are very similar to the shutdown command. The only difference is that your Pi will turn back on once the SIGKILL signal has been sent.

sudo– this notifies your Pi to follow the next command

shutdown – this is the command that will shut down your Pi

—r – this is the command to reboot the system after it has been shutdown

now – your Pi will execute the command immediately. As with the shutdown command, you can use numbers to have your Pi shut down in a specific number of minutes, or you can give your Pi a time to execute the reboot.

Use 5 and your Pi will reboot in 5 minutes; use 18:12 and your Pi will reboot at 12 minutes past 6 in the evening.

Shutdown Safely from Desktop

If you have a monitor connected to your Pi, shutting down graphically is super simple. 

You need to first click on Menu from the desktop and then select shutdown from the dropdown menu. 

This is a great method to use if you have a monitor because it is so easy and leaves little room for error. We recommend this method if you do not have a keyboard connected to your Raspberry Pi.

Shutdown Safely Remotely

You could use the time commands to shut down your Pi at a specific time (for example in 5 minutes or at 18:12 – see the above for more information). But how do you do a true remote shutdown on your Raspberry Pi?

We recommend that you try out the Secure Shell Protocol.

For this, you need to have some experience with your Raspberry Pi. This is because you need to know:

How to enable your Pi’s SSH

Your Pi’s IP address

How to SSH into your Pi

Once you know how to do these things, all you need to do now is safely shut down your Pi using any of the three shutdown commands already discussed. These are:

            sudo halt

            sudo shutdown -h now

            sudo shutdown -r now

This is a complex method if you are new to the Raspberry Pi game, and so we will discuss it in detail in another article.

Turning On Your Raspberry Pi

Now you know how to safely turn off your Raspberry Pi, it is important to know how to turn it back on. Thankfully it is very easy to do.

You need to plug a USB power cord into a USB port on your Raspberry Pi. That’s it!

If you have shut down correctly, everything will get back up and running smoothly with no issues.

Final Thoughts

Safely shutting down your Raspberry Pi is easy when you know how. Be sure to follow these instructions so that you are not causing damage to your Pi – no more yanking out the power cord!

It is essential to safely shut down your Pi so that all running processes can be terminated. Pulling out the power cord may corrupt your SD card’s data or corrupt the data stored in the file system. 

Executing commands that will run SIGTERM and SIGKILL signals will also make sure that any changes to running programs or processes are saved. This is vitally important if you are dealing with vast amounts of data.

The commands to safely shut down your Pi are:

            sudo halt

            sudo reboot

            sudo shutdown -h now

            sudo shutdown -r now

Melanie Nilsen
Latest posts by Melanie Nilsen (see all)