Book Image

Raspberry Pi Networking Cookbook - Second Edition

By : Rick Golden
Book Image

Raspberry Pi Networking Cookbook - Second Edition

By: Rick Golden

Overview of this book

<p>With increasing interest in Maker Projects and the Internet of Things (IoT), students, scientists, and hobbyists are using the Raspberry Pi as a reliable, inexpensive platform to connect local devices to Internet services.</p> <p>This book begins with recipes that are essential to installing the Raspberry Pi and configuring it for network access. Then it continues with recipes on installing common networking services such as firewalls and file sharing.</p> <p>The final chapters include recipes for network monitoring, streaming data from the Raspberry Pi to IoT services, and using clusters of Raspberry Pis to store and analyze large volumes of data.</p>
Table of Contents (14 chapters)
Raspberry Pi Networking Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Shutting down the Raspberry Pi


This recipe shows how the Raspberry Pi can be powered off safely.

Before powering off 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 a chance to complete any disk writing that may be in progress and to prepare 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 the devices attached to the Raspberry Pi an opportunity to clean up and prepare for the next boot.

After completing this recipe, you will be able to power off the Raspberry Pi safely.

Getting ready

Here are my ingredients:

  • An Initial Setup for the Raspberry Pi (refer to the Preparing for initiating the boot recipe)

  • An SD card formatted with the official Raspbian Linux image

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

How to do it...

Perform the following steps to shut down the Raspberry Pi:

  1. If you have not already done so, log in to the Raspberry Pi as the user pi (the default password is raspberry):

    Raspbian GNU/Linux 7raspberrypi tty1
    
    Raspberrypi login: pi
    Password:
    
    Last Login: Sun Jun 21 19:45:35 UTC 2015 on tty1
    Linux raspberrypi 3.18.11-v7+ #781SMP PREEEMPT Tue Apr 21 18:07:59 BST 2015armv7l
    
    The programs included with the Debian GNU/Linux system are free software;The exact distribution terms for each program are described in the individual files in /user/share/doc/*/copyright.
    
    Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.
    
    pi@raspberrypi ~ $ 
  2. Shut down and halt (-h) the operating system. This command is privileged. Use the sudo prefix to run the shutdown command as a privileged user, as follows:

    pi@raspberrypi ~ $ sudo shutdown –h now
    
    Broadcast message from root@raspberrypi (pts/0) (Sun Jun 21 19:53:03 2015):
    The system is going down for system halt NOW!
    
  3. After the shutdown command is executed, the Raspberry Pi will begin its shutdown process, 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, leaving only a single red LED lit on the Raspberry Pi (as long as the LEDs are flashing, the Raspberry Pi is still busy shutting down).

  5. The power supply can now be unplugged from the Raspberry Pi.

How it works...

If you have not already logged into the Raspberry Pi, you will need to log in to the Raspberry Pi before shutting it down.

The default user is pi. You should have already changed the default user's password during the first boot (refer to the Booting Raspbian Linux for the first time recipe). In case you have not changed it, the default password is raspberry.

After logging in, the shutdown command is executed with the –h option, which tells the Raspberry Pi to halt after the operating system is shut down.

The shutdown command is privileged. Therefore, the sudo command is used as a prefix to temporarily grant privileges. More information on Executing commands with privileges can be found in Chapter 2, Administration.

There's more...

The shutdown command can also be used to reboot the system. Just use the –r reboot option instead of the –h halt option.

Rebooting the system when you're logged in as the user pi can be done with the help of the following command:

pi@raspberrypi ~ $ sudo shutdown –r now

Synonyms exist for the shutdown command, which include poweroff and reboot.

To power off the system instead of using shutdown –h, you can also use the following command:

pi@raspberrypi ~ $ sudo poweroff

Instead of shutdown –r, you can also use the following command:

pi@raspberrypi ~ $ sudo reboot

More information about these commands can be found in their man pages.

See also