Boot the Raspberry Pi from a USB Hard Drive

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.

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.

Boot from SSD Setup
Boot from SSD Setup

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.  

Boot from SSD Setup
Boot from SSD Setup

5. Type p at the prompt to see a list of current partitions on the drive.

Boot from SSD Setup
Boot from SSD Setup

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.

Boot from SSD Setup

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.

Boot from SSD Setup

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.

16. Now lets set the Hard Drive spin down time of the external USB hard drive.

sudo apt-get install hdparm

Now set the value of the spin down (-B parameter) to 127, otherwise the HDD won’t spin down. Set the idle spin-down time value (-S parameter) to 10 minutes, like this:

sudo hdparm -B127 -S120 /dev/sda

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.

Short URL: http://tinyurl.com/yy7u3646
   Send article as PDF   

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Do NOT follow this link or you will be banned from the site!