Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 2850

Raspberry Pi OS • Bookworm LVM rootfs

$
0
0
Hi Folks,

This does seem possible. It came up as a side issue on viewtopic.php?t=363217. I blatted my rpi5 this morning, installed 2023-10-10-raspios-bookworm-arm64.img.xz onto an sdcard, added lvm2 then copied it to a gpt lvm partioned ssd which booted. I then performed an update (which involved a kernel update) and rootfs was still bootable. I'll await another kernel update to be certain.

Should anyone desire to play with this idea then the following is the sequence of events. A major warning to casual viewers. Do NOT casually paste this into a script and fiddle with it because it WILL destroy the target device contents. Obviously 'sys-rbackup' does not exist for others. Replace with a suitable alternative (it's an rsync with suitable options). The 'sed' is not very clever but suffices for a stock rpi image.

Code:

foo@pi23:/wrk $ cat sdlvm#!/bin/false#umount /mnt/dev/p2#umount /mnt/dev/p1#vgremove $(hostname)#pvremove "$1""2"which pvs || exit 1[ -z "$1" ] && exit 1E=echo#chk and umount /dev/media/*$E vgchange -an -y $(hostname)$E vgremove -y $(hostname)$E pvremove "$1""2"$E parted -s "$1" mklabel gpt || exit 1$E parted -s "$1" mkpart primary 4M 516M || exit 1$E parted -s "$1" mkpart primary 516M 64G || exit 1$E parted -s "$1" name 1 bootfs || exit 1$E parted -s "$1" name 2 rootfs || exit 1$E parted -s "$1" set 1 boot on || exit 1$E parted -s "$1" set 2 lvm on || exit 1$E pvcreate "$1""2"  || exit 1$E vgcreate $(hostname) "$1""2" || exit 1$E lvcreate -y -n rootfs -l 100%FREE $(hostname) || exit 1$E mkfs.vfat "$1""1" || exit 1$E mkfs.ext4 "/dev/"$(hostname)"/rootfs" || exit 1$E mkdir -p /mnt/dev/p{1,2} || exit 1$E mount "$1""1" /mnt/dev/p1 || exit 1$E mount "/dev/"$(hostname)"/rootfs" /mnt/dev/p2 || exit 1$E update-initramfs -u -k all$E DRY=" " sys-rbackup /boot/firmware/ /mnt/dev/p1/ || exit 1$E DRY=" " sys-rbackup / /mnt/dev/p2/ || exit 1$E sed -i -e "s,root=[^[:space:]]*,root=/dev/mapper/$(hostname)-rootfs," /mnt/dev/p1/cmdline.txt || exit 1$E sed -i -e "s,PART.*=.*-01[^[:space:]]*,PARTLABEL=bootfs," /mnt/dev/p2/etc/fstab || exit 1$E sed -i -e "s,PART.*=.*-02[^[:space:]]*,/dev/mapper/$(hostname)-rootfs," /mnt/dev/p2/etc/fstab || exit 1$E cat /mnt/dev/p2/etc/fstab$E umount /mnt/dev/p2 || exit 1$E cat /mnt/dev/p1/cmdline.txt$E umount /mnt/dev/p1 || exit 1
A successful run will produce this..

Code:

foo@pi23:/wrk $ sudo parted /dev/sda p freeModel: asmedia ASMT1153e (scsi)Disk /dev/sda: 1000GBSector size (logical/physical): 512B/4096BPartition Table: gptDisk Flags: Number  Start   End     Size    File system  Name    Flags        17.4kB  4194kB  4177kB  Free Space 1      4194kB  516MB   512MB   fat16        bootfs  boot, esp 2      516MB   64.0GB  63.5GB               rootfs  lvm        64.0GB  1000GB  936GB   Free Space        foo@pi23:/wrk $ df -hPFilesystem               Size  Used Avail Use% Mounted onudev                     3.8G     0  3.8G   0% /devtmpfs                    806M  5.6M  800M   1% /run/dev/mapper/pi23-rootfs   58G  5.5G   50G  10% /tmpfs                    4.0G   32K  4.0G   1% /dev/shmtmpfs                    5.0M   48K  5.0M   1% /run/lock/dev/sda1                488M   81M  407M  17% /boot/firmwaretmpfs                    806M  128K  806M   1% /run/user/1000foo@pi23:/wrk $ cat /boot/firmware/cmdline.txt console=serial0,115200 console=tty1 root=/dev/mapper/pi23-rootfs rootfstype=ext4 fsck.repair=yes rootwaitfoo@pi23:/wrk $ cat /etc/fstab | egrep -v "^(#|$)"proc            /proc           proc    defaults          0       0PARTLABEL=bootfs  /boot/firmware  vfat    defaults          0       2/dev/mapper/pi23-rootfs  /               ext4    defaults,noatime  0       1foo@pi23:/wrk $ ls -l /dev/mappertotal 0crw------- 1 root root 10, 236 Feb 28 15:30 controllrwxrwxrwx 1 root root       7 Feb 28 15:30 pi23-rootfs -> ../dm-0foo@pi23:/wrk $ sudo pvs  PV         VG   Fmt  Attr PSize  PFree  /dev/sda2  pi23 lvm2 a--  59.12g    0     foo@pi23:/wrk $ sudo vgs  VG   #PV #LV #SN Attr   VSize  VFree  pi23   1   1   0 wz--n- 59.12g    0    foo@pi23:/wrk $ sudo lvs  LV     VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert  rootfs pi23 -wi-ao---- 59.12g 
I think this is the module (guessing, I've not checked)..

Code:

foo@pi23:/wrk $ lsmod | grep dm_moddm_mod                180224  3
Ultimately I want a GUI app(*) to do this. In the meantime, a command line tool(**) would suffice, if there's interest?

(*) Was going to list advantages. Seems I'm away for a couple of days. :-|

(**) I have to code for others rather than myself but much quicker than (*).

Statistics: Posted by swampdog — Wed Feb 28, 2024 5:49 pm



Viewing all articles
Browse latest Browse all 2850

Trending Articles