In "USB boot with Raspberry Pi 4 Model B", write the image for microSD to USB mass storage as it is, and then resize the partition. The procedure is described. But the fact is, the USB mass storage only needs to have the system files in place, and you don't have to make an exact copy using the Raspberry Pi Imager or the dd command. Here are the steps to create a partition first and then copy the files.
You can find the partition of the Raspberry Pi OS (64bit) installation image with the gdisk
command.
$ unzip 2020-08-20-raspios-buster-arm64.zip
$ gdisk -l 2020-08-20-raspios-buster-arm64.img
GPT fdisk (gdisk) version 1.0.5
Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present
***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory.
***************************************************************
:
Number Start (sector) End (sector) Size Code Name
1 8192 532479 256.0 MiB 0700 Microsoft basic data
2 532480 7380991 3.3 GiB 8300 Linux filesystem
You can see that the installation image is partitioned by MBR.
The first partition is assigned to / boot
and the second partition is assigned to/
.
Create the following partition with the gdisk
command.
$ sudo gdisk -l /dev/sdb
GPT fdisk (gdisk) version 1.0.5
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
:
Number Start (sector) End (sector) Size Code Name
1 2048 526335 256.0 MiB 0700 Microsoft basic data
2 526336 5860533134 2.7 TiB 8300 Linux filesystem
I chose GPT because the USB mass storage capacity used was 3TB. If it's less than 2TB (and one sector is 512 bytes or less), the MBR should be fine. If the USB mass storage is HDD, you can create a swap partition here.
Format / boot
with vfat
and /
with ʻext4`.
$ sudo mkfs -t vfat /dev/sdb1
$ sudo mkfs -t ext4 /dev/sdb2
Mount the installation image, USB mass storage and copy the contents.
$ mkdir img_boot img_root
#In the image/boot, /Assign partition to loop device
$ sudo losetup -Pr --show -f 2020-08-20-raspios-buster-arm64.img /dev/loop20
$ sudo mount /dev/loop20p1 img_boot
$ sudo mount /dev/loop20p2 img_root
#Mount USB mass storage partition to copy files
$ mkdir boot root
$ sudo mount /dev/sdb1 boot
$ sudo mount /dev/sdb2 root
#File copy
$ sudo cp -a img_boot/* boot/
$ sudo cp -a img_root/* root/
#Clean up the installation image
$ sudo umount img_boot img_root
$ sudo losetup -d /dev/loop20
$ rmdir img_boot img_root
Update the partition information for cmdline.txt
and fstab
.
#Check the PARTUUID of the partition
$ sudo blkid /dev/sdb?
/dev/sdb1: SEC_TYPE="msdos" UUID="C7EE-35DE" TYPE="vfat" PARTLABEL="Microsoft basic data" PARTUUID="09468d30-111e-4028-8f37-16f65e497c25"
/dev/sdb2: UUID="8aff8673-0851-45af-a8cd-8c31614b9632" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="9522d40d-e6df-422a-a5f6-26195aa7e074"
# root=PARTUUID=The value of above/dev/Rewrite to PARTUUID of sdb2
$ cat boot/cmdline.txt
console=serial0,115200 console=tty1 root=PARTUUID=9522d40d-e6df-422a-a5f6-26195aa7e074 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh splash plymouth.ignore-serial-consoles
# /boot and/PARTUUID=To/dev/With sdb1/dev/Set the one for sdb2
#If you created other partitions such as swap, add them here
$ cat root/etc/fstab
proc /proc proc defaults 0 0
PARTUUID=ee96d62f-2fe6-44c0-abcf-f70569772297 /boot vfat defaults 0 2
PARTUUID=035df15c-ccbe-45c0-9e9a-f97096bd3ee9 / ext4 defaults,noatime 0 1
#Clean up
$ sudo umount boot root
$ rmdir boot root
All you have to do is connect this USB mass storage to your Raspberry Pi 4 and you're ready to go.