Raspberry Pi 5 NVMe Boot: M.2 HAT+ Setup Guide

16 min read

,
Techzei graphic on a white background showing a Raspberry Pi 5 with an M.2 HAT+ and NVMe SSD stacked on top, with the text Boot from an NVMe SSD

Raspberry Pi 5 NVMe boot needs a compatible SSD, an M.2 HAT+ or PCIe adapter, and an up-to-date bootloader. Write Raspberry Pi OS to the SSD, then check that the Pi starts from it. The official HAT+ boards are detected automatically; other adapters can need extra configuration.

An SSD is useful when your Pi runs databases, containers or other services that write frequently. It can improve responsiveness and reduce dependence on a microSD card. For a small home server or a Pi running Pi-hole with Unbound, storage reliability matters as much as headline speed.

Why boot a Raspberry Pi 5 from NVMe instead of microSD

The Raspberry Pi 5 has a single-lane PCIe 2.0 interface on a small FPC connector on the edge of the board. That link tops out at 500 MB/s, which is far more than the microSD slot can deliver, but the bigger difference is random access. Operating systems, Docker, databases and log files mostly do small 4 kB reads and writes, and that is where microSD cards struggle.

Raspberry Pi publishes figures for its own SD cards and SSDs, which makes for a fair comparison because both are tuned for the Pi 5:

Storage (official Raspberry Pi)Interface on Pi 54 kB random read4 kB random write
Raspberry Pi SD cardSDR1045,000 IOPS2,000 IOPS
Raspberry Pi SSD 256 GBPCIe (NVMe)40,000 IOPS70,000 IOPS
Raspberry Pi SSD 512 GBPCIe (NVMe)50,000 IOPS90,000 IOPS
Raspberry Pi SSD 1 TBPCIe (NVMe)90,000 IOPS90,000 IOPS

The SSD figures show why small, frequent writes are a better reason to upgrade than maximum transfer speed. They are manufacturer ratings, not a benchmark of this setup; actual performance depends on the drive, workload and configuration.

An NVMe drive can report temperature, wear and errors through SMART. That helps you monitor it, but neither an SSD nor a healthy-looking SMART report replaces a backup.

Who can skip it? If your Pi 5 is a desk toy, a retro gaming box or a learning machine that you reflash every few weeks, a good A2 microSD card is fine. NVMe is worth it when the Pi stays on and does real work.

What you need

Raspberry Pi M.2 HAT+ mounted on a Raspberry Pi 5 with its empty M.2 M key slot, 2230 and 2242 mounting points and the PCIe ribbon cable connected
The standard M.2 HAT+ accepts 2230 and 2242 drives. Image: Raspberry Pi

The hardware list is short, but two details decide whether a drive fits at all: the form factor (its length) and the key on its edge connector.

  • A Raspberry Pi 5. The Pi 4 has no PCIe connector, so this guide does not apply to it.
  • An M.2 adapter. Raspberry Pi sells the M.2 HAT+ and the M.2 HAT+ Compact, from $12. Both convert the Pi’s PCIe connector to a single M.2 M key slot and can supply up to 3 A to the drive.
  • An M.2 M key NVMe SSD in the right size. The standard M.2 HAT+ takes 2230 and 2242 drives. The Compact takes 2230 only. Full-length 2280 drives need a third-party board built for them.
  • A microSD card with Raspberry Pi OS for the first boot, or a wired Ethernet connection if you want to use Network Install instead.
  • A proper power supply. Raspberry Pi recommends its 27 W USB-C Power Supply for the Pi 5. On a 3 A supply the Pi limits its USB ports to 600 mA in total, which can bite if you also hang a USB drive off it.
  • Cooling. The standard M.2 HAT+ uses 16 mm spacers so the Raspberry Pi Active Cooler fits underneath. The Compact is shaped to sit inside the official Raspberry Pi Case around its fan, but there is no room for the Active Cooler under it.
