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
.
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
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/
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.
Since there are many steps, I made an installer.
https://github.com/nowlinuxing/rpi4-installer
Recommended Posts