how I set up my Raspberry Pi to boot from an external USB drive
I have a raspberry pi that serves a Nextcloud instance and some other personal sites. Rather than storing data in the cloud, we say we store ours in the cupboard.
Until this week, it was a Raspberry Pi 3. Working on it was a bit of a pain because it didn't have much memory, so I've finally cracked and bought an 8GB Raspberry Pi 5.
The old machine had been booting from an SD card, but with big things like databases, server files and the nextcloud data on an external USB hard disk.
I'd already lost some data and had to remake it once due to a corrupted SD card, so I wanted to take the opportunity to switch to booting from the hard disk.
All the guides I found online on booting from USB assume you're happy to wipe the USB disk. I didn't want to do that because it had all my data on it. I've worked out how to do it, so I thought I'd write this down in case it helps anyone else.
The old Pi had a 32GB SD card in it, with a FAT boot partition and an ext4 partition called rootfs
which had the real filesystem.
The USB disk is a 1TB drive, with a single ext4 partition.
My first question was whether it was safe to make the partition smaller, without losing any data.
The answer is yes: I took the easy route and plugged the drive into my laptop, then used Ubuntu's Disks app to resize it so there's 32GB free at the end.
I then added a FAT partition the same size as the one on the SD card, and another ext4 partition to use up the rest of the space.
I used dd
to copy the data from the SD card into those partitions.
I also edited the FAT partition to say it's bootable
, but I don't know if that was necessary.
On a separate SD card, I used the Raspberry Pi Imager to wipe it and set up Raspbian for the Raspberry Pi 5.
I did that twice, because the first time round I didn't notice the other tabs where you set up wifi details and ssh access.
I put that in the Pi 5 and turned it on, then connected through ssh.
I ran raspi-config
and in the Advanced settings menu changed the boot order to try USB first.
But it turns out that isn't enough: you also have to edit /boot/firmware/cmdline.txt
and change the root
option to the UUID of the partition on the USB disk.
I got that by running lsblk -o name,partuuid
on the machine with the USB drive plugged in.
Once I'd done that, the Pi 5 booted up well enough: it's using the boot partition on the SD card, but the filesystem root is mounted from the USB drive.
I don't know why it's not using the boot partition on the USB disk. I'm not too bothered about that, though.