We all love the Raspberry Pi. It is fascinating to observe, what kind of different uses this low cost device motivates. I am using it in a rather conventional way as web server and backup file server, running the Debian-based Raspbian Linux distribution optimized for the Raspberry Pi.

Motivation

The one thing that really bothered me with the Raspberry PI was the bad I/O performance to the memory SD card. My Kingston 16 GB class 4 card actually gives poor performance only, as a quick

dd if=/dev/zero of=/tmp/out bs=1M count=400

benchmark reveals

419430400 bytes (419 MB) copied, 94.3303 s, 4.4 MB/s

The more I was excited to learn that

performance with USB flash drives is as on standard PCs

and only Raspbian’s boot partition must reside on the SD memory card.

I decided to give it a try and move the root partition of my existing Raspbian installation to an USB stick and see, if things improve. In my case, writing performance improved by a factor of roughly 5.

Copying the Filesystem

Firstly, partition and format the USB flash drive to hold an ext4 partition large enough to take the current root partition. Let us assume that this partition on the USB flash drive is called /dev/sdb1 on your Linux like operating system. Then, shut down the Raspberry properly,

sudo shutdown

remove the SD card and connect it with a card reader to your computer. Just as for the USB flash drive, let us assume the card’s partitions are recognized as /dev/sdc1 for the boot partition and /dev/sdc2 for the root partition.

Configuration

After copying the filesystem, unmount the USB flash drive and the SD card

sudo umount /media/usb_root /media/sd_root

and connect the SD card only to the Raspberry PI. After powering the Raspberry PI, it will boot as before from the memory card. Login to the PI, open a terminal and connect the USB flash drive to the Raspberry PI. You may find out under what label the USB flash drive’s partition is recognized by scanning through the most recent system logs that the

You see how we replace the root option in the kernel argument list. Moreover, open the file /etc/fstab and change the device label of the root filesystem to generic /dev/root. Though this step is not required, it keeps things clean.

Testing

We are done. Reboot the Raspberry PI

sudo reboot

Please note that you will not loose any data if things go wrong, as you simply have to revert file /boot/cmdline.txt on a computer to boot from the SD card again.

Once the Raspberry PI booted, check by a

ls -al /dev/root

if the root file system is now mounted from the expected partition. If everything is fine, you may now remove the root partition from the SD card and use the memory for something else.

In my case, redoing the benchmark

dd if=/dev/zero of=/tmp/out bs=1M count=400

gave greatly improved results

419430400 bytes (419 MB) copied, 17.7538 s, 23.6 MB/s

Notes

Once your root filesystem is on an external drive, you may remove the memory SD card after booting the Raspberry PI. Don’t forget to properly unmount all the memory card’s partitions (e.g. boot).

Take care if you connect multiple storage devices to the Raspberry PI’s USB port, this might mess up the partition labeling. To be on the safe side, remove any USB devices other than the flash disk on booting.

If you experience error messages like usb 1-1.3: reset high-speed USB device number … using dwc_otg, your USB flash drive might consume more power than a single USB port of the Raspberry PI might provide. See this post here for a more detailed discussion and a solution.

References

The idea for this post originates from this instructions here to directly install a Raspbian distribution to a USB flash drive.