Raspberry Pi single board computers have historically booted from microSD flash cards. This works OK, but isn’t nearly as solid a solution as an SSD or M.2 hard drive. Earlier in 2020, Raspberry Pi 4 gained the ability to boot from USB which means any hard drive that can be connected to the Pi via USB (typically USB 3.0) and recognized by the OS can be used as a boot device. Most common external boot devices are SSD hard drives and M.2 hard drives – but you could even use something like a USB flash drive.
The problem with booting a Raspberry Pi to an external USB hard drive is that there isn’t much documentation on how to do this properly – when Raspberry Pi’s first gained this capability, it required manual upgrades to Beta bootloaders, and some configuration changes to make it work. This has since changed, and it’s much easier with newer versions of Raspbian – but of course all of that old documentation still exists on the web and can be extremely confusing for anyone searching for how to accomplish USB boot.
So in this tutorial, we’re going to show you how to get a Raspberry Pi to boot from USB as of December 2020 and early 2021.
What you’ll need (Amazon affiliate links):
Raspberry Pi 4 – I recommend the CanaKits as they come with almost everything you need to get started including the microSD card. The CanaKit Raspberry Pi 4 4GB Starter Kit is a great option at $99.99. Or you can bump up to the 8GB version for $20.00 more.
Next, you’ll need a USB 3.0 external hard drive. The drive that I’m using for this tutorial is the Seagate Portable 2TB External Hard Drive. But, I have also successfully configured the Raspberry Pi to boot from M.2 (not NVMe) using the Silicon Power 256GB A55 M.2 SSD with an external SSK Aluminum USB 3.1 to M.2 SSD Enclosure.
Another promising option if you want an all-in-one case with M.2 boot capability is the Argon ONE M.2 case, though I admit that my first experience with this case hasn’t been ideal – the M.2 connectivity was extremely intermittent to the point of being unusable. I have contacted Argon ONE about a replacement or RMA, but have not yet heard back – so buyer beware.
Initial Raspbian Install
Booting from USB first requires that we boot from the microSD just like we would with any other Raspberry Pi installation. The easiest way to format your microSD card with Raspbian is to use the Raspberry Pi Imager application. Download the Raspberry Pi Imager and install it on Windows, macOS, or Ubuntu. Once installed, select Raspberry Pi OS (32-BIT) for the OS and then choose your microSD card. MAKE SURE to double-check that you have selected the correct microSD card as this will overwrite anything that you have on there.
Once you have double and triple-checked that you have the correct microSD card, click the ‘WRITE’ button to flash the card with the latest version of Raspbian.
Next, we’ll want to set up our Raspberry Pi 4 for the initial setup of Raspbian. Plug in a keyboard, mouse, monitor and power adapter to the Raspberry Pi. For my setup, I’m using the Rii i4 Mini Bluetooth Keyboard with Touchpad for keyboard/mouse combo, and the 7″ Raspberry Pi Touchscreen Monitor.
Plug the freshly configured microSD card into the Raspberry Pi and power everything on. After a few minutes, you will end up at the Raspbian desktop with an initial setup wizard. Click ‘Next’ to get started.
The wizard is pretty straight forward. First it will ask about your location information, then it will ask you to change your default Pi user password. Make sure you set the password to something strong.
Next you will be asked about your screen resolution – if you have a black border around your screen, click ‘This screen shows a black border around the desktop’ and click ‘Next.’
Then choose your WiFi network and enter the password, or if you’re going wired, you can click ‘Skip.’
When asked if you want to update, click ‘Skip’ for now – we will update manually later.
Now you’re done! Click ‘Restart’ to reboot the Pi 4.
Once the Pi is back online, let’s first enable SSH and VNC (optional). These two services make the Pi easier to access from another computer.
Click the Raspberry icon in the top left and choose Preferences –> Raspberry Pi Configuration. Then click on the ‘Interfaces’ tab and select ‘Enable’ next to SSH and VNC.
Now, let’s connect via SSH (or open a terminal on the Raspberry Pi desktop) and update the Pi.
sudo apt update
sudo apt upgrade -y
The upgrade will take a while (5-10 mins usually). Once finished, you’re up to date.
Let’s now take a quick benchmark test of our microSD card. To do this, install hdparm:
sudo apt install hdparm -y
Once installed, run:
sudo hdparm -t /dev/mmcblk0
This will give us our read speed:
This is a basic measurement of the drive – there are a ton of different ways to benchmark, but that is beyond the scope of this document.
Next, let’s add our USB drive. First, shut down the Raspberry Pi:
sudo shutdown -h now
Connect the USB drive and boot the pi back up. Your drive should be mounted as /dev/sda, but you can check this by running:
sudo fdisk -l
In the screenshot above, we can see a 29.9GB microSD drive and a 1.8TB USB 3 drive mounted as /dev/sda. Next, we need to copy all of the contents of the microSD drive over to the SSD hard drive. Click the Raspberry Pi icon at the top left of the desktop and choose Accessories –> SD Card Copier.
Select your microSD card in the ‘Copy From Device’ field, and the SSD (or other USB hard drive) for the ‘Copy To Device’ field. Click ‘Start’ to copy everything from the microSD to the USB drive. This will take a few mins.
Once complete, if you run the fdisk command again, you should see that /dev/sda now has two partitions.
Before we boot to the USB drive, first let’s double-check that our Raspberry Pi is set up to boot from USB if there is no microSD card inserted. Drop to SSH and run:
Navigate to Advanced Options –> Boot Order and press ‘Enter’ on B1 USB Boot. You should get a confirmation page:
Press ENTER to hit OK. Then choose ‘Finish’ on the Raspi-config screen. You will be asked to reboot. Choose ‘Yes’ to reboot the Pi.
When the Raspberry Pi comes back up, we’re now going to want to test out the USB boot. Do a graceful shutdown:
sudo shutdown -h now
Power off the Raspberry Pi, remove the microSD card, and then power it back on. If everything was done correctly, your Raspberry Pi will boot back into Raspbian without a microSD card – this means you’re successfully running on your USB 3 drive!
Let’s run that same benchmark again (but this time against /dev/sda):
sudo hdparm -t /dev/sda
You should notice much higher read speeds now:
Running the same test, but with an M.2 drive instead of the external SSD, we get even greater speeds: