How to Boot a Pi CM4 from NVMe SSD

CM4 NVMe SSD Boot Feature

I have been working on a couple of photography projects with the Raspberry Pi CM4 (more on this soon). In order to extract the most out of this tiny little computer, I wanted to use an NVMe SSD drive instead of the built-in eMMC chip (or a microSD card).

Here is a step-by-step guide on how to get your CM4 booting from an NVMe SSD drive. This is working as of November 2021. Although I’m using the CM4 IO board, these steps should work with any NVMe connected through the CM4’s PCIe bus.

Change the Boot Order

NVMe SSD boot is still in beta so there are a couple of extra steps you need to take before changing the boot order. You should perform these steps on a Linux machine, like a Raspberry Pi 4. It is possible to do this on a Windows machine, but I have not tested it myself.

First, download the usbboot utility to your Linux machine. This will be used to connect the CM4 as a device to your machine. After the CM4 is connected, you will update the bootloader to include the option to boot from an NVMe drive.

git clone --depth=1 https://github.com/raspberrypi/usbboot
cd usbboot

The command above will download (clone) the newest usbboot utility to your machine, followed by moving into the folder created by the download.

Next, make sure the libusb-1.0-0-dev is installed on your machine.

sudo apt install libusb-1.0-0-dev

Now, build the usbboot tool. Again, make sure you are inside the usbboot folder created above.

make

Edit the recovery/boot.conf file to add NVMe boot as the first option. NVMe is option number 6. Keep in mind that the options are read from right to left.

nano recovery/boot.conf

Here is what my BOOT_ORDER looks like. You don’t have to edit anything else in this file.

BOOT_ORDER=0xf25416

Save your changes to recovery/boot.conf and close the editor. (“Ctrl+X”, then “y”, then “Return/Enter”)

Run recovery/update-pieeprom.sh to update pieeprom.bin with the new boot order settings.

cd recovery
./update-pieeprom.sh
cd ..

At this point, you are ready to connect the CM4 to the host computer and update the bootloader. Do not power the CM4 yet. First, connect the CM4 to the host computer using the micro USB connector on the CM4 IO board. Also, make sure there is a jumper on “disable eMMC Boot”. You don’t want the CM4 to boot into the operating system just yet.

Run usbboot on the host computer. It will wait for a connection.

sudo ./rpiboot

Power up the CM4 and you will see the CM4 show up as a storage device on your host machine.

Finally, flash the new bootloader information to the CM4 by running usbboot again. But this time, with an extra parameter.

sudo ./rpiboot -d recovery

At this point, you will have changed the boot order on the CM4. Next, we will take a look at how to move the OS and the boot partition to the NVMe drive.

Moving the files to the NVMe SSD drive

Disconnect the USB cable and power off the CM4. Next, remove the jumper from “disable eMMC Boot”. This is the last time you will be booting from eMMC.

Connect the NVMe drive to the board and boot up the CM4. All of the commands described in this section are to be made on the CM4 (or on another computer through SSH)

For starters, check that the CM4 can see the new NVMe drive.

lsblk

If you see the NVMe drive listed, proceed to transfer the OS to the new drive. Use the SD Card Copier selecting the eMMC drive as the source and the NVMe drive as the target. Make sure to check the “New Partition IDs” box.

We are almost done. On to the final steps, which is to load the new firmware to the NVMe drive. To do this, you need to mount the drive partitions first.

mkdir mnt
mkdir mnt/fat32
mkdir mnt/ext4
sudo mount /dev/nvme0n1p1 mnt/fat32
sudo mount /dev/nvme0n1p2 mnt/ext4

Run rpi-update on the mounted drive.

sudo ROOT_PATH=mnt/ext4 BOOT_PATH=mnt/fat32 rpi-update

Shut down the CM4 and power it up again. If everything was setup correctly, you should see the activity light on NVMe drive blinking (if there is an activity LED) as the CM4 boots from this drive.

To confirm that the CM4 has booted from the new NVMe SSD drive, open a terminal window and run the command below.

lsblk

You should see the root and boot partitions mounted from the NVMe drive.

What’s Next?

In the future, when this software is no longer in beta, you will be able to flash the OS image directly to the NVMe SSD. Until then, you’ll have to perform the steps above.

Let me know in the comments below what plans do you have to use the CM4 and NVMe storage. As for me, I’m working on a couple of photography-related projects that involve the CM4 and it was great to explore its capabilities. Now, I know that my projects can count on fast and reliable NVMe SSD storage.

Related Products to this Post

You can support the site by using one of the affiliate links below. By using the links below, you are helping out the website without any additional cost to you. Every time someone buys an item through these links, the website gets a very small commission. I keep all the ad links at the bottom of the page so they don’t interfere with the article flow.

NVME to PCI-E 4.0 Adapter: https://amzn.to/47IUG9Z
Crucial 1TB SSD: https://amzn.to/3RVZhRu
KIOXIA 128GB NVME Drive: https://amzn.to/40ihueF

André

André is just a regular dude that loves photography, traveling, and hacking stuff. When he's not planning his next bikepacking trip, he's tinkering with a couple of Raspberry Pi's and writing personal apps. He usually codes in CFML or JavaScript.

You may also like...

8 Responses

  1. Nice writeup, thanks for the updated instructions compared to a few of the older ones about (especially with the recovery folder, and not the NVME as many other posts have). As for me, I’m using mine to do some timelapse work and hoping the NVME can improve file IO for on-device processing of images. What’s your project in-the-works?

  2. Bill says:

    Just wanted to say thank you for this guide, because it’s the only one I’ve seen so far that was updated for the current versions of the software, and it worked perfectly!

  3. Dozer says:

    Have you tried something similar installing PINN and multiple OS’s by any chance?

  4. nochamol says:

    Hi, i used your tutorial to Update my CM4 board to use an nvme ssd and worked for me, using Ubuntu 22.04 LTS on amd64 i had to run the : sudo ./rpiboot to be able to write the remote CM4 board fs, and i did the SD copy prior to the switch of the boot order, but i worked as expected, thx for this tutorial,

Leave a Reply

Your email address will not be published. Required fields are marked *