[{ALLOW view All}]
[{ALLOW edit Markus}]

[{TableOfContents }]

!!Boot from 4TB NVMe 
The Raspberry PI Imager creates max 2TB partitions as MBR type. If you want to use a 4TB SSD as boot device you need this instructions.\\

Approach in short
# Install Raspberry PI OS on SD Card
# Use GPT table on NVMe and create same type of partitions on NVMe like on SD card
# copy over both partitions data
# switch boot order

!1. Prepare SDF Card
I will use terminal only, so I use lite version:
Raspberry Pi Imager > Raspberry PI OS (Other) > Raspberry PI OS Lite (64-bit)

!2. Prepare NVMe
We create same partitions like in SD-Card, check out SD-Card first:
{{{
> sudo fdisk --list
	[...]
	Device           Start        End    Sectors  Size Type
	/dev/nvme0n1p1    8192    1056767    1048576  512M Microsoft LDM metadata
	/dev/nvme0n1p2 1056768 7814035455 7812978688  3.6T Linux filesystem

	Device         Boot   Start      End  Sectors  Size Id Type
	/dev/mmcblk0p1         8192  1056767  1048576  512M  c W95 FAT32 (LBA)
	/dev/mmcblk0p2      1056768 15597567 14540800  6.9G 83 Linux
}}}

Create
{{{
> sudo fdisk /dev/nvme0n1 
create GPT first, this enables us to use MORE than 2TB !
> g 
create first partition: 512MiB boot partition. 4MiB before partition. fat32. Label as ‘bootfs’
> n  (new partition)
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
USE exact size from former SD-card (see >sudo fdisk --list<), e.g. 8192 - 1056767

> t (change partition type)
> 11 = Microsoft basic data !!! - "efi system partition" should work too(?)

create second partition ext4 partition
> n
> primary
> (defaults)
note: partition type "Linux" = ext4

> w         # write/execute all settings, do not forget!
}}}
Validate again
3. check
{{{
> sudo fdisk /dev/nvme0n1
> p
Disk /dev/nvme0n1: 3.64 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model: Samsung SSD 990 PRO 4TB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 328DEADB-7020-B14F-BB7C-760218A70054

Device           Start        End    Sectors  Size Type
/dev/nvme0n1p1    8192    1056767    1048576  512M Microsoft LDM metadata
/dev/nvme0n1p2 1056768 7814035455 7812978688  3.6T Linux filesystem
}}}

!3. create file systems
{{{
> sudo mkfs -t vfat /dev/nvme0n1p1
> sudo mkfs -t ext4 /dev/nvme0n1p2
}}}

!4. change label
{{{
> sudo fatlabel /dev/nvme0n1p1 bootfs
> sudo e2label /dev/nvme0n1p2 rootfs
}}}

!5. check
{{{
> lsblk -f  # FINAL
NAME        FSTYPE FSVER LABEL  UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
mmcblk0
├─mmcblk0p1 vfat   FAT32 bootfs 4C33-F302                             446.2M    13% /boot/firmware
└─mmcblk0p2 ext4   1.0   rootfs 3b445224-0aeb-4897-9108-009ed4211fb4    4.3G    31% /
nvme0n1
├─nvme0n1p1 vfat   FAT16 bootfs 7432-7D47
└─nvme0n1p2 ext4   1.0   rootfs 148a2332-36f1-40fa-9347-0ef42e25452d    3.4T     0% /media/markus/rootfs
}}}
and
{{{
> sudo fdisk --list
	Disk /dev/nvme0n1: 3.64 TiB, 4000787030016 bytes, 7814037168 sectors
	Disk model: Samsung SSD 990 PRO 4TB
	Units: sectors of 1 * 512 = 512 bytes
	Sector size (logical/physical): 512 bytes / 512 bytes
	I/O size (minimum/optimal): 512 bytes / 512 bytes
	Disklabel type: gpt
	Disk identifier: 328DEADB-7020-B14F-BB7C-760218A70054

	Disk /dev/mmcblk0: 7.44 GiB, 7985954816 bytes, 15597568 sectors
	Units: sectors of 1 * 512 = 512 bytes
	Sector size (logical/physical): 512 bytes / 512 bytes
	I/O size (minimum/optimal): 512 bytes / 512 bytes
	Disklabel type: dos
	Disk identifier: 0x890595ad

	Device           Start        End    Sectors  Size Type
	/dev/nvme0n1p1    8192    1056767    1048576  512M Microsoft LDM metadata
	/dev/nvme0n1p2 1056768 7814035455 7812978688  3.6T Linux filesystem

	Device         Boot   Start      End  Sectors  Size Id Type
	/dev/mmcblk0p1         8192  1056767  1048576  512M  c W95 FAT32 (LBA)
	/dev/mmcblk0p2      1056768 15597567 14540800  6.9G 83 Linux
}}}