M.2 HAT+M.2 HAT+ CompactThird-party PCIe boards
Drive sizes2230, 22422230 onlyVaries, some take 2280
Active Cooler underneathYesNoDepends on the board
Official Raspberry Pi CaseOnly with lid and fan removedYes, designed for itRarely
Auto-detected (HAT+ spec)YesYesOnly if HAT+ compliant
Extra config for bootNoneNoneOften dtparam=pciex1 and PCIE_PROBE=1

Raspberry Pi’s own SSD comes in 256 GB, 512 GB and 1 TB, uses the 2230 size and is an officially supported option for the Pi 5. Plenty of other 2230 and 2242 NVMe drives work, but compatibility varies between controllers, so buy from a seller that accepts returns if you pick something else. Raspberry Pi lists its approved resellers by region under the Buy now button on each product page, which is a useful way to find the official boards in your region. On marketplaces, check that a listing names the exact board, because many generic adapters use similar wording.

Step 1: Update Raspberry Pi OS and the bootloader

Start from a working Raspberry Pi OS install on microSD. NVMe boot depends on the Pi 5’s bootloader, which lives in an EEPROM chip on the board rather than on the card, so an old bootloader can stop everything else from working. First bring the OS up to date:

sudo apt update && sudo apt full-upgrade

Then check which bootloader the Pi is running:

sudo rpi-eeprom-update

Raspberry Pi’s M.2 HAT+ documentation says any bootloader dated 6 December 2023 or later is new enough. Check the actual reported version rather than relying on when the board was bought. If the output says an update is available, or the date is older than December 2023, open the configuration tool:

sudo raspi-config

Go to Advanced Options > Bootloader Version, choose Latest, finish, and then apply the update and reboot:

sudo rpi-eeprom-update -a
sudo reboot

After the reboot, run sudo rpi-eeprom-update again. It should report BOOTLOADER: up to date. Raspberry Pi OS also runs an rpi-eeprom-update service at startup that installs new bootloader releases automatically, so leave it enabled unless you have a specific reason to freeze the version.

Shut the Pi down with sudo poweroff and unplug it before you touch the hardware. Raspberry Pi is explicit that you should never connect or disconnect an M.2 device while the board has power.

Step 2: Fit the M.2 HAT+ and the SSD

Three-step illustration of fitting the Raspberry Pi M.2 HAT+: spacers and GPIO stacking header on the Pi 5, inserting an M.2 SSD into the HAT, and the finished assembly with the ribbon cable connected
Disconnect power before fitting the HAT, cable and SSD. Image: Raspberry Pi (illustrations), Techzei (layout)

The standard M.2 HAT+ goes on in this order. If you have the Active Cooler, fit it first, because you cannot reach the mounting holes once the HAT is on.

  1. Screw the four threaded spacers to the Pi 5 with the supplied screws.
  2. Press the 16 mm GPIO stacking header firmly onto the Pi’s GPIO pins. Orientation does not matter, but every pin must go in.
  3. On the Pi’s PCIe connector, gently lift the cable holder from both sides. Insert the ribbon cable with the metal contacts facing the USB ports, then push the holder back down evenly.
  4. Place the HAT on the spacers and screw it down.
  5. Lift the holder on the HAT’s own connector, insert the other end of the ribbon cable with the copper contacts facing up, and press the holder closed.
  6. Remove the knurled drive screw, slide the SSD into the M.2 slot at a slight upward angle, press it flat, and fit the screw so its notch holds the end of the drive. Do not overtighten it.

The Compact version is simpler: there is no stacking header, the ribbon cable goes into the Pi’s PCIe port with the contacts facing inward towards the USB ports, and only 2230 drives fit.

If the drive is not detected, check the ribbon cable first. A cable that is crooked or not fully inserted at either end can prevent detection. Disconnect power before reseating it.

Step 3: Check that the Pi can see the drive

Put the microSD card back, power on and open a terminal. Raspberry Pi OS detects HAT+ boards automatically, so the drive should appear straight away:

ls -l /dev/nvme*

You want to see two entries, /dev/nvme0 (the controller) and /dev/nvme0n1 (the drive’s storage namespace). lsblk gives a clearer view of all disks and their partitions:

