Adding an NVMe Drive to a Raspberry Pi 5

calendar

February 18, 2024

categories
Reviews
tags
nvme pi 5 raspberry pi

Content:

One of the new features of the Raspberry Pi 5 is the addition of a PCIe connector. Located on the rear of the board, behind the power input, the connector provides a single lane of Gen 2 PCI express connectibity.

While PCIe was present on the Raspberry Pi 4, all available lanes were used by the VL805 USB 3.0 controller. Various mods exist to repurpose the PCIe, including several attempts to use external graphics cards. The port on the Pi 5 marks the first time a mainline Raspberry Pi board has featured a user-accessible PCIe connection.

Given that the microSD storage is still one of the weak points of the Pi, it’s unsurprising that several storage addons have been released to make use of this port, allowing an NVMe drive to be used as the Pi boot drive.

We have one of these boards, the NVMe base from Pimoroni. This article will go through the process of installing the board, and checking out the performance.

Unpacking the Board

The board comes in a small pouch-like package, along with the screws and cable needed to complete the installation.

Pimoroni also offer known compatible NVMe drives with the base, which is useful if you don’t have a drive lying around you wish to use.

There are no instructions included in the package, but Pimoroni do make a video guide available for you to follow. We also have our own video outlining the initial setup process, or you can continue to follow this article.

Pre-configuring the Drive

If you already have an OS you wish to install on the drive, it’s possible to install it now through a PC (as you would if using a microSD card), and skip the OS installation step later on. Be aware that your Pi will need to be running up-to-date firmware to ensure NVMe booting is enabled, though this will become less of an issue as time progresses (and newer firmware comes pre-installed).

Installing the Drive

To mount the drive to the board, you’ll need to take note of the length of the drive you’re using. A typical NVMe drive is a 2280, but the one we have here is a 2242. You can do a test fit to check the length of the drive if you’re unsure. The board includes mounting holes for 2230, 2242, 2260 and 2280 drives.

Our size 2242 drive

Be aware that this board is designed for NVMe drives. SATA drives using the M.2 connector will physically fit, but will not work with this board. Your drive should specify which type it is – ours has both PCIe and NVMe on the label.

Turning the base over, you’ll need to insert the medium-sized of the included screws into the hole corresponding to the drive size you’re using. There’s only one of these screws, so it should be easy to find. Add a nut to the other size of the board, to hold the screw in place.

Next, slot the drive into position, using another nut to hold it parallel to the NVMe base.

NVMe Base with drive fitted
NVMe base with the drive installed. Note the nut holding the drive in position

Connecting to the Pi

To connect the base to the Pi, a small custom cable is used. This cable is labelled, so it should be obvious which way to install it. The text on the cable will be visible when the install is complete.

Cable to connect the base to the Pi
Cable used to connect the base to the Pi

Ensure that the tab is lifted before pushing the cable into the NVMe base. Once it’s fully in place, close the tab to secure it.

To sit the drive under the Pi, the four standoffs need to be installed. Fit these to the four holes on the outside of the base, using the short screws.

Here’s where we deviate slightly from the Pimoroni video guide. We chose to install the Pi onto the standoffs, using the remaining short screws to hold it in place. Partially tighten them to begin with, so minor adjustments to positioning can be made to get all screw holes lined up correctly. Once all are in place, tighten them fully to secure the base to the Pi.

All that is left is to plug in the cable. Lift the locking tabs either side of the connector, to lift the tab up. The cable can then be slotted in to the tab. Take care not to crease the cable, and make a nice smooth bend, to prevent damage to the cable.

In the Pimoroni guide, they chose to plug the cable in before attaching the Pi, allowing the Pi to be flipped onto the base once the cable is installed.

With this done, the installation is complete.

Installing an OS

Assuming you don’t already have an OS installed on the NVMe drive, you’ll need to install one through the Pi itself. To do this, you’ll need to use a microSD card to boot from the Pi.

Before proceeding further, check that your Pi firmware is up-to-date. To do this, use the Raspberry Pi Software Configuration tool.

raspi-config
raspi-config bootloader version
Select the bootloader version option in raspi-config to update to the latest firmware

Under bootloader version, select latest to use the latest version of the Pi firmware.

Once this is complete, reboot the system to complete the firmware update.

It’s possible to use raspi-config to set the NVMe drive to the default boot option, but it’s not necessary to do this (the default option will boot from NVMe if a microSD is not bootable).

With the firmware up-to-date, check that the drive is identified. You should see the drive on the desktop if it is already formatted, but you can also find it using a terminal.

blkid

While the microSD card will be found under a /dev/mmcblk* mount point, NVMe drives show up under /dev/nvme*.

If you’re installing an OS using dd, ensure you use the /dev/nvme* path to install the OS to the NVMe drive. Also, check the OS you’re installing has support for the Raspberry Pi 5 – at the time of writing, not all of the popular Pi OS’s support the new board.

To install Raspberry Pi OS, you can use the Raspberry Pi Imager directly from the Pi. The options should be self-explanatory, and the NVMe drive should be automatically detected.

Once your OS is installed, you can remove the microSD card and the Pi will boot from the new OS.

Testing Performance

To get an idea of the performance of the drive using the NVMe base, the hdparm utility was used. This utility allows read speeds to be tested, using the following command:

hdparm -tT /dev/nvme0n1

The results of this benchmark are as follows:

Timing cached reads: 4504 MB in 2.00 seconds = 2255.73 MB/sec
Timing buffered disk reads: 1300 MB in 3.00 seconds = 433.06 MB/sec

Cached reads are not important, but included as a point of reference. This value is limited by the performance of the rest of the system.

The timing buffered disk reads show the read speed for pulling data directly from the NVMe drive. At over 400MB/sec, this is much greater than speeds you’ll reach using a microSD card.

By default, the PCIe slot operates at PCIe gen 2 speeds. This is the speed at which the connection has been certified. However, it’s possible to enable PCIe gen 3, with the caveat that it’s not certified to run in this configuration.

To enable this setting, add

dtparam=pciex1_gen=3

to the /boot/firmware/config.txt file.

Rebooting the Pi, the benchmark test was repeated, with the following results.

Timing cached reads: 4932 MB in 2.00 seconds = 2470.52 MB/sec
Timing buffered disk reads: 2518 MB in 3.00 seconds = 839.26 MB/sec

Enabling this setting almost doubled the read speeds, to over 800MB/sec.

It’s worth pointing out here that the drive you’re using will also influence the benchmark results, particularly if you have a slow drive.

If performance is key, enabling gen 3 mode seems to be very worthwhile.

Conclusion

Overall, the addition of an NVMe drive to the Raspberry Pi 5 is a great way to overcome one of the weak points of the Pi. The ability to boot directly from the drive with no config changes needed (assuming an up-to-date firmware) is fantastic, and a great improvement on the USB boot option available on previous Pi’s.

While the Pimoroni base isn’t the only one available, it’s a well designed board and fits nicely below the Pi 5. The inclusion of a compatibility list is a big plus, given that compatibility issues will realistically be down to the Pi itself rather than the base (and thus impact other NVMe addons). I’d also expect to see compatible case designs from Pimoroni in the future, given their history in selling Pi cases.

Video

We also have a video where we take a look at this board, and show the process of attaching it to the Pi, and running the benchmarks referred to in this article. Be sure to check it out!

If you like what we do, consider supporting us on Ko-fi