Possible to boot raspberry pi 4 from an external USB?

Here it is, as said the hard way… possible you can do it much easier with cloning software. But you be rewarded with a fresh, optimal aligned install on your SSD with really unique UUID for the disk and partitions!

NOTE; THIS IS A WRITE UP FROM MEMORY, DID NOT REPEAT THE COMMANDS !!

DO NOT JUST COPY PASTE !!!

First be sure your RPI4 has the latest EEPROM firmware.

[root@rpi4 ~]# vcgencmd bootloader_version
Dec 11 2020 11:15:17
version c3f26b6070054bca030366de2550d79ddae1207a (release)
timestamp 1607685317

To update the EEPROM you need the lastest Raspberry PI OS. (I used the minimal without GUI)

Doc’s from the Raspberry Pi Foundation and here to update to “stable” instead of “critical”.

On the RPI (OS does not matter now) downlaod the Nethserver image for the Raspberry PI: (At the time of writing RC2…)

wget https://github.com/NethServer/arm-dev/releases/download/7.9.2009_RC2/Nethserver-7.9.2009-RC2-RaspberryPi-img.raw.xz

decompress the image:

xz -d -T 0 -k Nethserver-7.9.2009-RC2-RaspberryPi-img.raw.xz

his may take a while… despite we are telling to use as many threats possible (-T 0) it seem to run just one.

now attach a loop-device to the decompressed image on the disk:

sudo losetup -f -P  Nethserver-7.9.2009-RC2-RaspberryPi-img

in this the -f is for find a available loopdevice and -P attech the partitions too. It finds most probably the first loop-device meaning /dev/loop0p1 and /dev/loop0p2 should exist now

make an (arbitrary) directory for the mount point of the source image:

mkdir source

and mount the loop-devices attached to the NS-image:

sudo mount /dev/loop0p2 source
sudo mount /dev/loop0p1 source/boot

Attach the SSD and partition it as you wish, but the first partition needs to FAT32 minimal 256MB (I made it 512MB), a second partition type linux. I like GPT partitiontables more (they live on both “sides” of the disk, you have an backup if you mess up) so used gdisk with this result:

[root@rpi4 ~]# gdisk -l /dev/sda
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 976773168 sectors, 465.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 85B4599F-8B98-4F9F-A907-70D2C33AE3EE
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 2048-sector boundaries
Total free space is 908615661 sectors (433.3 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1050623   512.0 MiB   0700  Microsoft basic data
   2         1050624        68159487   32.0 GiB    8300  Linux filesystem

format the disks: (in here /dev/sda is assumed to be the SSD check this!!)

sudo mkfs.msdos /dev/sda1
sudo mkfs.ext4 /dev/sda2

make an (arbitrary) directory for the mount point of the SSD and mount the partitions:

mkdir target
sudo mount /dev/sda2 target
mkdir target/boot
sudo mount /dev/sda1 target/boot

copy the content from source to target

sudo cp -rp source/* target/.

(this takes a while… we are allmost done :grinning:)

now we need disk-id’s (UUID) and the part-id of the new rootfs which is /dev/sda2 .

On my system: (Note this system boots without SD-Card hence it does not show up)

[root@rpi4 ~]# sudo blkid
/dev/sda1: UUID="D17B-9F4F" TYPE="vfat" PARTLABEL="Microsoft basic data" PARTUUID="6995254a-06c6-44d0-ab93-b9fb910f257e"
/dev/sda2: UUID="c64adf56-cf9f-46ef-9751-5f119dae26ad" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="45e458a4-8f16-4b32-a61e-45d34b51f28a"
/dev/zram0: UUID="4e7e5bcd-c0aa-4c99-bc9c-f69743189e67" TYPE="swap"

edit the kernel command line so the kernel can find the rootfs, look for root= and change it to root=PARTUUID= and make it to fit your PARTUUID, Here is mine:

sudo nano target/boot/cmdline.txt

here is mine: (substitute your PARTUUID of /dev/sda2)

console=serial0,115200 console=tty1 root=PARTUUID=45e458a4-8f16-4b32-a61e-45d34b51f28a rootfstype=ext4 elevator=deadline rootwait

and edit the fstab to match your disks

sudo nano target/etc/fstab

Again here is mine : (substitute your UUID’s )

UUID=c64adf56-cf9f-46ef-9751-5f119dae26ad  / ext4    defaults,noatime 0 0
UUID=D17B-9F4F  /boot vfat    defaults,noatime 0 0

THAT’S IT :grinning:

Well you may want to remove the “first-boot” flag so you can reboot your RPI without running system-init.

sudo rm target/var/spool/first-boot

Poweroff end remove the SD-Card and power on again:
If your systems boots from SSD and you are happy:

touch /var/spool/first-boot

And reboot…

2 Likes