!6. Copy first partition
{{{
> sudo dd if=/dev/mmcblk0p1 of=/dev/nvme0n1p1 bs=1M status=progress

Mount
> sudo mkdir /media/markus/rootfs
> sudo vi /etc/fstab 
	m2 part1 > /media/markus/bootfs
	m2 part2 > /media/markus/rootfs

> sudo rsync -avPAHXx --numeric-ids / /media/markus/rootfs
(> sudo umount /dev/nvme0n1p2)
}}}

!7 Prepare m2 to boot
Get UUIDs
{{{
> sudo blkid
/dev/nvme0n1p1: LABEL_FATBOOT="bootfs" LABEL="bootfs" UUID="4C33-F302" BLOCK_SIZE="512" TYPE="vfat" 
	PARTUUID="45e773bc-3db4-9f47-bf68-298a18c04083"
/dev/mmcblk0p1: LABEL_FATBOOT="bootfs" LABEL="bootfs" UUID="4C33-F302" BLOCK_SIZE="512" TYPE="vfat" 
	PARTUUID="890595ad-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="3b445224-0aeb-4897-9108-009ed4211fb4" BLOCK_SIZE="4096" TYPE="ext4" 
	PARTUUID="890595ad-02"
/dev/nvme0n1p2: LABEL="rootfs" UUID="7d8d2d84-14bc-497b-bb86-e86e02c3eb7a" BLOCK_SIZE="4096" TYPE="ext4" 
	PARTUUID="cce223b0-1be4-4f4e-9fe2-6449e5e4ec86"
}}}
Exchange mount point from SD card with SSD
{{{
> sudo vi /media/markus/rootfs/etc/fstab
change PARTUUID for SD partitions with m2 partitions

> sudo vi /media/markus/bootfs/cmdline.txt

Change boot order
> sudo raspi-config
}}}
check boot order
{{{
> sudo rpi-eeprom-config
order is from right to left
1 = Check SD card
6 = Check PCIe NVME
4 = Check USB drive
f = Start again
see https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#BOOT_ORDER
}}}
!8. Reboot
{{{
> sudo reboot now
}}}

!Issues
If it is not booting from m2, check [community.volumio.com|https://community.volumio.com/t/guide-prepare-raspberry-pi-for-boot-from-usb-nvme/65700]
{{{
> sudo vcgencmd bootloader_version
> sudo vi /etc/default/rpi-eeprom-update
> dmesg
}}}
Check [jeffgeerling.com|https://www.jeffgeerling.com/blog/2023/nvme-ssd-boot-raspberry-pi-5]
{{{
> sudo vi /boot/firmware/config.txt

# Add to bottom of /boot/firmware/config.txt
dtparam=pciex1

# Note: You could also just add the following (it is an alias to the above line)
# dtparam=nvme

# Optionally, you can control the PCIe lane speed using this parameter
# dtparam=pciex1_gen=3
}}}

!Wipe disk
wipe all disk partitions before cloning
{{{
> sudo umount /dev/nvme0n1p?
> sudo wipefs --all --force /dev/nvme0n1p?
> sudo wipefs --all --force /dev/nvme0n1
> sudo dd if=/dev/zero of=/dev/nvme0n1 bs=1024 count=1
}}}