egrechko
Posts: 2
Joined: Mon Jul 27, 2020 1:31 am
Location: Portland, Oregon
Contact: Website

USB Boot Ubuntu Server 20.04 on Raspberry Pi 4

Mon Jul 27, 2020 1:57 am

Hey folks. Recently I got Ubuntu Server 20.04 to USB boot on a Raspberry Pi 4 so I wanted to post my guide on here to help some people out.

I also have a write up on my website. https://eugenegrechko.com/blog/USB-Boot ... berry-Pi-4

Update firmware to support USB Booting

First things first you need to make sure that your Raspberry Pi 4 supports USB Booting. In order to do this, you will have to install Raspbian on an SD card and update the firmware. To do this reference this video https://www.youtube.com/watch?v=tUrX9wzhygc. You'll want to watch up to the part where he verifies the boot loader is updated, around 7:56. If you already updated your bootloader skip to the next step.

Download 64 bit version of Ubuntu Server

Now we need to download the 64bit version of Ubuntu Server for Raspberry Pi 4. Then we'll flash the image to our SSD using Raspberry Pi Imager.

Visit the Ubuntu Raspberry Pi download page and grab yourself the 64-bit version for the RP4.

Flash Image to SSD

After downloading our image we'll need to install Raspberry Pi Imager. Visit the Raspberry Pi Downloads page and install it on your computer.

Next open Imager. Click "Choose OS" & find your newly downloaded image of Ubuntu Server. After that click on "Choose SD Card" and select your SSD drive. Finally, click Write and wait for the process to finish.

Mount system-boot partition on SSD

Now we need to mount the system-boot partition on the SSD drive in order to change some things.

Code: Select all

sudo mkdir /mnt/ssdboot
sudo mount /dev/sdb1 /mnt/ssdboot
cd /mnt/ssdboot
Uncompress the kernel

IMPORTANT: You will have to rerun this step every time ubuntu updates the kernel.

First, we're going to uncompress the vmlinuz file into vmlinux. This is because booting from a compressed 64bit arm kernel is not currently supported.

Find out where the gzipped content starts in the image.

Code: Select all

od -A d -t x1 vmlinuz | grep '1f 8b 08 00'
Expected output
0000000 1f 8b 08 00 00 00 00 00 02 03 ec 5b 0f 74 54 e5
The first string of numbers 0000000 is the location that we're looking for. In this case its right at the beginning of the image.

Now use dd to extract the data and zcat to uncompress it into a file. If your number was something other than 0000000 make sure you put that number as the skip value.

Code: Select all

dd if=vmlinuz bs=1 skip=0000000 | zcat > vmlinux
Update config.txt for booting

Now that we have the uncompressed image we'll want to update the config.txt file in order to tell the Pi how to boot.

Edit config.txt ( you can use nano or gedit if you're not comfortable with vim )

Code: Select all

vim config.txt
Start by commenting out all of the [pi*] blocks. Comment out the block and it's options. Should look like this.

Code: Select all

#[pi4]
#kernel=uboot_rpi_4.bin
#max_framebuffers=2

#[pi2]
#kernel=uboot_rpi_2.bin

#[pi3]
#kernel=uboot_rpi_3.bin
Add kernel=vmlinux & initramfs initrd.img followkernel in the [all] section. Leave the rest the way it was before.

Code: Select all

[all]
arm_64bit=1
device_tree_address=0x03000000
kernel=vmlinux
initramfs initrd.img followkernel
Update .dat & .elf files

Now we need to update the .dat & .elf files to the latest version in the master branch of the raspberrypi/firmware Github. https://github.com/raspberrypi/firmware ... aster/boot

Download boot folder

Visit the link above and download the folder using something like GitZip. https://gitzip.org/

Copy files from downloaded folder

Next copy all of the .dat & .elf files into the boot folder. Overwrite all files.

Code: Select all

cp ~/Downloads/firmware-/boot/*.dat ./

cp ~/Downloads/firmware-/boot/*.elf .
Boot

Now you're ready to boot your Raspberry Pi. Make sure the SD card is unplugged. Unmount the SSD from your computer. Plug it into your Raspberry Pi and power on.

If you run into any issues let me know. I'll do my best to help you out. Hope this helped some people!
I'm not gambling, mom, I'm day trading!

User avatar
ranrinc
Posts: 16
Joined: Tue Feb 25, 2020 7:23 am
Location: Jakarta Indonesia
Contact: Website

Re: USB Boot Ubuntu Server 20.04 on Raspberry Pi 4

Tue Jul 28, 2020 12:15 pm

Thanks for the guide, however I made some changes and adding jsciamms procedure into it. My guide can be read here https://krdesigns.com/articles/Boot-ras ... ut-microsd

egrechko
Posts: 2
Joined: Mon Jul 27, 2020 1:31 am
Location: Portland, Oregon
Contact: Website

Re: USB Boot Ubuntu Server 20.04 on Raspberry Pi 4

Tue Jul 28, 2020 1:25 pm

ranrinc wrote:
Tue Jul 28, 2020 12:15 pm
Thanks for the guide, however I made some changes and adding jsciamms procedure into it. My guide can be read here https://krdesigns.com/articles/Boot-ras ... ut-microsd
Wow, great guide. I'm going to incorporate the kernel uncompress script and a couple of other things into my Pi to see how they work. Thanks!
I'm not gambling, mom, I'm day trading!

User avatar
esbeeb
Posts: 167
Joined: Sun Feb 05, 2012 12:23 am

Less elegant, simple method of running root fs from a USB-attached SATA drive.

Tue Jul 28, 2020 2:35 pm

Hello.

I appreciate this breakthrough. :)

I too have come up with a simple way to gain the speed of running Ubuntu from a USB-attached SATA drive (albeit, the "system-boot" partition is still run from a MicroSD card, which is why it's "less elegant"). Please see here, for this "less-elegant" method.

It basically involves some careful labeling of a couple of partitions, to get the "writable"-labelled root filesystem to be loaded from the USB-attached SATA drive, instead of running it from the MicroSD card.

User avatar
ranrinc
Posts: 16
Joined: Tue Feb 25, 2020 7:23 am
Location: Jakarta Indonesia
Contact: Website

Re: Less elegant, simple method of running root fs from a USB-attached SATA drive.

Fri Jul 31, 2020 3:17 pm

esbeeb wrote:
Tue Jul 28, 2020 2:35 pm
Hello.

I appreciate this breakthrough. :)

I too have come up with a simple way to gain the speed of running Ubuntu from a USB-attached SATA drive (albeit, the "system-boot" partition is still run from a MicroSD card, which is why it's "less elegant"). Please see here, for this "less-elegant" method.

It basically involves some careful labeling of a couple of partitions, to get the "writable"-labelled root filesystem to be loaded from the USB-attached SATA drive, instead of running it from the MicroSD card.
Yup and old method, by simply using the microSD to redirect its boot to USB Drive instead, but today the best way to do it is using this new method so we can have a better used of the microSD for something else.. :D

Return to “Ubuntu”