LVM on OS
Posted: 22 Mar 2024, 14:48
Greetings from North America 
We are building a project including multiple RevPI (part PR100379, 32GB,4GB of RAM)
We installed the provided OS on those devices but we noticed that the OS is sitting on a single partition "/" and we would like to use LVM and create separated partitions such as /var, /var/log, /home, /.
Why so ?
1. Suggested by the CIS benchmark for Debian
2. Common good practice: eg: even if you have a good monitoring system, you may have a process that starting logging a lot of data an fill up the whole disk/partition so the whole system will stop. When using a separated partition, it would be impossible to write any logs but the rest of the services will continue to work.
Why LVM ?: Easier to manage
I have followed the instructions from https://github.com/MikeJansen/rpi-boot-lvm to create extract and recreate an OS with LVM.
It worked on a traditional Raspberry PI using an SD Card but the MMC flash is causing more issue.
I udpdated the /boot/cmdline.txt to use root=LABEL=root and removed the waitroot=true and restarted the device. It boots but there is a kernel panic saying it couldn't find the LABEL=root.
I have a feeling there is an issue the driver not loaded soon enough or something else...
I was wondering the community could help me with this issue ?
Thanks a lot for your help
P.
I'm sharing my curated documentation below:

We are building a project including multiple RevPI (part PR100379, 32GB,4GB of RAM)
We installed the provided OS on those devices but we noticed that the OS is sitting on a single partition "/" and we would like to use LVM and create separated partitions such as /var, /var/log, /home, /.
Why so ?
1. Suggested by the CIS benchmark for Debian
2. Common good practice: eg: even if you have a good monitoring system, you may have a process that starting logging a lot of data an fill up the whole disk/partition so the whole system will stop. When using a separated partition, it would be impossible to write any logs but the rest of the services will continue to work.
Why LVM ?: Easier to manage
I have followed the instructions from https://github.com/MikeJansen/rpi-boot-lvm to create extract and recreate an OS with LVM.
It worked on a traditional Raspberry PI using an SD Card but the MMC flash is causing more issue.
I udpdated the /boot/cmdline.txt to use root=LABEL=root and removed the waitroot=true and restarted the device. It boots but there is a kernel panic saying it couldn't find the LABEL=root.
I have a feeling there is an issue the driver not loaded soon enough or something else...
I was wondering the community could help me with this issue ?
Thanks a lot for your help
P.
I'm sharing my curated documentation below:
Code: Select all
mount /dev/sdb2 rpi
mount /dev/sdb1 rpi/boot/firmware
DISK=/dev/sdb
parted $DISK mkpart primary fat32 2048s 512MiB
parted $DISK mkpart primary ext4 512MiB 100%
parted $DISK set 2 lvm on
mkfs.fat -F 32 -n bootfs ${DISK}1
pvcreate ${DISK}2
vgcreate rpi ${DISK}2
lvcreate -L 10G -n root rpi
lvcreate -L 5G -n var rpi
lvcreate -L 5G -n var_log rpi
lvcreate -L 2G -n tmp rpi
lvcreate -L 5G -n home rpi
mke2fs -t ext4 -L root-rpi /dev/rpi/rootfs
mke2fs -t ext4 -L root /dev/rpi/root
mke2fs -t ext4 -L var /dev/rpi/var
mke2fs -t ext4 -L var_log /dev/rpi/var_log
mke2fs -t ext4 -L tmp /dev/rpi/tmp
mke2fs -t ext4 -L home /dev/rpi/home
mount /dev/rpi/root rpi
mkdir -p rpi/boot/firmware
mkdir -p rpi/var/log
mkdir -p rpi/home
mkdir -p rpi/tmp
mount ${DISK}1 rpi/boot/firmware
mount /dev/rpi/var_log rpi/var/log
mount /dev/rpi/home rpi/home
mount /dev/rpi/tmp rpi/tmp
mount /dev/rpi/var rpi/var
tar -xvzf rpi-lvm.tar.gz -C rpi
# Update root=XXXXX to root=LABEL=root
vim rpi/boot/firmware/cmdline.txt
cat << EOF > rpi/etc/fstab
proc /proc proc defaults 0 0
LABEL=bootfs /boot/firmware vfat defaults 0 2
LABEL=root / ext4 defaults,noatime 0 1
LABEL=var /var ext4 defaults,noatime 0 1
LABEL=var_log /var/log ext4 defaults,noatime 0 1
LABEL=home /home ext4 defaults,noatime 0 1
LABEL=tmp /tmp ext4 defaults,noatime 0 1
EOF
umount rpi/boot/firmware
umount rpi/home
umount rpi/tmp
umount rpi/var
umount rpi/var/log
umount rpi