PCIe To M.2 HAT B Adapter Board for the Raspberry Pi 5

Figure 1-1 PCIe To M.2 HAT B Front View
Figure 1-2 PCIe To M.2 HAT B Back View

Product Overview

This product is a dedicated M.2 adapter board for the Raspberry Pi 5, compatible with M.2 SSDs of sizes 2230/2242/2260/2280. It supports both Gen2 and Gen3 modes and allows booting the PI5 from an SSD. The board features a slim design in the middle, ensuring durability while enhancing airflow to lower the SSD temperature. It has a clear working status with onboard indicators: the PWR light is steady when powered, and the ACT light blinks during read/write operations.

Product Dimensions

Figure 1-3 PCIe To M.2 HAT B Dimensions

The module resources are outlined in the following diagram:

Figure 1-4 PCIe To M.2 HAT B Resource Overview
① M-Key Slot

② 2-pin External 5V Power Connector

③ PCIe 16-pin Flip-style FPC Connector

④ SSD 2230 Model Mounting Hole

⑤ SSD 2242 Model Mounting Hole

⑥ SSD 2260 Model Mounting Hole

⑦ SSD 2280 Model Mounting Hole

⑧ Working Status Indicator Light

⑨ Mounting Pillar Hole

Product Specifications

ModelPCIe To M.2 HAT B
Supported ModesGen2、Gen3
Supported ProtocolNVME
Supported SSD Models2230、2242、2260、2280
PCIe Interface StandardPCIe Gen 2.0 x1
SSD ConnectorM.2 M Key
External 5V Power Connector2-pin female connector
Dimensions88.00mm (Length) x 56.46mm (Width)

Usage

This product connects to the FPC connector (PCIe interface) on the side of the Raspberry Pi 5 using a 16P flat cable and is securely installed onto the Raspberry Pi 5 with four mounting holes and pillars with nuts. Insert the SSD to expand storage. Based on the NVMe protocol, the PCIe interface of this product provides higher bandwidth and performance compared to traditional SD cards and USB storage. It supports M.2 NVMe SSDs, significantly improving data read and write speeds, and supports various M.2 SSD models (such as 2230, 2242, 2260, 2280), offering strong compatibility. The installation and configuration are straightforward, allowing both developers and enthusiasts to easily enjoy the convenience and advantages of high-speed storage.

Product Installation

1. Fix the four mounting pillars to the four mounting holes on the Raspberry Pi 5.

2. Connect the 16P flat cable to the PCIe 16-pin flip-style FPC connector on the board (see item ③ in Figure 1-4). The triangular mark on the cable should align with the dot mark on the board, as shown:

Figure 2-1 Correct Connection of Flat Cable

3. Assemble the product and the Raspberry Pi 5 together using the mounting pillars, and connect the other end of the flat cable to the FPC connector on the side of the Raspberry Pi 5. The installation is complete as shown:

Figure 2-2 Connecting to the Raspberry Pi 5 Side FPC Connector
Figure 2-3 Completed Assembly

4. Install your SSD by matching the model number with the mounting holes on the board (refer to resource items ④, ⑤, ⑥, and ⑦ in the resource diagram), as shown:

Figure 2-4 Overall View

Test

Update the Raspberry Pi

1. Update the Raspberry Pi to ensure it can run the latest software by entering the following command:

sudo apt update && sudo apt upgrade

2. Check the firmware to ensure it is up to date by entering the following command:

sudo rpi-eeprom-update

3. Install rpi-update to get the latest firmware:

sudo apt install rpi-update

4. Update the firmware by running rpi-update:

sudo rpi-update

5. After updating, restart the Raspberry Pi:

sudo reboot

Identify the SSD

1. Edit the /boot/firmware/config.txt file and add dtparam=nvme to enable the PCIe interface:

sudo nano /boot/firmware/config.txt

Add dtparam=nvme at the end of the file, as shown:

2. If PCIe Gen3 needs to be enabled:

Method 1: Continue by adding dtparam=pciex1_gen=3 to the same file.

Method 2: Use the raspi-config command to open Raspberry Pi configuration:

raspi-config

Select Advanced Options

