USB boot with Raspberry Pi 4 Model B (3) LVM edition

In "USB boot with Raspberry Pi 4 Model B (2) Partition creation", create a basic partition on USB mass storage and format it with ext4. I copied the Raspberry Pi OS as it is. By the way, most Linux distributions for x86 allow you to choose LVM during installation. You can also use LVM on the Raspberry Pi 4. You can also use LVM on the root partition. However, you need to use the initramfs to start it.

Until the last time (although it was not specified), installation to USB mass storage was done on a PC, but since initramfs cannot be created with this method, this time we will work from Raspberry Pi OS installed on microSD. To do. Note that the target device will change from / dev / sdb to dev / sda.

LVM creation

The place to create a partition is the same as last time.

$ sudo gdisk -l /dev/sda
GPT fdisk (gdisk) version 1.0.3

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
   2          526336      5860533134   2.7 TiB     8300

Create LVM on the second partition. The name is pi-vg, but you can use any other name.

#Create LVM physical volume
$ sudo pvcreate /dev/sda2

#Volume group pi-Create vg
$ sudo vgcreate pi-vg /dev/sda2

#Create a logical volume
#The capacity of the USB mass storage used this time is 3TB.
#Assuming 8GB to be allocated to swap/Capacity is calculated back from the total capacity
$ sudo lvcreate --size 2786G --name root pi-vg
$ sudo lvcreate -l 100%FREE --name swap pi-vg

#Check the current HDD status
$ lsblk /dev/sda
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  2.7T  0 disk 
├─sda1            8:1    0  256M  0 part 
└─sda2            8:2    0  2.7T  0 part 
  ├─pi--vg-root 254:0    0  2.7T  0 lvm  
  └─pi--vg-swap 254:1    0  8.3G  0 lvm  

The USB mass storage used was an HDD, so I created a swap partition because I don't have to worry about device deterioration due to writing data. When deciding the size of swap, I referred to the following information and secured almost the same capacity as the memory.

Format the created boot, root, swap.

$ sudo mkfs -t vfat /dev/sda1
$ sudo mkfs -t ext4 /dev/pi-vg/root
$ sudo mkswap       /dev/pi-vg/swap

Copy system files

If you do something like that, you can copy in the same way as before, but here we will save this trouble and copy from the microSD used for booting.

$ mkdir /tmp/root
$ sudo mount /dev/pi-vg/root /tmp/root/

#Devtmpfs not a real filesystem, sysfs, proc, tmpfs,boot and
#lost created during ext4 format+Copy directories other than found
$ cd /
$ sudo cp -a bin etc home lib media mnt opt root sbin srv tmp usr var /tmp/root/
$ cd /tmp/root/
$ sudo mkdir dev sys proc run boot tmp

