= Move root and boot to new LVM mirrored SDDs = == LVM == Detail see [https://wiki.gentoo.org/wiki/LVM] === Basic Discs === two 1TB disks. Partition layout will be gpt with 3 partitions (BIOS boot 2M, EFI system, Linux LVM). LVM will be RAID1. Disks are sdd and sde on initial attachment. ==== Partitioning: ==== {{{ fdisk /dev/sdd g n default +2M t 1 4 n default +128M t 2 1 n default default t 3 30 w p }}} Result: {{{ Festplatte /dev/sdd: 931,51 GiB, 1000204886016 Bytes, 1953525168 Sektoren Festplattenmodell: Samsung SSD 870 Einheiten: Sektoren von 1 * 512 = 512 Bytes Sektorgröße (logisch/physikalisch): 512 Bytes / 512 Bytes E/A-Größe (minimal/optimal): 512 Bytes / 512 Bytes Festplattenbezeichnungstyp: gpt Festplattenbezeichner: EA219CEB-45F9-C34C-8C6B-A3F491EA8B88 Gerät Anfang Ende Sektoren Größe Typ /dev/sdd1 2048 6143 4096 2M BIOS boot /dev/sdd2 6144 268287 262144 128M EFI-System /dev/sdd3 268288 1953525134 1953256847 931,4G Linux LVM }}} repeat for second disk /dev/sde ==== LVM: ==== ===== Physical volumes ===== {{{ pvcreate /dev/sd[de]3 }}} Result in **dvdisplay** {{{ --- Physical volume --- PV Name /dev/sdd3 VG Name vg01 PV Size <931,39 GiB / not usable 2,69 MiB Allocatable yes PE Size 4,00 MiB Total PE 238434 Free PE 172897 Allocated PE 65537 PV UUID 9KCwX5-KuDX-de30-J0ke-9822-ljkX-wj3jKr --- Physical volume --- PV Name /dev/sde3 VG Name vg01 PV Size <931,39 GiB / not usable 2,69 MiB Allocatable yes PE Size 4,00 MiB Total PE 238434 Free PE 172897 Allocated PE 65537 PV UUID N4TuOc-Dq6A-ZwVW-61t7-gfME-pSFu-Q9Iwty }}} ===== Volume group ===== {{{ vgcreate vg01 /dev/sd[de]3 }}} Result in **vgdisplay** {{{ --- Volume group --- VG Name vg01 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size <1,82 TiB PE Size 4,00 MiB Total PE 476868 Alloc PE / Size 131074 / <512,01 GiB Free PE / Size 345794 / <1,32 TiB VG UUID i1M7O9-dbOQ-azV4-ajmF-utwq-cKaj-RhBROV }}} ===== Logical Volumes ===== ====== for root ====== {{{ lvcreate --mirrors 1 --type raid1 -L 256G -n root vg01 }}} Result in **lvdisplay** {{{ --- Logical volume --- LV Path /dev/vg01/root LV Name root VG Name vg01 LV UUID N95R5k-dFV6-VecO-j2yQ-nQ12-xjwC-eyjnZ9 LV Write Access read/write LV Creation host, time snailix, 2021-11-11 23:58:06 +0100 LV Status available # open 1 LV Size 256,00 GiB Current LE 65536 Mirrored volumes 2 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:4 }}} === block ids === ==== root ==== {{{ blkid | grep vg01-root }}} {{{ /dev/mapper/vg01-root_rimage_0: UUID="06a2c8e7-dc77-49db-8e72-c7d0fa9ebe77" BLOCK_SIZE="4096" TYPE="ext4" /dev/mapper/vg01-root: UUID="06a2c8e7-dc77-49db-8e72-c7d0fa9ebe77" BLOCK_SIZE="4096" TYPE="ext4" /dev/mapper/vg01-root_rimage_1: UUID="06a2c8e7-dc77-49db-8e72-c7d0fa9ebe77" BLOCK_SIZE="4096" TYPE="ext4" }}} ==== boot ==== {{{ blkid | grep sdd2 }}} {{{ /dev/sdd2: UUID="bfb2c0c7-e7bf-44d3-b8c9-1cd60ace50a4" BLOCK_SIZE="1024" TYPE="ext2" PARTUUID="e7666b15-77f8-2942-806b-6f5a198fa496" }}} === copy root from old installation === Boot from USB and mount the old and the new root. mount using UUID to be sure to mount the right devices. {{{ mkdir /mnt/root-old mkdir /mnt/root-new mount UUID="fcafeec5-6c23-4edd-acf3-dfab41ae7776" /mnt/root-old mount UUID="06a2c8e7-dc77-49db-8e72-c7d0fa9ebe77" /mnt/root-new rsync -aHv --progress --delete /mnt/root-old/ /mnt/root-new/ }}} === fstab === edit fstab to reflect the UUIDs {{{ UUID="bfb2c0c7-e7bf-44d3-b8c9-1cd60ace50a4" /boot ext2 noauto,noatime 1 2 UUID="06a2c8e7-dc77-49db-8e72-c7d0fa9ebe77" / ext4 noatime 0 1 ... }}} === initramfs === mount sdd2 on boot (using UUID to be sure that it is the correct one) {{{ umount /boot mount UUID="bfb2c0c7-e7bf-44d3-b8c9-1cd60ace50a4" /boot }}} generate initrd (wiht lvm busybox luks support) {{{ genkernel --lvm --busybox --luks --install initramfs }}} === grub2 === Grub2 installation. using gpt layout but no UEFI. ==== Install ==== {{{ grub-install /dev/sdd grub-install /dev/sde }}} ==== Default ==== in /etc/default/grub {{{ GRUB_CMDLINE_LINUX="dolvm root=UUID=06a2c8e7-dc77-49db-8e72-c7d0fa9ebe77 rootfstype=ext4 vga=0x31B init=/usr/lib/systemd/systemd" }}} ==== Config ==== {{{ grub-mkconfig -o /boot/grub/grub.cfg }}} **Remark:** for me during runtime the disks are sdd (hd3) and sde (hd4) but during boot they are sda (hd0) and sdb (hd1) because the devices on the hardware controller are moved to sda, ... Therfore I have to change the hd-entries in /boot/grub/grub.cfg using {{{ sed -i 's/hd3/hd0/g' /boot/grub/grub.cfg }}} ==== Sync boot over discs ==== to be able to boot from another disk (I have 3 disk that have a grub2 installation) I use the following script. (create mountpoints in /mnt accordingly). And this relies on a correct entry for boot in fstab) {{{ echo 'mount boot' mount /boot echo 'mount sda1' mount /dev/sda1 /mnt/sda1 echo 'mount sde2' mount /dev/sde2 /mnt/sde2 echo 'sync to sda1' rsync -aHv --progress --delete /boot/ /mnt/sda1/ echo 'sync to sde2' rsync -aHv --progress --delete /boot/ /mnt/sde2/ echo 'umount sde2' umount /mnt/sde2 echo 'umount sda1' umount /mnt/sda1 echo 'umount boot' umount /boot echo 'done' }}}