Sometimes, you need to turn your Raspberry Pi off! Maybe you need to move it, or connect something to the GPIO pins and don’t want to be concerned about shorts. Or, perhaps you just don’t want it to be draining power when you’re not using it!
Whatever your reason, you’ll want to make sure to do it the right way. This guide will show you how.
Why Shouldn’t You Just Pull the Plug?
There’s no denying that pulling the power cord from your Raspberry Pi will definitely shut it down. After all, it’s not going to work without any power. However, this is far from the best way to shut down your Raspberry Pi.
In fact, it’s generally recommended that you never turn a computer off this way.
There are a few reasons that this can be a bad idea. First, if your operating system is writing anything to the file system of your Raspberry Pi, you might well find that interrupting this by removing the power cord can severely damage your system.
It’s unlikely to cause physical damage – although we’ll discuss that a little more in a bit.
However, a write to the file system that gets interrupted essentially means that that file is corrupted from now on. If this is a critical system file then it could well be game over for your operating system.
At the very least, you may well have to do hours of work to get into a workable state again – it may well even be that you’ll be better off reinstalling completely. This obviously is far from ideal!
There is a small chance of physical damage when simply removing the power cord from your Raspberry Pi too.
It’s unlikely and shouldn’t really be a cause of major concern – but for safety’s sake, it’s best to make sure that you shut down the computer using the correct methods before you pull the power cord.
There’s an increased risk of this if you’re using a mechanical hard drive, as the spinning and moving parts of these don’t respond well to a sudden power loss.
Of course, if you simply have to shut down your Raspberry Pi immediately and the only way that you can reasonably do it is by pulling the plug, then that’s what you’ll have to do – but just be aware that in pretty much every circumstance it’s the worst way to do it!
How To Shut Down A Raspberry Pi From The Desktop
If you’re not too familiar with the command line, then this may well be the easiest way for you to shut down your Raspberry Pi.
In fact, if you’re used to working within Microsoft Windows, then you’ll likely already be familiar with this method of shutting down your pc – as it’s essentially almost identical to the way that you’d do it on Windows.
That’s because this method doesn’t use the command line or terminal at all. Of course, it’s really useful to learn the command line – and highly recommended that any Linux users learn to do at least some basic things on the command line.
Still, it’s actually really quick and simple to shut down your Raspberry Pi without using the command line. You need to be at the desktop – and you’ll also need a mouse plugged into the Raspberry Pi, and sometimes it will need a heatsink.
Looking at the Raspberry Pi desktop screen you should notice in the bottom left corner of the screen that there is a Raspberry symbol. If you’re used to using Windows you’ll find it in the same place that the windows or start button usually is.
Click this icon, and then you should see a menu appear much like the start menu on Windows. At the bottom of this menu, you’ll see the word shutdown with an icon next to it. Click this, and you’ll be presented with another menu.
This menu will have three options – shutdown, reboot, and logout.
Choosing the shutdown option will power down your Raspberry Pi safely.
It will take a few seconds to complete the process, but doing it this way means that your Raspberry Pi will go through all the steps that are necessary to make sure that your operating system and file system are ready to be turned off safely.
Choosing the reboot option will essentially perform the same task as choosing the shutdown option – however, your system will power on again immediately after the shutdown is complete.
Finally, the logout option is for if you wish to change users. If you’ve got multiple users registered on your Raspberry Pi, then this is how you log out of 1 user account and into another user account.
How To Shut Down A Raspberry Pi From The Command Line
Of course, many Raspberry Pi users won’t actually be using the desktop environments at all. For instance, many users are running the Raspberry Pi in what’s commonly called headless mode – which means that it’s being run without having a display connected at all.
In fact, many Raspberry Pi users not only don’t use a display, but they don’t have a keyboard or mouse plugged directly into their Raspberry Pi at all – but instead connect to the computer remotely.
Whether you’re executing these commands directly on the Raspberry Pi, or you’re connecting to your Raspberry Pi remotely from another computer, you’ll be able to control practically everything on your Raspberry Pi from the command line.
And of course this also includes being able to shut down your Raspberry Pi from the command line. There are a few different commands that you can use to shut down and/or power cycle your Raspberry Pi.
First up we have the halt command. This is one of the oldest commands that you can use when trying to shut down your Raspberry Pi.
The problem with this command is that it doesn’t actually turn off your Raspberry Pi. Instead it just stops the CPU from working.
So while your Raspberry Pi may still be powered on and running some programs it won’t be able to access any external devices such as USB drives or network cards.
The second command that you can use to shut down your Raspberry Pi is the shutdown command. This command works exactly the same as the halt command except that it actually turns off your Raspberry Pi completely.
The third command that you can use is the power-off command.
This command is similar to the shutdown command except that instead of turning off your Raspberry Pi it simply puts it into a low power state where it’s still fully operational but is no longer receiving any new instructions from the CPU.
Now, there’s a fourth command that you can use and that’s the reboot command. This command is very similar to the shutdown command because it basically does the exact same thing as the shutdown command.
However, unlike the shutdown command, the reboot command doesn’t put your Raspberry Pi into a low power state. Instead, it reboots your Raspberry Pi so that it starts back up again as if it was first booted up.
For most people the shutdown command is the one that they’re going to want to use. After all, it’s the only one that will actually fully power off the Raspberry Pi.
To execute this command simply type the following into the terminal.
sudo shutdown -h now
Remember as with all Linux terminal commands to make sure that you’ve typed everything correctly including making sure that each letter is the correct case. Linux is case-sensitive so using a capital letter in the wrong place will mean that commands won’t work!
This command will give your Raspberry Pi the instruction to shut down and power off immediately. It will make sure to go through all the necessary steps, of course – which means that it may take a bit of time to fully shutdown.
Practically every Raspberry Pi owner will need to shut down their system at some point. Hopefully this guide has helped you learn how to do it correctly and safely!