#To create the initramfs described below, the boot partition/tmp/Mount under root
$ sudo mount /dev/sda1 /tmp/root/boot/
$ sudo cp -a /boot/* /tmp/root/boot/

Change startup settings

Update cmdline.txt and fstab. Specify options for initramfs as well as partition information.

# root=To/dev/pi-vg/Specify root
#initrd to use initramfs=Add 0x01f00000
#If it fails to start, you can remove quiet to display a running message on the screen to help identify the cause.
#The break option is also useful for debugging. For more information initramfs-tools(7)See
$ cat /tmp/root/boot/cmdline.txt
console=serial0,115200 console=tty1 root=/dev/pi-vg/root initrd=0x01f00000 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles

#As before, check the PARTUUID of the boot partition with the blkid command and specify it.
#In the case of SSD, to prevent device deterioration,/dev/pi-vg/root defaults"defaults,noatime"To specify
$ cat /tmp/root/etc/fstab
proc            /proc           proc    defaults          0       0
PARTUUID=09468d30-111e-4028-8f37-16f65e497c25  /boot           vfat    defaults          0       2
/dev/pi-vg/root  /               ext4    defaults  0       1
/dev/pi-vg/swap  none            swap    sw  0       0

initramfs

Create ʻinitrd.gz` in the boot partition and use it at boot time.

# /tmp/Various directories so that commands can be executed under root/tmp/Mount under root
$ sudo mount --bind /sys  /tmp/root/sys
$ sudo mount --bind /proc /tmp/root/proc
$ sudo mount --bind /dev  /tmp/root/dev

# /tmp/root/initrd to boot.Create gz
$ sudo chroot /tmp/root/ apt install lvm2
$ sudo chroot /tmp/root/ mkinitramfs -o /boot/initrd.gz

# boot/config.In txt"initramfs initrd.img followkernel"Add
$ cat /tmp/root/boot/config.txt
:
initramfs initrd.gz 0x01f00000

At the beginning, I mentioned that I can't create an initramfs when working on a PC, because ʻapt install lvm2` here doesn't work. After installing the lvm2 package, the process of creating the initramfs runs, but it seems that the cause is that the correct kernel version cannot be obtained at this time (check it because I have not followed the details).

##Clean up
$ sudo umount /tmp/root/sys /tmp/root/proc /tmp/root/dev
$ sudo umount /tmp/root/boot
$ sudo umount /tmp/root

This completes the installation. You can boot from the USB mass storage by shutting down the Raspberry Pi OS, unplugging the microSD, and then turning it on.

bonus

Since there are many steps, I made an installer.

https://github.com/nowlinuxing/rpi4-installer


Recommended Posts

USB boot with Raspberry Pi 4 Model B (3) LVM edition
USB boot on Raspberry Pi 4 Model B
raspberry pi 1 model b, python
raspberry pi 1 model b, node-red part 17
getrpimodel: Recognize Raspberry Pi model (A, B, B +, B2, B3, etc) with python
Hello World with Raspberry Pi + Minecraft Pi Edition
Infer Custom Vision model with Raspberry Pi
I tried L-Chika with Raspberry Pi 4 (Python edition)
GPS tracking with Raspberry Pi 4B + BU-353S4 (Python)
GPGPU with Raspberry Pi
DigitalSignage with Raspberry Pi
Machine learning with Raspberry Pi 4 and Coral USB Accelerator
Run LEDmatrix interactively with Raspberry Pi 3B + on Slackbot
Display USB camera video with Python OpenCV with Raspberry Pi
Raspberry Pi 4B initial setting
Run BNO055 python sample code with I2C (Raspberry Pi 3B)
Port FreeRTOS to Raspberry Pi 4B
SNS Flask (Model) edition made with Flask
[Raspberry Pi] Stepping motor control with Raspberry Pi
Use vl53l0x with Raspberry Pi (python)
Servo motor control with Raspberry Pi
USB over ethernet using Raspberry pi
Serial communication with Raspberry Pi + PySerial
OS setup with Raspberry Pi Imager
Try L Chika with raspberry pi
Programd automatic start at startup with Raspberry Pi 3B + systemd Summary
VPN server construction with Raspberry Pi
Try various Linux distributions with VMware ESXi arm edition + USB boot
Try moving 3 servos with Raspberry Pi
Using a webcam with Raspberry Pi
Seq2Seq (2) ~ Attention Model edition ~ with chainer
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
Logging the value of Omron environment sensor with Raspberry Pi (USB type)
Measure SIM signal strength with Raspberry Pi
Connect two USB cameras to Raspberry Pi 4
Pet monitoring with Rekognition and Raspberry pi
Raspberry Pi Security Infrared Camera (Python Edition)
Build a Tensorflow environment with Raspberry Pi [2020]
Programming normally with Node-RED programming on Raspberry Pi 3
Improved motion sensor made with Raspberry Pi
Try Object detection with Raspberry Pi 4 + Coral
Power SG-90 servo motor with raspberry pi
Use PIR motion sensor with raspberry Pi
Make a wash-drying timer with a Raspberry Pi
Build OpenCV-Python environment on Raspberry Pi B +
Operate an oscilloscope with a Raspberry Pi
Create a car meter with raspberry pi
Inkbird IBS-TH1 value logged with Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
I tried running Flask on Raspberry Pi 3 Model B + using Nginx and uWSGI
Discord bot with python raspberry pi zero with [Notes]
Media programming with Raspberry Pi (preparation for audio)
Why detectMultiScale () is slow on Raspberry Pi B +
Enjoy electronic work with GPIO on Raspberry Pi
MQTT RC car with Arduino and Raspberry Pi
Power on / off your PC with raspberry pi
Use Majoca Iris elongated LCD with Raspberry Pi
CSV output of pulse data with Raspberry Pi (CSV output)
Observe the Geminids meteor shower with Raspberry Pi 4
Play with your Ubuntu desktop on your Raspberry Pi 4
Introduced Ceph on Kubernetes on Raspberry Pi 4B (ARM64)