lsblk

A brand-new SSD has no partitions, so it does not appear on the desktop and sudo blkid shows no partition UUID for it. That is normal. Raspberry Pi Imager partitions and formats the drive when it writes the OS, so you do not need to prepare it by hand.

If /dev/nvme0 is missing, power off and reseat the ribbon cable before doing anything else. With a non-HAT+ adapter, also add dtparam=pciex1 to /boot/firmware/config.txt and reboot, because the PCIe connector is only enabled automatically when a HAT+ board is attached.

Step 4: Put Raspberry Pi OS on the NVMe drive

You can install fresh, clone an existing card, or use Network Install. A fresh install gives you a clean system and is the method Raspberry Pi documents. Cloning keeps everything you have already set up on the microSD card. Writing an image or cloning to the SSD overwrites its contents, so back up anything already on it.

Option A: Fresh install with Raspberry Pi Imager on the Pi

Imager runs on the Pi itself, so you do not need an M.2 enclosure or another computer. On Raspberry Pi OS, install it with:

sudo apt install rpi-imager

Open Imager from the applications menu, choose Raspberry Pi 5 as the device and Raspberry Pi OS (64-bit) (or the Lite version for a headless server) as the OS, and pick the NVMe drive as the storage. Be careful here, because the microSD card you are running from also appears in the list. Use the customisation screens to set the hostname, user account, Wi-Fi and SSH, then write the image. Imager creates the same layout as an SD card install: a small FAT partition mounted at /boot/firmware and an ext4 root partition that fills the rest of the drive.

You can also write the image from a laptop or desktop with the SSD in a USB M.2 enclosure, then fit the drive to the HAT. The on-Pi route avoids buying the enclosure.

Option B: Clone your existing microSD card

If the Pi already runs a configured system, cloning saves you from rebuilding it. On Raspberry Pi OS with the desktop, use SD Card Copier, Raspberry Pi’s own cloning tool. Set Copy From Device to the microSD card and Copy To Device to the NVMe drive, tick New Partition UUIDs, and press Start. The tool creates fresh partitions, copies files across and resizes the copy to fill the larger drive.

The New Partition UUIDs box matters. Raspberry Pi OS finds its root filesystem by partition UUID, and if the SD card and the SSD carry identical IDs while both are inserted, the system can end up mounting the wrong one. Fresh IDs avoid that, and the tool updates the copy’s /etc/fstab and cmdline.txt to match.

For a system running databases or containers, a fresh install followed by a restore from application backups is often easier to verify than cloning a live filesystem. Stop active writers before any live copy, and check the restored services before retiring the card.

Option C: Network Install with no microSD card

With a current bootloader, a Pi 5 with a keyboard, monitor and wired Ethernet can download Imager over the network and install straight to a blank NVMe drive. Power on with no bootable storage attached, or hold Shift during power-on, and follow the on-screen installer. It is handy for a brand-new Pi, but you still need the bootloader to be recent enough, so an SD card is the safer starting point for an older board.

Step 5: Set the boot order (BOOT_ORDER)

Techzei diagram explaining how to read the Raspberry Pi 5 BOOT_ORDER value 0xf416 from right to left: NVMe first, then SD card, then USB, then restart
BOOT_ORDER is read from right to left: this example tries NVMe first. Image: Techzei

The Pi 5’s default bootloader configuration uses BOOT_ORDER=0xf461, which tries the SD card first, then NVMe, then USB. So if no microSD card is inserted, the Pi finds the NVMe drive and boots from it on its own. Most people want the card out anyway, but if you plan to keep a card in the slot, or you just want the Pi to try NVMe first, change the boot order.

The easy way: raspi-config

Run sudo raspi-config, open Advanced Options > Boot Order and pick NVMe/USB Boot (described as “Boot from NVMe before trying USB and then SD Card”). The tool writes the change to the EEPROM, and it takes effect after a reboot. When an NVMe drive is present, this option sets BOOT_ORDER=0xf146.

The manual way: rpi-eeprom-config

To see or edit the bootloader settings yourself, use:

