How to migrate Raspberry Pi 5 OS from micro SD to NVME m.2 SSD

首先我買了Raspberry Pi CM5後來買了Raspberry Pi CM5 I/O board來當個人電腦使用,系統是安裝在256GB SD卡上運行的很好。用久了在開啟較肥的程式像Web Browser或LiberOffice會有慢半拍的反應,而有了升級NVME m.2 SSD念頭。

因為Raspberry Pi 5支援的最快PCIe gen3 x 4就不去考慮快的Gen4 or Gen5 m.2 SSD。找了ADATA出的 LEGEND 710入門級的產品,會利用HMB(Host Memory Buffer)來加速I/O速度,因為是Raspberry Pi OS kernel會認不得而無法正常使用

事先在SD卡的/boot/firmware/cmdline.txt 加入 kernel command line參數如下,然後重開機m.2 SSD即可正常使用

/boot/firmware/cmdline.txt

console=tty1 root=PARTUUID=00cee001-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles nvme.max_host_mem_size_mb=0 nvme_core.default_ps_max_latency_us=0 pcie_aspm=off pcie_port_pm=off

抄寫SD system to m.2 SSD會需要用的rpi-clone的script

sudo -s
git clone https://github.com/billw2/rpi-clone.git
cd rpi-clone

實測遇到rpi-clone nvme0n1會失敗所以自行修改了rpi-clone並產出patch file

git diff -p --output=~/rpi-clone-nvme.patch

Patch file rpi-clone-nvme.path

diff --git a/rpi-clone b/rpi-clone
index b6baf53..63e6fcd 100755
--- a/rpi-clone
+++ b/rpi-clone
@@ -1095,7 +1095,7 @@ fi
 
 dst_disk_size=$(echo "$dst_partition_table" \
                                | grep "^/dev/$dst_disk" | cut -d ":" -f 2 | tr -d 's')
-dst_root_dev=/dev/${dst_part_base}${root_part_num}
+dst_root_dev=/dev/${dst_part_base}p${root_part_num}
 
 dst_mount_table=$(findmnt -o source,target -n -l \
                                | grep "^/dev/$dst_disk" | tr -s " ")
@@ -1120,7 +1120,7 @@ do
        fi
        dst_exists[p]=1
 
-       part="${dst_part_base}${p}"
+       part="${dst_part_base}p${p}"
        dst_partition[p]="$part"
        dst_device[p]="/dev/$part"
 
@@ -1485,7 +1485,7 @@ Use -U for unattended even if initializing.
                then
                        continue
                fi
-               dst_dev=/dev/${dst_part_base}${p}
+               dst_dev=/dev/${dst_part_base}p${p}
                fs_type=${src_fs_type[$p]}
                if    ((p == ext_part_num)) \
                   || [ "$fs_type" == "--" ]
@@ -1665,7 +1665,7 @@ do
                        qprintf "Syncing unmounted partitions:\n"
                fi
                sync_msg_done=1
-               dst_dev=/dev/${dst_part_base}${p}
+               dst_dev=/dev/${dst_part_base}p${p}
                fs_type=${src_fs_type[$p]}
                ext_label $p $fs_type "" label
                if [ "$label" != "" ]
@@ -1711,7 +1711,7 @@ do
                        mkdir -p $dst_dir
                fi
 
-               dst_dev=/dev/${dst_part_base}${p}
+               dst_dev=/dev/${dst_part_base}p${p}
                fs_type=${src_fs_type[$p]}
                ext_label $p $fs_type "" label
                if [ "$label" != "" ]

最後在跑過rpi-clone nvme0n1必需要修正/boot/firmware/cmdline.txt 關於

root=PARTUUID=00cee001-01 # NVME boot partition UUID

查詢nvme0n1p1的UUID指令為

lsblk -n -o PARTUUID /dev/nvme0n1p1
00cee001-01

這樣整個系統轉移就算大功告成