[LINUX] Create a partition and then install the Raspberry Pi OS

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.

Create partition

Check the partition of the installation image

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 a partition

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.

Partition format

Format / boot with vfat and / with ʻext4`.

$ sudo mkfs -t vfat /dev/sdb1
$ sudo mkfs -t ext4 /dev/sdb2

Copy file

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

setting change

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.

Recommended Posts

Create a partition and then install the Raspberry Pi OS
Install Raspberry Pi OS (Raspbian)
Create a color sensor using a Raspberry Pi and a camera
Create a web surveillance camera with Raspberry Pi and OpenCV
Specify or create a python folder and then save the screenshot.
[Raspberry Pi] Add a thermometer and a hygrometer
Install 64-bit OS (bate) on Raspberry Pi
Install docker-compose on 64-bit Raspberry Pi OS
Create a car meter with raspberry pi
Create a visitor notification system using Raspberry Pi
[Ubuntu] Install Android Studio and create a shortcut
Make a thermometer with Raspberry Pi and make it visible on the browser Part 3
Build a distributed environment with Raspberry PI series (Part 3: Install and configure dnsmasq)
Install pyenv on Raspberry Pi and version control Python
Create an LCD (16x2) game with Raspberry Pi and Python
Get the weather using the API and let the Raspberry Pi speak!
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
Install a tact switch on the Raspberry Pi to make daily "Good morning Yosoro !!" tweets comfortable
A program that receives the servo command of the radio control, interrupts the Raspberry Pi and logs it
Building a distributed environment with the Raspberry PI series (Part 2: PiServer analysis and alternative system design)
[MariaDB] Install MariaDB on Linux and create a DB and an operating user.
Control the motor with a motor driver using python on Raspberry Pi 3!
Christmas classic (?) Lighting a Christmas tree with Raspberry Pi and Philips Hue
Make a thermometer with Raspberry Pi and make it viewable with a browser Part 4
Make a Kanji display compass with Raspberry Pi and Sense Hat
Raspberry Pi --1 --First time (Connect a temperature sensor to display the temperature)
Create your own IoT platform using raspberry pi and ESP32 (Part 1)
Dig the directory and create a list of directory paths + file names
MQTT on Raspberry Pi and Mac
raspberry pi 4 centos7 install on docker
Install ghoto2 on Raspberry Pi (memo)
OS setup with Raspberry Pi Imager
Install OpenMedia Vault 5 on Raspberry Pi 4
Using a webcam with Raspberry Pi
Display the signal strength RSSI of a specific SSID (raspberry pi (linux))
A memo to simply use the illuminance sensor TSL2561 with Raspberry Pi 2
The microphone was not recognized on Linux's Raspberry Pi OS (formerly Raspbian).
Make a wireless LAN Ethernet converter and simple router with Raspberry Pi
Create a socket with an Ethernet interface (eth0, eth1) (Linux, C, Raspberry Pi)
I connected the thermo sensor to the Raspberry Pi and measured the temperature (Python)
Gently explain the process of making a simple serverless surveillance camera using Raspberry Pi, Gmail API and Line API
Pet monitoring with Rekognition and Raspberry pi
Build a Tensorflow environment with Raspberry Pi [2020]
Create a graph using the Sympy module
Use the Grove sensor on the Raspberry Pi
Make a wash-drying timer with a Raspberry Pi
Operate an oscilloscope with a Raspberry Pi
How to install NumPy on Raspberry Pi
Create a Python image in Django without a dummy image file and test the image upload
Make a Python program a daemon and run it automatically when the OS starts
[pyqtgraph] Understand SignalProxy and create a crosshair that follows the cursor on the graph
I tweeted the illuminance of the room with Raspberry Pi, Arduino and optical sensor
Create a REST API using the model learned in Lobe and TensorFlow Serving.
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a Web server --2 PHP introduction
Create a simple reception system with the Python serverless framework Chalice and Twilio
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a Web server ―― 1. Apache introduction
Zip-compress any file with the [shell] command to create a file and delete the original file.
Create a Django project and application in a Python virtual environment and start the server
Creating a temperature control system with Raspberry Pi and ESP32 (3) Recipient Python file
[For beginners] I made a motion sensor with Raspberry Pi and notified LINE!