rpi-eeprom-config
sudo rpi-eeprom-config --edit

The first command prints the current configuration. The second opens it in a text editor and applies your changes to the latest bootloader image on the next reboot. Raspberry Pi’s PCIe documentation suggests this line for NVMe boot:

BOOT_ORDER=0xf416

The value looks cryptic, but it is easy to read once you know the rule: each hex digit after 0x is one boot mode, and the bootloader tries them from right to left.

DigitBoot modeWhat it does
1SD CARDBoot from the microSD card
2NETWORKNetwork boot from a TFTP server
4USB-MSDBoot from a USB mass storage device
6NVMEBoot from an NVMe SSD on the PCIe interface
7HTTPHTTP boot over Ethernet
eSTOPStop and show an error pattern
fRESTARTGo back to the first mode and loop

So 0xf416 means NVMe first, then SD card, then USB, then start again. The raspi-config value 0xf146 means NVMe, then USB, then SD. The Pi 5’s default, 0xf461, is SD card, then NVMe, then USB. Pick the order that matches how you would recover the Pi if the SSD failed: with NVMe first, a fresh rescue card in the slot is ignored while the SSD still boots, whereas the default SD-first order lets you recover just by inserting a card. That is why leaving the default order and simply keeping the slot empty is a perfectly good choice.

If you use a third-party adapter that is not HAT+ compliant, add this line as well so the bootloader scans the PCIe bus during boot:

PCIE_PROBE=1

Save, close the editor and reboot to write the new configuration to the EEPROM.

Step 6: Reboot and confirm you are running from NVMe

Shut down, remove the microSD card (unless you set NVMe first and want to keep it), and power on. Once you are logged in, check what the root filesystem is mounted from:

findmnt /
lsblk

findmnt / should show /dev/nvme0n1p2 as the source, and lsblk should list nvme0n1p1 mounted at /boot/firmware and nvme0n1p2 mounted at /. If you still see mmcblk0 partitions in those mount points, the Pi booted from the card, so revisit the boot order or the clone.

It is worth checking the drive’s health once while everything is fresh. The nvme-cli package reads the SSD’s SMART log, including temperature, percentage used and media errors:

sudo apt install nvme-cli
sudo nvme smart-log /dev/nvme0

Keep an eye on temperature in particular if the SSD sits directly above the Active Cooler’s exhaust or inside a closed case.

Optional: Enable PCIe Gen 3 on the Raspberry Pi 5

Close-up of the Raspberry Pi 5 board with the small FPC connector for PCIe circled in red, the port the M.2 HAT+ ribbon cable plugs into
The HAT connects through the Pi 5’s PCIe ribbon connector. Image: Raspberry Pi

By default the Pi 5 runs its PCIe link at Gen 2.0 speed, 5 GT/s. You can switch it to Gen 3.0, 8 GT/s, which roughly doubles the theoretical link bandwidth. Raspberry Pi’s warning is direct: the Pi 5 is not certified for Gen 3.0 speeds and Gen 3.0 connections might be unstable. The M.2 HAT+ is also listed by Raspberry Pi as a PCIe 2.0 board, so Gen 3 runs it outside its rated spec.

To turn it on with raspi-config, go to Advanced Options > PCIe Speed, choose Yes to enable PCIe Gen 3 mode, finish and reboot. Or add this line to /boot/firmware/config.txt yourself and reboot:

dtparam=pciex1_gen=3

You can confirm the negotiated link speed with lspci. Look for the LnkSta line on the NVMe controller, which should read 8GT/s after the change:

sudo lspci -vv | grep -E "Non-Volatile|LnkSta:"

Leave Gen 3 disabled on a Pi running services you depend on. Gen 2 already provides a substantial upgrade over microSD for many workloads. If you try Gen 3, monitor for PCIe errors, freezes or filesystem problems and revert if they appear.

Troubleshooting Raspberry Pi 5 NVMe boot

