By default, Raspberry Pi boots up and stores all of its programs on a microSD memory card, which has rather limited bandwidth. On the Raspberry Pi 4, the memory card slot can achieve a theoretical maximum of 50 MBps, which is double the 25 MBps maximum on the Pi 3B+ (and other 3 series). you get more speed if you attach an external drive to one of the Raspberry Pi's USB ports, especially with the Pi 4 offering USB 3.0 connections that have a theoretical maximum of 660 MBps. While we got around a third of that maximum in our real-life tests of a Raspberry Pi 4 with SSD, we were still impressed with how much faster app opens, web serving and file copying took place.
Unfortunately, at this time, you can't boot a Raspberry Pi 4 off an external drive. But you can force the Raspbian OS to use an external drive for its "root" partition, which holds all of its programs and data. So, in effect, you have a small boot partition on a microSD card but the meat of the entire operating system would still live on your speedy SSD or Flash Drive. A future firmware update will allow the Pi 4 to boot off of external drives, no microSD card required, The instructions directly below work on a current-day Pi 4 or an earlier model, but if you want to boot your Pi 3 off of an external drive scroll down to the next section of this page.
How to Run a Raspberry Pi 4 Off an SSD
The first thing you need to do is prepare your external drive so that all of the appropriate data is on it. To get started:
1. Connect your external drive to the Pi. Make sure to attach your drive to one of the blue-colored USB 3.0 ports.
2. Launch a terminal window on the Pi 4. You can do this either by clicking the terminal icon on the desktop, by hitting CTRL + ALT + t or by connecting to the Pi from another computer using SSH.
3. Use the fdisk -l command to see a list of all your drives.
sudo fdisk -l
You'll see a list of available partitions. Take note of the second partition on your microSD card; that's where your data is stored and, in my case, it is called /dev/mmcblk0p2, though you may not need this information. Also, remember the name assigned to your external drive, which is probably /dev/sda but could be different if you have more than one drive attached.
4. Launch fdisk, targeting your external drive.
sudo fdisk /dev/sda
A prompt will appear, offering you the change to see a list of fdisk commands.
5. Type p at the prompt to see a list of current partitions on the drive.
You'll probably only see one partition here, but if there are multiples, you may want to delete them all.
6. Type d to delete the primary partition. If you have many partitions you want to delete, you'll need to repeat this step.
7. Type n to create a new partition, hit p to make it a primary partition and type 1 so that it's partition 1 and hit Enter twice to select default beginning and last sections.
8. Type w to write your changes to the drive.
If you get an error message saying something like "Device or resource busy," reboot your Pi and try again. It could be that another process is using the external drive, preventing it from being partitioned.
9. Format the new partition in the ext4 file format. Note that the partition name will be the drive name with a 1 at the end (ex: /dev/sda1).
sudo mkfs.ext4 /dev/sda1
This may take a few minutes.
10. Create a new folder called /media/newdrive, which you will use to mount your external drive.
sudo mkdir /media/newdrive
11. Mount the new partition as /media/newdrive. Note that your partition name will have a 1 after it. So it will be /dev/sda1, rather than just /dev/sda.
sudo mount /dev/sda1 /media/newdrive
12. Copy all the files from your root folder using the rsync -avx command.
sudo rsync -avx / /media/newdrive
This process could take as long as a hour if you have a lot of data.
13. Open the /boot/cmdline.txt file for editing
sudo nano /boot/cmdlinetxt
You'll see cmdline.txt open in a text editor in your terminal.
14. Paste the following text at the end of the first (and likely only) line of cmdline.txt.
root=/dev/sda1 rootfstype=ext4 rootwait
This text tells the Raspberry Pi to look at /dev/sda1 (provided that that is your external drive partition) as your primary storage drive. To boot, you'll need both the microSD card and your external drive connected. The Raspberry Pi cannot boot if the external drive is missing and this text is in the cmdline.txt file.
Hit CTRL + X to exit and Y (when prompted to save) then Enter to confirm your change.
If you ever want to comment this text out so you can boot and run off a single microSD card, you can just put the code on a second line with the comment # in front of it.
15. Reboot your Raspberry Pi 4. It won't boot unless the external drive is attached.
How to Boot Your Raspberry Pi Off a USB Drive
You can boot Raspberry Pis that are older than the Pi 4 directly off of USB. When you're done with the process, you won't even need to have a microSD card in the Pi's slot.
1. Create your external boot drive. There are two main ways to do this.
- Use Etcher to "burn" the Raspbian OS to your external drive, a process we cover in our article on how to get started with Raspberry Pi. This works great, but doesn't copy over any data from an existing build.
- Clone your current microSD card to the external drive using Raspbian's built-in SD Card Copier, which is loced under the Accessories menu.
2. Create or find a bootable microSD card. If you already have a bootable microSD card, you can use it.
3. Connect both drives to your Raspberry Pi and boot it.
4. Open the the /boot/config.txt file for editing
sudo nano /boot/config.txt
5. Add program_usb_boot_mode=1 to the bottom of the file and save it.
6. Reboot the Raspberry Pi with the microSD card inside and external drive connected. When it boots, the Pi will write a bit to the firmware, informing it to boot off the USB drive. You only need to do this once and you can remove program_usb_boot_mode=1 to from the config.txt file, because the change is now permanently part of the Pi's firmware.
7. Reboot the Pi again with the microSD card removed. It should now boot off of the external drive.
From now on, your Pi will boot off of its external drive, unless there's no external drive attached. If there's no bootable external drive, the Pi will boot off its microSD card.