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

Raspberry Pi OS • Re: Bookworm LVM rootfs

$
0
0
With Pimoroni advertising an upcoming dual nvme pcie hat, I may have to reconsider mdadm being pointless.

Wrt lvm I have a working script. Pretty much what I posted..

Code:

#!/bin/bash#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 -y --force --force "$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 -F 32 "$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
..substituting E= for sudo of course.

I think it will have to be an app for general use. I accidentally had my rpi5 collide on the network with an rpi4 which only became apparent when I couldn't "find" the rpi4 to copy its stuff. Fixed that. rpi5 is now pi24. rpi4 is back to being pi23. The script fails on the target because there is an existing VG of a different name. ie: pi05 encounters "pi04" VG. Yes, this can be solved with a heavy blat of the target disk but I envisage lots of accidental trashing of folks disks if I did that.

The safe way forward is to present it visually and/or require the user to have invoked (say) gparted to wipe the target disk beforehand.

Anyway, for those who understand shell script, the above is what I used earlier to make my rpi5 sdcard write itself to the ssd. Replace 'sys-rbackup' with a similar "clone disk" command accordingly.

Important thing is. LVM works. When you "apt-get install lvm2" the initramfs stuff gets called and is thereafter automatic just like other linux systems.

Statistics: Posted by swampdog — Fri Mar 15, 2024 8:27 pm



Viewing all articles
Browse latest Browse all 5161

Trending Articles