Getting More From Your Raspberry Pi
One of the many things we love about the Raspberry Pi is its amazing flexibility, so we’re always on the look out for different ways that we can use it, and different things we can do with it. And, luckily for us, there are loads of very clever people in the Raspberry Pi community who are also doing the same, and sharing their experiences.
In this post we’re going to take a look at a small number of tips which will hopefully allow you to get a little more out of your Raspberry Pi.
Setting Up a Headless Raspberry Pi
This is something that we looked at quite some time ago (see our Value For Money Raspberry Pi Setup post). However, fellow maker Frederick Vandenbosch recently posted an excellent article about setting up a headless Raspberry Pi which highlighted how simple it is to prepare a Raspberry Pi that can be used without a keyboard, mouse or monitor.
Frederick’s article describes the pre-requisites and all the steps required to prepare an SD card with the latest release of Raspbian Jessie; including how to enable SSH and how to get the Raspberry Pi to automatically connect to a WiFi network when it is first booted.
For full details of this process, checkout Frederick’s article Headless Raspberry Pi Setup with Raspbian Jessie.
Creating a Backup Image of a Live System
One of the occupational hazards of using a Raspberry Pi is that the operating system on the SD card can occasionally get corrupted. This can happen for various reasons, but the most likely cause tends to be failure of the power supply while the Raspberry Pi is running. Whilst it’s thankfully not a common occurrence, when this corruption does happen it generally means a total loss of everything on the card; with little hope of recovery.
In some cases we have found that it can be possible to at least partially recover a corrupted SD card by simply copying a new set of files into the boot partition of the SD card; but this is by no means guaranteed. With this in mind, it is always worth keeping a recent backup of your operating system.
There are a number of different ways of backing up the Raspberry Pi operating system SD card, and the simplest is probably to use a disk imaging program (for example Win32DiskImager) to read the disk image from the SD card and store it as an image (.img) file. This image file can then be used to re-image the SD card in the unlikely event of the card becoming corrupted.
However, we’ve recently had a go at an alternative method of backing up an SD card which allows us to create a copy of a live image while the system is running. For full details of this method, take a look at the article about making a backup dd image while Pi is live at the Raspberry Pi foundation’s forum web site. This method basically involves using the dd command; for example:-
dd if=/dev/mmcblk0 of=/dev/sda bs=1M
will backup the complete operating system to an SD card plugged into one of the USB sockets on the Raspberry Pi using an SD card reader.
We found that in order for this dd command to work correctly, it was necessary to set the Raspberry Pi to boot to the CLI, to ensure that the GUI is not running.
The output device (in our case /dev/sda) can be determined by plugging in our SD card reader and issuing the command:-
which will return something like:-
/dev/sda1: LABEL="boot" UUID="F1A5-B5DE" TYPE="vfat"
From this output, we would take the ‘/dev/sda’ part to specify our output device.
An alternative to using the dd command is to use dcfldd, which is an enhanced version of dd. In order to use dcfldd you will need to first install the dcfldd utility using the commands:-
sudo apt update sudo apt install dcfldd
The dcfldd utility allows the writing to more than one output device at a time. For example, the command:-
sudo dcfldd if=/dev/mmcblk0 of=/dev/sda of=/dev/sdb sizeprobe=if
should backup our operating system image to both /dev/sda and /dev/sdb. We tried this using a USB hub, since this was the only way that we could practically connect 2 SD card readers to our Raspberry Pi 3.
Unfortunately, using this method seems to take too long for it to be of any practical value. We left our backup running overnight, and it was still running the next morning when we came in.
A more practical alternative to this is to make use of a multi card reader, such as the Kingston USB 3 card reader shown below. Using this card reader we could backup to 2 SD cards at once (one in the micro SD card slot, and one in the SD card slot using a SD card adapter).
Using this method, it took around 90 minutes to backup a system running from a 16GB card, to 2 other 16GB SD cards, using the command:-
sudo dcfldd if=/dev/mmcblk0 of=/dev/sdb of=/dev/sdd sizeprobe=if
However, we did find that the dcfldd utility did not give an accurate indication of the progress of the backup.
Booting a Raspberry Pi 3 From a USB Flash Drive
We quite like the idea of being able to boot a Raspberry Pi from a USB flash drive, and the article about booting a Raspberry Pi 3 from a USB Mass Storage Device explains how this can be done.
Note, that in order to do this it is necessary to initially boot the Raspberry Pi from an SD card. Having done this, it is then necessary to alter the OTP (One Time Programmable) memory on the Raspberry Pi in order to enable the boot from USB option. This process is irreversible, so once done it is not possible to retrospectively disable the boot from USB option. The Raspberry Pi is effectively permanently modified; although this does not stop you from still booting from an SD card if you want to do this.
For reasons explained in the article, this will only currently work with a Raspberry Pi 3. Also, (again, for reasons explained) it will not work with just any USB drive. We did not have any luck booting our Raspberry Pi 3 using a Kingston 16GB DataTraveler MicroDuo. However, we did successfully manage to get our Pi 3 to boot using an Integral 8 GB flash drive.
The article mentions a number of other USB drives that are also reported to work with the Raspberry Pi 3, and we’ll try to update this blog post as and when we find further USB drives that also work.
Following the publication of this article, we have verified that it is possible to boot the Raspberry Pi 3 from the following USB flash drives:-
- SanDisk Cruzer Blade 4GB (Using Raspbian Jessie Lite)
- SanDisk Ultra Fit USB 3.0 16GB
- SanDisk Cruzer Fit USB 2.0 16GB
We also tried a Kingston DataTraveller G3 32GB, but this would not work.