Select PCIe Speed — Yes to enable PCIe Gen 3 mode.

3. Then restart the Raspberry Pi to apply the changes:

sudo reboot

4. After restarting, open the Raspberry Pi terminal and enter the command lspci to identify your SSD. For example, if you are using a Sandisk SSD, it will be shown within the red box in the figure, with the other being the PI5's RPI chip.

Partitioning

1. Ensure that the Raspberry Pi is correctly connected to and recognizes the SSD.

2. Identify the device number by running the lsblk command, which will display the device number and the directories where the device is mounted.

lsblk

NAME —— Displays the name of the device.

MAJ:MIN —— Displays the major and minor device numbers. RM —— Indicates whether the device is removable (0 for non-removable, 1 for removable).

SIZE —— Displays the size of the device.

RO —— Indicates whether the device is read-only (0 for read-write, 1 for read-only).

TYPE —— Displays the type of the device (disk for disk, part for partition).

MOUNTPOINT —— Displays the mount point of the device.

3. Open the disk partitioning tool.

Here, taking creating a new partition as an example: For the device to be partitioned (such as nvme0n1), open the disk partitioning tool.

sudo fdisk /dev/nvme0n1

Type the letter 'n' and follow the operation prompts to partition.

Enter the command 'lsblk' again to check whether the partitioning is successful.

As shown in the figure, there is an additional device named nvme0n1p3. This is the newly created partition.

Formatting

1.File system type

sudo mkfs

Then press the tab key. You can see multiple different file system type options as shown in the figure.

2. Format the partition. If you want to format a certain partition, enter "sudo mkfs.file format type /dev/device name". For example, I want to format partition nvme0n1p3 into ext4 file format.

sudo mkfs.ext4 /dev/nvme0n1p3

As shown in the figure above, if "done" appears at the end, it proves that the formatting is successful.

Mount the device

1. Create a mount directory

The format of the command is "sudo mkdir name of the created mount directory". For example, "sudo mkdir SG".

sudo mkdir SG

2. Mount the device

Mount partition nvme0n1p3 to directory SG.

sudo mount /dev/nvme0n1p3 ./SG

3. Enter the command "df -h" to check the disk status.

df -h

As shown in the figure, it can be seen that partition nvme0n1p3 has been mounted to directory SG.

Partition read-write test

1.Enter the directory where the partition is mounted.

cd SG

2.Release memory cache

To ensure the accuracy of the read-write test, we need to release the cache. Use the following command to release the memory cache:

sudo sh -c "sync && echo 3 > /proc/sys/vm/drop_caches"

3.Write test (copy the Raspberry Pi memory content to the hard disk)

Use the dd command to generate data from /dev/zero and write it to the mounted hard disk to perform a write performance test.

sudo dd if=/dev/zero of=./test_write count=2000 bs=1024k

4.Read test (copy the hard disk content to the Raspberry Pi memory)

Use the dd command to read data from the test_write file generated just now to /dev/null to perform a read performance test.

sudo dd if=./test_write of=/dev/null count=2000 bs=1024k

5. Clear the cache

sudo sh -c "sync && echo 1 > /proc/sys/vm/drop_caches"

This will synchronize the data in the cache to the disk and release the cache of the file system.

6. Delete the test file

After performing the read-write test, it is recommended to delete the created test file.

sudo rm ./test_write

Notes:

Different cards and environments: Test results may vary depending on the memory card used and the environment. The Raspberry Pi is limited by its hardware performance, and the test results may not be as accurate as tests on a PC.

Automatic mounting at startup

1. Set up mounting

If there are no problems with the test and you do not need the M.2 SSD as the system disk but only use it as an extended disk, you can set up automatic mounting by editing the file "/etc/fstab" with the command "sudo nano /etc/fstab".

sudo nano /etc/fstab

Add at the end of the file:

/dev/nvme0n1p3 /home/pi/SG ext4 defaults 0 0

The format is:

/dev/nvme0n1p3 (device name)

/home/pi/SG (mounted directory)

ext4 (file system type)

defaults (default mounting options)

The 0 and 0 respectively indicate whether to perform backup and the order of file system checks.

After editing, save and exit (press Ctrl + X, then press Y and Enter).

2. Make the changes take effect

To ensure that the configuration is correct, you can use the command sudo mount -a to make the mounting configuration take effect immediately:

sudo mount -a

3. Restart the system and check the mounting status.

sudo reboot
lsblk

Notes:

When editing the /etc/fstab file, ensure that you enter the correct device name and mount point to avoid system boot failure; use the command 'sudo mount -a' to apply the changes and confirm there are no errors.

Cancel Automatic Mounting and Delete Mount Directory

1. To unmount the device and delete the mount directory:

Navigate back to the parent directory of the mount directory

cd ..

Unmount the directory

sudo umount ./SG

Delete the mount directory

sudo rmdir ./SG

2. Cancel Automatic Mounting

Edit the file to comment out or delete the added automatic mounting command.

sudo nano /etc/fstab

Comment out the line '/dev/nvme0n1p3 /home/pi/SG ext4 defaults 0 0' by adding a "#" symbol at the beginning of the line.

Booting from NVME SSD

1. Ensure that the rpi-eeprom tool is installed and updated:

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

2. Edit the bootloader configuration:

sudo rpi-eeprom-config --edit

In the editor, find the line for BOOT_ORDER and modify it to the following content:

BOOT_ORDER=0xf416

Add the line:PCIE_PROBE=1

Save and exit the editor (press Ctrl + X, then press Y and Enter).

If you want to prioritize booting from the SD card, change it to BOOT_ORDER=0xf461.

If you want to configure other content, refer to the following table:

ValueModeDescription
0x0SD CARD DETECTTry SD then wait for card-detect to indicate that the card has changed - deprecated now that 0xf (RESTART) is available.
0x1SD CARDSD card (or eMMC on Compute Module 4).
0x2NETWORKNetwork boot - See Network boot server tutorial
0x3RPIBOOTRPIBOOT - See usbboot
0x4USB-MSDUSB mass storage boot - See USB mass storage boot
0x5BCM-USB-MSDUSB 2.0 boot from USB Type C socket (CM4: USB type A socket on CM4IO board). Not available on Raspberry Pi 5.
0x6NVMECM4 and Pi 5 only: boot from an NVMe SSD connected to the PCIe interface. See NVMe boot for more details.
0x7HTTPHTTP boot over ethernet. See HTTP boot for more details.
0xeSTOPStop and display error pattern. A power cycle is required to exit this state.
0xfRESTARTRestart from the first boot-mode in the BOOT_ORDER field i.e. loop

3. Make the configuration take effect

After editing is completed, update the bootloader.

sudo rpi-eeprom-update -d -f

4.Download the system to the solid-state drive

There are many ways to download the system. This article takes downloading in the Raspberry Pi as an example.

Click on the menu bar in the upper left corner of the Raspberry Pi desktop - select Accessories - select Imager.

In the official Raspberry Pi Imager tool in the Raspberry Pi, customize the desired system and initial settings, and then download the system to the solid-state drive.

After the download and installation are completed, restart the Raspberry Pi.

sudo reboot

After the Raspberry Pi boots up, the mount of the SD card appears on the desktop, indicating that the system is applicable and the configuration of booting from the SSD is successful.

Notes:

If your solid-state drive has already mounted a directory to the Raspberry Pi system and you did not unmount it before using the Raspberry Pi Imager tool to download the system, the official Raspberry Pi Imager tool will not be able to find the hard drive, which will result in the inability to download the system. You need to unmount the hard drive. For specific operations, please refer to section Cancel Automatic Mounting and Delete Mount Directory.

If you encounter a situation where the hard drive cannot be recognized during use and the statement added in the config.txt file is dtparam=nvme, you can try adding the statement dtparam=pciex1_gen=3 to enable PCIe Gen3. For specific operations, please refer to section Identify the SSD.

At present, we have tested many hard drives. Some hard drives have poor compatibility with our products. You can refer to the Raspberry Pi official test description of the compatibility of some hard drive models at the following link:

NVMe compatibility list - Pineberry Pi Documentaton

Technical Support

Technical Support and Product Notes