Techzei cheat sheet card listing the key Raspberry Pi 5 NVMe boot commands: rpi-eeprom-update, ls /dev/nvme*, rpi-eeprom-config --edit, BOOT_ORDER=0xf416, PCIE_PROBE=1, dtparam=pciex1_gen=3 and findmnt
Use the commands for your chosen adapter and boot configuration. Image: Techzei

Most problems fall into a handful of patterns, and the first command to run is almost always ls -l /dev/nvme* from a working microSD boot. It tells you straight away whether you are dealing with hardware or boot configuration.

SymptomLikely causeWhat to try
No /dev/nvme0 at allRibbon cable not fully seated, or wrong orientationPower off, reseat both ends, check contact direction
Drive missing with a third-party adapterPCIe not enabled for non-HAT+ boardsAdd dtparam=pciex1 to config.txt; add PCIE_PROBE=1 to the bootloader config
Drive visible, but Pi still boots from SDBoot order tries SD firstRemove the card, or set BOOT_ORDER=0xf416
Pi never tries NVMe, even with no cardOld bootloaderUpdate with sudo rpi-eeprom-update -a, then reboot
Wrong root mounted, odd behaviour with card and SSD both insertedClone kept the same partition UUIDsRe-clone with New Partition UUIDs ticked, or remove the card
Random freezes or I/O errorsPCIe Gen 3 enabled, or a drive the Pi does not get on withRemove dtparam=pciex1_gen=3; try another drive
Drive throttles or disappears under loadHeat or weak power supplyUse the 27 W supply, improve airflow, check nvme smart-log

For deeper problems, the Pi 5’s default bootloader configuration already sets BOOT_UART=1, so a USB serial adapter on the debug UART connector shows the bootloader’s log. Its output shows each boot mode it tries, and on a healthy system you see lines such as Boot mode: NVME (06) followed by the drive’s model name. If the bootloader cannot boot a drive that Linux sees perfectly well, Raspberry Pi asks for a bug report on the rpi-eeprom GitHub repository with that console output attached.

Once the Pi boots reliably from NVMe, it is a far better base for always-on jobs. A sensible next step is a remote access setup so you can reach it from outside your home without opening ports on your router.

FAQ

Do I need to edit config.txt to boot a Raspberry Pi 5 from NVMe?

Not with the official M.2 HAT+ or M.2 HAT+ Compact. Both follow the HAT+ specification, so Raspberry Pi OS and the bootloader detect them automatically. You only need dtparam=pciex1 (and PCIE_PROBE=1 in the bootloader config) for adapters that are not HAT+ compliant, plus dtparam=pciex1_gen=3 if you choose to try Gen 3.

Can I use a 2280 NVMe SSD with the M.2 HAT+?

No. The standard M.2 HAT+ supports 2230 and 2242 drives, and the Compact supports 2230 only. For a full-length 2280 drive, you need a third-party PCIe board designed for that length, and you should check its own instructions for any extra configuration.

Will a SATA M.2 SSD work?

No. The M.2 HAT+ connects to the Pi’s PCIe interface and supports M key devices such as NVMe SSDs. M.2 SATA drives use a different protocol and will not be detected, even if they physically fit.

Can I leave the microSD card inserted after moving to NVMe?

Yes, as long as the boot order tries NVMe first. Use different partition UUIDs on the two devices if both hold Raspberry Pi OS, otherwise the system can mount the wrong root filesystem. Many people simply remove the card and keep it as an emergency boot disk.

Is PCIe Gen 3 safe on the Raspberry Pi 5?

Raspberry Pi does not certify the Pi 5 for Gen 3.0, and says those connections might be unstable. Treat it as an unsupported speed-up of the link rather than a normal setting. Keep it off on systems you rely on, and treat any filesystem errors after enabling it as a reason to switch back.

Can I use the M.2 HAT+ and an AI accelerator at the same time?

Not on one M.2 HAT+. The Pi 5 has a single PCIe lane, and the HAT exposes one M.2 slot, so it holds either an SSD or another M.2 device. Running both at once needs a third-party board with a PCIe switch, and Raspberry Pi notes that only certain devices support enumeration behind a switch.

About the author