blue-ox.nl From coffee-fueled fruity tech to fast runs—think different, let’s run them.

RPi from SD-card to M.2 SSD

R

introduction / background

Quote by notenoghtech (see below for credits)

M.2 is a connector type. It’s a hardware specification shared by NVMe (PCIe controller) and SATA-based solid-state drives. To take advantage of the boot via PCIe port exclusive to Raspberry Pi 5 board, you need an M.2 NVMe drive.
The next step is to understand the form factor. M.2 SSDs come with various storage capacities and sizes. The numbers like 2240 or 2280 refer to the physical footprint. M.2 SSD board is 22mm wide and comes with various lengths: 40/60/80mm which is noted with the corresponding footprint numbers 2240/2260/2280 etc.

For my setup I use the following

M.2 HAT+ (Raspberry Pi) + M.2 NVMe SSD 128 GB

Start your Raspberry Pi with a regulare (empty) image from regular Pi OS installation on SD card (nice backup also)

sudo nano /boot/firmware/config.txt

Add the following lines at the bottom of the file,

[all]
dtparam=nvme
dtparam=pciex1_gen=3

Reboot your Raspberry Pi 5 board and install M.2 NVMe storage now. Once done, you can confirm that the PCIe port is working correctly and you can detect the new hardware with:

lspci


My output gives

PCI bridge: Broadcom Inc. and subsidiaries BCM2712 PCIe Bridge (rev 21)
Non-Volatile memory controller: Yangtze Memory Technologies Co.,Ltd PC210 (rev 03)
PCI bridge: Broadcom Inc. and subsidiaries BCM2712 PCIe Bridge (rev 21)
Ethernet controller: Raspberry Pi Ltd RP1 PCIe 2.0 South Bridge

lsblk


It should something like (SSD with the OS on it and the nvme disk),

NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
mmcblk0 179:0 0 29.7G 0 disk
├─mmcblk0p1 179:1 0 512M 0 part /boot/firmware
└─mmcblk0p2 179:2 0 29.2G 0 part /
nvme0n1 259:0 0 931.5G 0 disk

The next step is to format the drive and prepare the partition.

sudo fdisk /dev/nvme0n1

asdf

then use the commands below, if you want multiple partitions, remember to define the sizes of each new partition correctly
n - create new partition
p - primary partition
w - write (save changed)


When you run lsblk again the table should look like this:

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
mmcblk0 179:0 0 29.7G 0 disk
├─mmcblk0p1 179:1 0 512M 0 part /boot/firmware
└─mmcblk0p2 179:2 0 29.2G 0 part /
nvme0n1 259:0 0 931.5G 0 disk
└─nvme0n1p1 259:1 0 931.5G 0 part

The next step is to change the boot order. Use sudo raspi-config to open the configuration menu and navigate to

sudo raspi-config

Advanced Options > Boot Order > NVMe /USB Boot

Don’t reboot your Raspberry Pi, just yet.
We need to copy partitions over to your new drive. We can use dd to achieve this with a single line of code:

sudo dd if=/dev/mmcblk0 of=/dev/nvme0n1 bs=4MB status=progressCode language: JavaScript (javascript)

Now you can reboot your Raspberry Pi.
If all went okay, on your next boot the board should be booting from M.2 NVMe SSD. You can confirm this by running lsblk again,

#output NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
mmcblk0 179:0 0 29.7G 0 disk
├─mmcblk0p1 179:1 0 512M 0 part
└─mmcblk0p2 179:2 0 29.2G 0 part
nvme0n1 259:0 0 931.5G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot/firmware
└─nvme0n1p2 259:2 0 29.2G 0 part /

sources (references) & credits

Basically all input/information came from the websites below. So credits and thanks to those content creators and subject matter experts. The only reason I mainly copy/paste their content is to guarantee I have a backup for myself and because multiple times I had to change and adapt. So archiving the “scripts” as I executed it succesfully is inportant for me.

https://notenoughtech.com/raspberry-pi/boot-raspberry-pi-5-from-nvme/
and for some backround information
https://www.jeffgeerling.com/blog/2023/nvme-ssd-boot-raspberry-pi-5
https://raspberrypi.stackexchange.com/questions/127757/how-to-clone-os-from-sd-to-ssd-using-command-line

About the author

Add comment

By Erik
blue-ox.nl From coffee-fueled fruity tech to fast runs—think different, let’s run them.

Pages

Tags