Raspberry pi 4 boot from USB

Posted under » Raspberry Pi on 30 Sep 2020

Your Pi doesn't have a hardisk and soon your SD card will run out space. Adding a thumbdrive or a USB drive is a solution. However I prefer the latter because thumbdrives tend to corrupt after a while especially under heavy usage. Now that we have SSD, it will improve the performance significantly.

Normally, the hardisk is mounted on /mnt or /media but you may want to add the USB disk automatically using fstab under a folder that you specify, eg. /usbdrive. Use 'df -H' in conjunction with 'lshw -C disk' to know the name of your USB drive

You will see the hard disk name and his location. Something like /dev/sda1 before it. Now you can add to your fstab.

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
/dev/sda1       /usbdrive       ext2    defaults          0       0

Now make a new folder "/usbdrive" on your pi. Restart and your done. However, mounting a disk is not enough.. We want to boot from USB.

For this you need to update the firmware and you can only do this from Raspberry OS.

As SUDO run terminal or connect through SSH

apt update
sudo apt full-upgrade
vim /etc/default/rpi-eeprom-update

The default value of the FIRMWARE_RELEASE_STATUS parameter is “critical,” which must be changed to “stable”

rpi-eeprom-update -d -a // latest
rpi-eeprom-update -d -f /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2020-06-15.bin // specify a .bin

After the update has completed successfully, reboot your Raspberry Pi 4.

Verify whether the update was successful by typing the following command in the terminal.

vcgencmd bootloader_version
vcgencmd bootloader_config

The second command will show you the boot order.

You should look for the last row of the result which should be BOOT_ORDER=0xf41. This is important! If you see this that means your Raspberry Pi 4 will first look for SD card and if there isn’t any it will try to boot from a drive connected to the USB ports of the Raspberry.

You then have to prepare your USB SSD with the OS of your choice.. eg. mine is Ubuntu Server.

Once the image is flashed to your SSD (I recommend using balena Etcher), plug the SSD/USB to your Raspberry Pi 4 and execute the following commands to mount the SSD/USB disk to your Raspi.

sudo mkdir /mnt/mydisk
sudo mount /dev/sda1 /mnt/mydisk

Then copy the needed files from SD card to SSD/USB disk with the following two commands:

sudo cp /boot/*.elf /mnt/mydisk
sudo cp /boot/*.dat /mnt/mydisk

Now your SSD are all set up. Remove your SDcard and reboot. You will now be able to boot from your USB.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS