---
agent:
  instructions: "Use this search API to find relevant content across this site (products with prices and stock, collections, guides, articles, courses, help and pages) with keywords or natural-language queries, instead of crawling individual pages. Replace {query} with your URL-encoded query. Results are returned in Markdown."
  endpoint: "https://piaustralia.com.au/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Raspberry Pi M.2 HAT+ and booting from NVMe

Fitting an NVMe SSD to a Raspberry Pi 5 with the M.2 HAT+ or M.2 HAT+ Compact, checking the Pi can see it, and making the Pi boot from it.

## What it does

The M.2 HAT+ connects an NVMe SSD to the PCIe connector on a Raspberry Pi 5. An SSD is far quicker than a microSD card and better suited to running all day, so it makes a good boot drive for a desktop, a home server or anything that writes a lot of data.

There are two versions:

| | M.2 HAT+ | M.2 HAT+ Compact |
|---|---|---|
| **Drive sizes** | M-key 2230 and 2242 | M-key 2230 only |
| **Active Cooler** | Fits underneath | Won't fit underneath |
| **Official Pi 5 case** | Only with the case lid and fan removed | Fits inside, around the case fan |
| **GPIO** | Comes with a 16 mm stacking header, so the pins stay usable | No stacking header |

The numbers are the drive's size in millimetres: a 2230 drive is 22 mm wide and 30 mm long. Both boards need a Raspberry Pi 5 and take an NVMe drive with an M-key connector. They run the link as single-lane PCIe 2.0, good for up to 500 MB/s, and can supply up to 3 A to the drive.

In the box you'll get a ribbon cable, spacers and screws, and a knurled screw that holds the drive down. The standard M.2 HAT+ also includes the stacking header.

## Before you fit it

Update Raspberry Pi OS, then check the Pi's bootloader:

```
sudo apt update
sudo apt full-upgrade
sudo rpi-eeprom-update
```

If the bootloader is dated 6 December 2023 or later, you're ready. If it's older, run `sudo raspi-config`, choose **Advanced Options → Bootloader Version → Latest**, then:

```
sudo rpi-eeprom-update -a
sudo reboot
```

Always shut down and unplug the power before fitting or removing anything in the M.2 slot.

## Fitting the M.2 HAT+

1. If you're using an Active Cooler, fit it first (see our [Pi 5 cooling guide](/docs/raspberry-pi-5-cooling)).
2. Screw the spacers onto the Pi and press the stacking header onto the GPIO pins.
3. Lift the cable latches on both the HAT and the Pi's PCIe connector. Slide the ribbon into the Pi with its metal contacts facing the USB ports, and press the latch down.
4. Sit the HAT on the spacers and fix it with the remaining screws.
5. Slide the other end of the ribbon into the HAT with the contacts facing up, and press its latch down.
6. Undo the drive screw. Slide the SSD into the M.2 slot at a slight upward angle, without forcing it.
7. Press the far end of the drive down flat, hook the notch on the screw into the slot at the end of the drive, and tighten gently.

**The Compact version** is simpler: screw it onto its spacers, plug the ribbon into the Pi with the contacts facing inwards towards the USB ports, then fit the drive the same way, pressed flat against the board.

## GPIO connections and stacking

The standard M.2 HAT+ carries SSD data through the **PCIe ribbon cable**, rather than the header's SPI or I2C data bus. Its identification EEPROM uses these header signals:

| Physical pin | BCM GPIO | Recorded purpose |
|---|---|---|
| 27 | GPIO 0 | ID_SD: identification data |
| 28 | GPIO 1 | ID_SC: identification clock |

These are the reserved HAT identification pins, separate from the usual I2C pair on physical pins 3 and 5. Our [40-pin GPIO reference](/docs/gpio-pinout) explains both numbering systems and the power and ground positions.

Raspberry Pi labels the standard board **Stackable HAT+** in its schematic. Its supplied 16 mm header passes the header through, but that alone does not confirm a complete stack will fit or work. Check the other board's pin use, height, cooling and power requirements. Two accessories cannot both occupy the Pi 5's single PCIe connector.

This signal list is not a complete electrical wiring schedule: power and ground connections are separate. It applies to the standard M.2 HAT+; do not assume the Compact version has the same header connections.

## Turning on the PCIe connector

There's nothing to do. Both versions follow the HAT+ standard, so the Pi recognises them and switches the PCIe connector on by itself.

(Other makers' NVMe adapters that don't follow the HAT+ standard need `dtparam=pciex1` added to `/boot/firmware/config.txt`.)

## Checking the drive

Boot the Pi from its microSD card and run:

```
ls -l /dev/nvme*
```

You should see `/dev/nvme0` and `/dev/nvme0n1`. If you do, the Pi can see the drive.

A brand-new drive won't appear on the desktop until it's been formatted. Raspberry Pi Imager's **Erase** option will do that, or you can go straight on to installing Raspberry Pi OS onto it.

## Booting from the SSD

1. **Put Raspberry Pi OS on the drive.** With the Pi running from its microSD card, open Raspberry Pi Imager and choose the NVMe drive as the storage device. If the bootloader is up to date, you can instead use Network Install over Ethernet.
2. **Remove the microSD card and reboot.** With no card in the slot, the Pi boots from the SSD.

If you'd like to keep a card in the slot and still boot from the SSD, change the boot order. The easy way is `sudo raspi-config` → **Advanced Options → Boot Order**, then pick the NVMe/USB option and reboot.

To set it by hand instead, open the bootloader settings:

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

and change the `BOOT_ORDER` line to:

```
BOOT_ORDER=0xf416
```

It's read from right to left: try the NVMe drive (6) first, then the microSD card (1), then USB (4), and if none of them works, start again (f). Save, then `sudo reboot` to write it. If you're using a non-HAT+ adapter, add `PCIE_PROBE=1` on its own line as well.

Once the Pi is running from the SSD, `lsblk` shows `nvme0n1p1` mounted at `/boot/firmware` and `nvme0n1p2` mounted at `/`.

## Faster speeds (PCIe Gen 3)

The PCIe connector runs at Gen 2 by default. You can switch it to Gen 3, roughly doubling the link speed, with **Advanced Options → PCIe Speed** in `sudo raspi-config`, or by adding this line to `/boot/firmware/config.txt` and rebooting:

```
dtparam=pciex1_gen=3
```

Be aware that the Pi 5 isn't certified for Gen 3, and the connection may not be stable. If you see drive errors or freezes after the change, remove the line (or switch it off again in `raspi-config`) to go back to Gen 2.

## Other M.2 cards

The M.2 HAT+ isn't only for SSDs. The original Raspberry Pi AI Kit is an M.2 HAT+ with a Hailo AI module in the slot; our [AI HAT+ guide](/docs/ai-hat-plus) covers the software side.

## Parts in this guide

- [Raspberry Pi M.2 HAT+](https://piaustralia.com.au/products/raspberry-pi-m-2-hat-for-raspberry-pi-5.md)
- [Raspberry Pi 5 M.2 HAT+ (Compact)](https://piaustralia.com.au/products/raspberry-pi-5-m-2-hat-compact.md)
- [Raspberry Pi SSD](https://piaustralia.com.au/products/raspberry-pi-ssd-256gb-2.md)
- [Raspberry Pi SSD Kit](https://piaustralia.com.au/products/raspberry-pi-ssd-kit-512gb-with-raspberry-pi-m-2-hat.md)
- [Raspberry Pi Active Cooler](https://piaustralia.com.au/products/raspberry-pi-active-cooler.md)
- [Raspberry Pi 5](https://piaustralia.com.au/products/raspberry-pi-5.md)

Written by Pi Australia from Raspberry Pi's M.2 HAT+ documentation, Raspberry Pi's hardware documentation (PCIe and NVMe boot), Raspberry Pi M.2 M-Key HAT+ schematic, RP-008218-DS revision 3.
