Should I use an SSD for my Raspberry Pi?
A Raspberry Pi is a great device for a bunch of projects. As a server for your home automation project, a 3D printer controller, a simple NAS or a media center, the possibilities are limited by your imagination only. Nonetheless does a Raspberry Pi, even in the newest generation 3, have its limitations.
While the 1GB of memory and the computing power of four cores with 1200 MHz (3B) or 1400 Mhz (3B+) are excellent for such a small device, the storage - typically an SD card - may become a bottleneck for your application, especially when using a cheap SD card. But can an SSD over USB 2.0 improve this? Let’s find out.
My Use Case
I use multiple Raspberry devices, but one of them struggles with the SD card size (of only 16 GB) and a high system load on a regular basis: My home automation server. The Raspberry Pi 3B serves as Home Assistant Server, MQTT Broker, Zigbee Bridge, Unifi Controller and I’m running a complete TICK-Stack on it for logging and monitoring purposes. In total there are 10 Docker containers running on that machine.
Most of the time without any problems and a system load between 0.7 and 1.3. Remember: The Raspberry 3B has 4 cores, so everything below 4 is fine here. But when my Backup scripts and Duplicati, my backup manager, are doing their work, or I try to access and analyze my collected data in the InfluxDB via Chronograf, the system load rises up beyond all limits. It varies between 6, what is slow and laggy, but from time to time acceptable, and 60: Totaly unusable.
As if that’s not enough, it takes hours getting back to normality again. And, as you can imagine, a not responding Home Assistant server (or Alexa) can be a pain…
Benchmark: SD vs SSD
So I had the idea to replace the SD card by an SSD, even it’ll get limited by the USB 2.0 port. Let’s begin with the benchmark. If you just want to replace your SD by an SSD yourself, there is a short guide below the benchmark section. :)
Tools / Tests
I’ve used this script and did three runs with each storage device. First, the script starts a hdparm test, followed by DD to test the write speed and iozone tests for the random 4k read and write values at the end.
SD Cards
In my opinion, these SD cards perform very well. I’m using the SanDisk 16GB card most of the time in my projects. The Samsung EVO is used in one of my action cameras. I couldn’t find my old no-name cards anymore - it would have been interesting to benchmark them too, but you can find some more tests in Jeff Gerling‘s post here.
Name | hdparm Read | DD Write | Random 4k Read | Random 4k Write |
---|---|---|---|---|
SanDisk Ultra SDHC 16GB, C10, U1 | 22.53 | 12.2 | 6.574 | 4.068 |
Samsung EVO Plus SDXC 128GB, C10, U3 | 22.25 | 19.75 | 6.637 | 3.182 |
All values are in MB/s.
The SSD
Now, it’s the SSDs turn. I’m very happy with the result. Keep in mind the SSD is connected via USB 2.0 with the Raspberry Pi:
Name | hdparm Read | DD Write | Random 4k Read | Random 4k Write |
---|---|---|---|---|
Samsung MZ-7TE120BW 840 EVO, 120GB | 30.02 | 32.1 | 10.548 | 12.200 |
All values are in MB/s.
Obviously, since the speed of my storage is the bottleneck, I have to use the SSD. No excuses.
Let’s do it
Requirements
To replace the SD card by an SSD, we need the following hardware:
- a Raspberry Pi
- an SSD
- a SATA to USB cable
- and a powered USB Hub
I’m using a Raspbian based image (Hypriot) during the process.
Preparing the Raspberry Pi
First of all, you need to enable booting from USB since we want to replace the SD card by the SSD entirely. To accomplish that, you need to have an already working
Raspberry Pi with an SD card and change the boot/config.txt file.
Login to your Raspberry Pi and execute the following command in your terminal:
echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt
This command chain appends the option program_usb_boot_mode=1 to the file /boot/config.txt.
Now you have to reboot to apply the new settings
sudo reboot
Afterward, check if booting from USB is enabled via
vcgencmd otp_dump | grep 17:
This command should print 17:3020000a into your terminal. If it shows 17:1020000a instead, it didn’t work.
Now you can shut down your Pi via sudo halt
and remove the SD card.
Preparing the SSD
Since the SSD shall replace the SD card, we have to install an OS image on the SSD. You can use Raspbian, for example. I’m using Hypriot, a Docker optimized OS, because I want to run multiple containers on it only.
First of all, connect the SSD with the SATA to USB cable and plug it into your computer. Now you can flash your SSD card with an OS image as you do with every SD card. I’m using the software Etcher for this purpose, but watch out: Don’t select your computers SSD. Make sure you pick the USB connected device!
After installing the OS to your USB connected SSD, we are done.
Attention: You may need to set up the WIFI connection, SSH and some other stuff before disconnecting the SSD from your computer, depending on the image you have installed.
That’s it. Boot it up!
Yep, that was easy, wasn’t it? Just connect the SSD to your Raspberry Pi via the USB adapter, make sure there is no SD card left in your Pi and power it up. It should boot up from the SSD and you can start using it as before. :)
Troubleshooting
Something doesn’t work? I’ve struggled with the following things.
- The SSD is not powering up
Make sure the SSD gets enough power. In most cases, you have to add a powered USB Hub with a minimum output of 1.2A. - The Pi doesn’t boot from the SSD
If you verified that booting from USB is enabled, you may have to increase the timespan the Raspberry Pi is looking for bootable USB devices. Insert your SD card again, boot the Pi up. Then increase the timespan to 5s with the following command:
echo program_usb_boot_timeout=1 | sudo tee -a /boot/config.txt
.
Reboot to write the values into the Pis memory, power off and try booting from the SD card again. - I’m using Hypriot and the Pi doesn’t boot from the SSD
You have to change the files /boot/cmdline.txt and /etc/fstab. The image points to the SD card slot by default, so you have to change it to the SSD (in most cases /dev/sda1 and /dev/sda2). You can find more information on Github.