Most of the time you might have seen a Raspberry Pi booting from an SD card. Don’t be in the presumption that an SD card is the only option to boot a Pi. Raspberry Pi can be booted from any type of USB storage, no matter whether it’s a thumb drive or a superfast PCI SSDs. We are pleased to show you how to boot Raspberry Pi from a USB drive in this tutorial. In this tutorial we are going to cover why you should boot a Raspberry Pi from a USB drive, what difference you may see when booting a Raspberry Pi from a USB drive, and three ways to boot a Raspberry Pi from a USB drive. First, it is necessary to know why you want to use USB drives to boot Raspberry Pi. The answer to this question lies in the following section.
Booting From USB Drive Is Right For You?
You may see using an SD card to boot a Raspberry Pi in most of the tutorials. Even official Raspberry Pi documentation is no exception. But, there is a reason for that. SD cards are portable to use. You need not maintain a separate unit for storage. It’s been seen that there is a dramatic reduction in the performance when flash drives have been used against SD cards. You may ask how the Pi would perform if you use HDDs/SSDs, they have a track record of an impressive performance against SD cards. Well, yes, you may yield better performance if you use hard drives. But, you may need to bear with additional components like a USB cable for data transfer, hard drive itself with a case for protection. Additionally, an extra power unit if the power drowns from the Pi is not sufficient to run the hard drive. All these requirements make this option inconvenient. If you are ready to compromise with all these inconveniences then you will get a stable, durable, and performance-oriented Pi for your project. Both ways are better in their way and both of them have their own pros and cons in practical. See this table which tells the difference in a simple way. We feel this table would help you to decide what is right for you.
|Booting from SD card||Booting from Hard Drive|
|More convenient||Faster than SD cards which increase performance|
|Portable||Hard drives must remain attached|
|Finite lifespan||Longer lifespan|
|Simple Backups||More complicated Backups|
Which Method Is To Use To Boot From USB?
If you are made your mind to try booting your Pi from a USB hard drive. Then you are in right place. We always encourage you to try exploring different options. We can tell you what we have experienced. But, it may not be true in your case. You should try this practically. You are not going to learn until you get your hands dirty. All right, let’s hop on to the actual topic. There are multiple different methods to boot a Raspberry Pi from USB hard drives. Ultimately, it all depends on which model of Pi you are using. We are going to show you three different methods of booting a Pi in this tutorial. It is important to know each one of them before getting started. Each method is better in some terms than others. Let’s have some knowledge of all three methods one after another.
Method #1: Raspberry Pi Imager.
This method is very simple and straight as Raspberry Pi Org starts supporting the USB boot option on the new upcoming models, there is no need of tweaking bootloader settings and flashing of EEPROM in the latest model. Booting from a USB drive is as same as booting a Pi from an SD card using the Raspberry Pi imager tool. You just need to select the hard drive instead of the SD card in the imager application while writing the boot image. Bear in your mind that this method will work only on Raspberry Pi OS 2020-08-20 or newer and Raspberry Pi 400 and later models. Please check out our post “How easy to set up a Raspberry Pi ” to know more about booting a Raspberry Pi from an SD card.
The other two methods are a debatable topic. One method says to hijack the complete root file system from the SD card into the USB drive. Other methods say to upgrade the firmware from the official Raspberry Pi org to boot the Pi from USB storage. We would like to compare both of the methods using a table here in this section.
|Upgrade Firmware||Moving the root file system|
|Only works with newer models||Works with all models|
|Requires a change on the Pi itself||Portable from one system to another|
|Procedure may differ between models||Universally applicable to all models|
|No need of SD card||SD card is mandatory to have|
Method #2: Moving The Root File System.
This method is closer to the universe. No matter what model you have starting from its early release to the present, it works flawlessly. Let’s get into it from the scratch. This procedure is divided into Five simple steps.
- Backup your SD card
- Trigger the file system check
- Clone the SD card to a hard drive
- Configure the hard drive as a boot partition
- Expand the swap
Time needed: 30 minutes.
Moving the root file system:
- Take a backup of your SD card:
Let’s start the procedure by taking a backup of your SD card. Use a built-in ‘SD card copier’ or any other program of your choice to copy the content of the SD card before processing.
- Trigger the file system check:
It’s good to start with a file system checkup to ensure everything is correct before moving the file system to the USB drive. Create a file named ‘forcefsck’ in the root directory. This file indicates the system to check the file system in the next reboot. If your Pi is hooked up to a monitor, you can see what is going on on the Pi. If not, just give a little extra time to the Pi to complete the boot process and come up. If you see your Pi booted without any errors, then your pi passed the file system test successfully. The file ‘forcefsck’ will disappear from the root directory. This is only a one-time test. Although you can trigger another test by repeating the process.
$ sudo touch /forcefsck
$ sudo reboot
- Clone the SD card to a hard drive:
The first step to booting from a hard drive is to copy the content of the SD card to the hard drive partition. All of you know that the Raspberry Pi imager creates two partitions on the SD card. We need to copy the content of the boot partition of the SD card to the hard drive. To do this let’s find out the data to be copied from which SD card’s partition to which hard drive’s partition. Let’s check the boot partitions now and take note of PARTUUID.
$ cat /boot/cmdline.txt
List all the storage partitions using blkid command. Here we have a hard drive attached and connected to the Pi with three partitions created on it. Please check our post “How to Partition and Format the Hard Drives on Raspberry Pi:” to know how the hard drive has been partitioned.
$ sudo blkid
All right, now we know the data to move from which partition to which partition. Let’s break it down for you. Match the PARTUUID of boot partition in the result of blkid command. this gives the information about the data to be copied from /dev/mmcblk0p2 partition to /dev/sda1 partition. Let’s copy the content using ‘dd’ command. dd command will not show any progress information. You need to wait until the backup process gets completed. Time depends on the size of the data. It may take a longer time if you have more data on your SD card. It tests your patience.
$ sudo dd if=/dev/mmcblk0p2 of=/dev/sda1 bs=32M conv=noerror,sync
dd: A command used to copy files or a partition.
if: input file
of: output file
bs: block size
conv: conversion options
After completion of the data transfer. Check the target partition for errors using the file system consistency check command.
$ sudo e2fsck -f /dev/sda1
If you see something like Cannot continue. Remount the drive and try the same command.
You may see some errors like this, there is something corrupted on the SD card file system. Try to repeat the process by turning off the Pi without shutdown. Or try by taking the previous backup again. The safest way is to do this by copying the contents of the SD card to a place and use that as a source for the dd command which prevents copying any files on the fly from the SD card. After all, errors go off. Reboot the Pi.
$ sudo reboot
Soon after reboot your Pi will starts reading the whole boot partition by itself. You can do this manually too by Issuing this command. This shouldn’t take long time. When you finished this command the new root system will have access to the full OS partition
$ sudo resize2fs /dev/sda1
- Configure the hard drive as a boot partition:
To set up the hard drive as your boot device you need modification in these two places:
Substitute the PARTUUID of /dev/sda1 in /boot/cmdline.txt
$ sudo blkid
Copy the PARTUUID of /dev/sda1. Edit the /boot/cmdline.txt file using any text editor and replace the PARTUUID of boot partition with the PARTUUID of /dev/sda1.
$ sudo nano /boot/cmfline.txt
Delete the PARTUUID of /dev/mmcblk0p2 and write the PARTUUID of /dev/sda1. Save and reboot the Pi.
After the reboot it starts using the hard drive. For any reason your Pi didn’t boot with your hard drive, you can connect your hard drive to your desktop computer and edit the /boot/cmdline.txt file. But, you should have PARTUUID of /dev/sda1 or /dev/mmcblk0p2 handy to update and boot your Pi with your choice of storage.
Edit the /etc/fstab and replace the PARTUUID of /dev/mmcblk0p2 with PARTUUID of /dev/sda1.
Reboot one more time.
$ sudo reboot
- Expanding the swap:
Now you are booting your Pi from your hard drive. If you are running new PI models which has 4 or 8 GB of RAM on them. You may need to expand system swap. Raspberry Pi is already using swap partition but in very little amount. Use swapon command to see how much of space is configured as swap. It’s just 100 MB.
$ swap -s
To increase the swap size edit the file ‘/etc/dphys-swapfile’. And, reboot the Pi.
Comment the ‘CONF_SWAPSOZE-100’ line and uncomment the CONF_SWAPFACTOR=2. This would automatically pickup the swap size as twice as the RAM size. When next time you reboot your swap size would be 8 GB on a 4 GB model of Pi. Please make sure you have enough space on your boot partition before touching the swap configurations. We recommend to do this when you have a boot disc larger than 32 GB.
Method #3: Updating The Bootloader EEPROM
This method is suitable only for Raspberry Pi 4 and 4B models. Depending on when your Raspberry Pi 4B was manufactured, the bootloader EEPROM may need to be updated to enable booting from USB mass storage devices. If you have older models of Pi with you, Probably you are going to break down your Pi if you followed this procedure. Procedure would differs with different models. Please pay attention on your procedure and Pi model before taking any decision. Visit this site to see how to upgrade the EEPROM of Raspberry Pi.
Now, we hope you have some idea on different ways to boot a Raspberry Pi from a USB drive. It’s a debatable topic to decide SD card vs USB storage. If you have new models of Pi, we recommend using USB storage. If not, just fine to stick with an SD card. Again, we recommend using super-fast SSD or at least faster HDDs if you are decided to go for a USB boot. Because flash drives are never found to be the best performers. You can use them as long as you are okay with their performance.
If you have older models of Pi we never recommend using USB storage as your default boot device. You may need to flash EEPROM on your Pi. This is a one-time procedure. You can’t undo this once you did the flash. This procedure is quite complex. It’s not for beginners. Moreover, the procedure would differ with different models. There are chances of damaging the Pi if you follow the wrong procedure. It’s better to use an SD card to boot up the Pi and use the USB storage as an extended drive to increase the storage capacity.
Thanks for reading this article. If you find this article interesting, please visit our site to read more such interesting article.