Shutting down the Raspberry Pi (shutdown)

This recipe shuts down the Linux operating systems so that the Raspberry Pi can be powered off safely.

Before powering down the Raspberry Pi, it is important to first shut down the operating system so that all of the applications and services on the Raspberry Pi have completely finished writing to disk and are ready for the next boot.

External devices, such as hard disks, also need time to shut down and flush their buffers. The shutdown command also gives devices attached to the Raspberry Pi an opportunity to clean up and prepare for the next boot.

Getting ready

The following are the ingredients:

  • An initial Raspberry Pi setup (see the Preparing for the initial boot recipe)
  • An SD card formatted with the official Raspbian Linux image

The Raspberry Pi should already be powered on and booted before starting with this recipe.

How to do it...

The following are the steps for shutting down the Raspberry Pi:

  1. Log in to the Raspberry Pi with pi as the username (the default password is raspberry).
    How to do it...

    The preceding screenshot shows the process of logging in to the Raspberry Pi with pi as the username.

  2. Execute the following command:
    shutdown –h now

    Shut down and halt the operating system. This command is privileged. Use the prefix sudo to run the shutdown command as a privileged user.

    How to do it...

    The preceding screenshot shows how to shut down the Raspberry Pi.

  3. The Raspberry Pi will begin to shut down, displaying messages from applications, devices, and services as they clean up and prepare for the next boot.
  4. Once the operating system has shut down, the Raspberry Pi will halt. Only a single red LED will remain lit on the Raspberry Pi as the Raspberry Pi is still powered on. The main display will be blank.
  5. The power to the Raspberry Pi can now be shut off.

How it works...

Once the Raspberry Pi boots, it prompts for a username and a password. By default, the Raspbian Linux distribution has one user configured, the pi user. This user's default password is raspberry. The password for the pi user can be changed using the raspi-config command.

After login, the shutdown command is executed with the –h option telling the Raspberry Pi to halt the system (power it off) after the operating system has shut down. The shutdown command is privileged, so the sudo command is used as a prefix to temporarily grant privileges.

There's more...

The shutdown command can also be used to reboot the system. Use the –r option. Rebooting the system when logged in as the pi user can be done with the following command:

sudo shutdown –r now

A number of synonyms exist for the shutdown command including halt, poweroff, 'and reboot.

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.115.120