Tuesday, 18 May 2021

Installing Manjaro Linux on logical volumes (LVM)

The default Manjaro installer looks as if it will allow you to define LVM partitions during the installation process but it actually won't. I like LVM a lot, and being determined to have a Manjaro system with LVMs underneath I spent some time researching and have what I think is a foolproof way of doing it.  

I'm assuming here that you want separate root and home volumes; if you don't these instructions should still work, but you'll need to adapt them.

Install Manjaro on ordinary partitions

I'll leave you to work out the sizes, and to decide whether you need an EFI partition and so on.

Boot a live CD/USB medium

I like sysrescueCD.

Dump the root and home partitions to external storage

I use fsarchiver to do the dumping.

fsarchiver savefs /mnt/sdb1/prospero/prospero-manjaro-nolvm.fsa /dev/nvme0n1p5 /dev/nvme0n1p5

Delete the root and home partitions and set up a PV

I use parted.  Something like this should work:

parted /dev/nvme0n1
(parted) p                                                                
Disk /dev/nvme0n1: 1024GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system     Name  Flags
 1      1049kB  538MB   537MB   fat32                 boot, esp
 2      538MB   1075MB  537MB   ext4
 3      1075MB  35.4GB  34.4GB  linux-swap(v1)        swap
 4      35.4GB  193GB   157GB   ext4
 5      193GB   1024GB  831GB   ext4

(parted) rm 5                                                             
(parted) rm 4                                                             
(parted) mkpart primary 35.4GB 100%                                       
(parted) set 4 lvm on                                                     
(parted) quit 

Set up the volume group and the LVs

[root@sysrescue ~]# pvcreate /dev/nvme0n1p4                               
WARNING: ext4 signature detected on /dev/nvme0n1p4 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/nvme0n1p4.
  Physical volume "/dev/nvme0n1p4" successfully created.
[root@sysrescue ~]# vgcreate vg01 /dev/nvme0n1p4
  Volume group "vg01" successfully created
[root@sysrescue ~]# lvcreate -L 100G --name root vg01
  Logical volume "root" created.
[root@sysrescue ~]# lvcreate -L 500G --name home vg01
  Logical volume "home" created.

Restore the dumped partitions

fsarchiver restfs /mnt/sdb1/prospero/prospero-manjaro-nolvm.fsa id=0,dest=/dev/mapper/vg01-root id=1,dest=/dev/mapper/vg01-home

Mount the root partition

mkdir /linux
mount /dev/mapper/vg01-root /linux

Get the UUIDs of the partitions

blkid /dev/mapper/vg01-root /dev/mapper/vg01-home

 Now use an editor (I like sed for this) to change the UUIDs for the root and home filesystems in /linux/etc/fstab to be the UUIDs displayed above.  You may not need to make any changes.

 chroot into the mounted root filesystem

modprobe efivarfs
arch-chroot /linux

(That "modprobe" is in there because of this Stack Exchange article.)

Mount required other filesystems and reinstall grub

mount /dev/nvme0n1p2 /boot
mount /dev/nvme0n1p1 /boot/efi
mount -t efivarfs efivarfs /sys/firmware/efi/efivars
grub-install /dev/nvme0n1

Add LVM2 to the hooks in the initramfs

(Otherwise the LVM filesystems aren't seen by the kernel, which doesn't end well)

sed -i 's/base udev autodetect modconf block/base udev autodetect modconf block lvm2/' /etc/mkinitcpio.conf

 The LVM2 hook must be after "block".

mkinitcpio -P

Reboot and your system should be running again


No comments:

Post a Comment