Booting Raspberry Pi 3 B from USB Drive

USB drives typically have a longer lifespan and better durability compared to SD cards, especially when it comes to frequent read/write operations. This can lead to improved reliability and reduced risk of data corruption or storage failures over time.

The Raspberry Pi 3 B+ has the capability to boot from USB drives without needing any special configuration or setting changes. However, for the earlier Raspberry Pi 3 model, booting from USB requires setting a specific OTP (one-time programmable) bit to enable USB boot mode.

This means that Raspberry Pi 3 models need a one-time configuration change to enable USB booting, while Raspberry Pi 3 B+ and newer models support USB booting out of the box without the need for any additional changes.

After you program the OTP bit to enable USB boot mode, you can still boot from an SD card if you desire. The Raspberry Pi will prioritize booting from the SD card if one is present. If there is no SD card inserted, it will attempt to boot from an attached USB drive if it is bootable.

So, even after setting the OTP bit, you can switch back to booting from an SD card by simply removing the USB drive and inserting the SD card. There's no need to make any additional changes to the Raspberry Pi's configuration.

1. Setting OTP Bit on Raspberry PI 3B

To enable USB boot mode on a Raspberry Pi 3, you need to boot it from an SD card with a specific configuration option to set the USB boot bit in the OTP (one-time programmable) memory. Once this bit has been set, the Raspberry Pi will have the ability to boot from USB drives without requiring an SD card.

It's important to note that any changes made to the OTP are permanent and cannot be undone. So, once you've set the USB boot bit, the Raspberry Pi will retain the ability to boot from USB drives indefinitely, even if you remove the SD card or power off the device.

You can use any compatible SD card that is running Raspbian or any other supported OS to program the OTP bit on a Raspberry Pi 3. As long as the SD card contains a supported operating system, you can follow the steps to enable USB boot mode by configuring the OTP bit.

Boot your PI and start the terminal. Use echo program_usb_boot_mode=1 to append program_usb_boot_mode=1 to the end of the /boot/config.txt file. This setting enables USB boot mode.

$ echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt

Check if the line has been added to the end of /boot/config.txt (Figure 1). This command will search for the line containing program_usb_boot_mode in the /boot/config.txt file. If the line has been added to the end of the file, it will be displayed in the output.

$ grep program_usb_boot_mode /boot/config.txt

Figure 1 - Checking if Boot_mode Is Enabled in /boot/config.txt

Reboot the Raspberry Pi.

$ sudo reboot

After reboot, start the terminal and check that the OTP has been programmed:

$ vcgencmd otp_dump | grep 17:

The command vcgencmd otp_dump | grep 17: is used to display the OTP (one-time programmable) memory, specifically searching for the line containing 17:. This line indicates whether the USB boot bit has been successfully programmed.

If the output 17:3020000a is shown, it confirms that the OTP bit has been set correctly, enabling USB boot mode (Figure 2).

Figure 2 - OTP bit Is Set Correctly

However, if this output is not displayed, it indicates that the OTP bit has not been successfully programmed. In such a case, you should go through the programming procedure again to ensure that all steps were followed correctly. If the bit is still not set after reprogramming, it could indicate a potential hardware fault in the Raspberry Pi itself, and further troubleshooting may be required.

You can remove the program_usb_boot_mode line from the config.txt file if you want to prevent another Raspberry Pi from programming USB boot mode when using the same SD card. To remove the line, you can edit the /boot/config.txt file using a text editor such as nano:

$ sudo nano /boot/config.txt

Navigate to the line containing program_usb_boot_mode=1 using the arrow keys, delete the line, and then save the changes by pressing Ctrl + X, followed by Y to confirm, and then Enter.

After removing the line and saving the changes, the Raspberry Pi will no longer attempt to program USB boot mode when booting from that particular SD card.

2. Copying Image to USB Drive

The provided steps guide you through the process of copying an image file (.img) to a USB drive and then booting a Raspberry Pi 3B from that USB drive. Here's a summary:

Boot your computer with a Linux operating system, such as Ubuntu. Download the operating system image supported by Raspberry Pi that you want to copy to the USB drive. You can find the appropriate image on the Raspberry Pi website or other reliable sources.

After downloading the image file, insert the USB drive into your computer. Do not mount the USB drive. Open a terminal and check the available disks using the lsblk command:

$ lsblk

Insert the compatible USB drive (e.g., Kingston 128 GB) into your computer but do not mount it.

Check if a new device is detected by running the lsblk command again. If a new device appears (e.g., /dev/sda), it indicates that the USB storage device has been recognized. Again, do not mount the USB drive.

Burn the downloaded image file (.img) to the USB drive using the dd command. Replace /path/to/image.img with the path to the downloaded image file and /dev/sda with the appropriate device identifier for your USB drive:

$ sudo dd if=/path/to/image.img of=/dev/sda

Note: Be extremely careful with the dd command, as it will overwrite the contents of the USB drive. Make sure to double-check the device identifiers (/dev/sda, etc.) and paths to image files to avoid accidental data loss.

The dd command can take a significant amount of time to copy the image file to the USB drive, especially if the image file is large or if the USB drive has a slower write speed. Interrupting the process prematurely can lead to incomplete or corrupted copies, potentially rendering the USB drive unusable or causing data loss.

After burning the image, remove the USB drive from your computer.

Shutdown your computer:

$ sudo shutdown -h now

Insert the USB drive into a USB port of the Raspberry Pi 3B, remove the SD card  and power it up.

Conclusion
In conclusion, booting a Raspberry Pi 3 B from a USB drive offers advantages such as improved reliability and reduced risk of data corruption compared to SD cards.

While the Raspberry Pi 3 B+ supports USB booting out of the box, the Raspberry Pi 3 requires a one-time configuration change to enable USB boot mode by setting a specific OTP bit. Once programmed, the Raspberry Pi retains the ability to boot from USB drives indefinitely.

Reference
https://www.instructables.com/Booting-Raspberry-Pi-3-B-With-a-USB-Drive/

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.