jasonwryan.com

Miscellaneous ephemera…

Chroot in LVM on LUKS on Raid: Arch Linux

image

In my previous post describing this setup I made the point that grub won’t be installed and that it is necessary to chroot in to install grub on both drives. This is the procedure I use to do that—and to perform any other maintenance that requires working from a live environment.

Again, most of this information is on the Arch Wiki chroot page, I am just going to fill in the detail around this setup: LVM on LUKS on Raid1.

Once you have booted into your live environment, load the modules that are required; in this case: raid1, dm-mod and dm-crypt.

Check that udev hasn’t helpfully read the superblock of your Raid drives and assembled phantom arrays:

1
cat /proc/mdstat

I find that there are a couple there generally assigned the names /dev/md126 and /dev/md127. These need to be stopped before assembling the correct arrays:

1
2
3
mdadm --stop /dev/md12[67]
mdadm --assemble /dev/md0 /dev/sd[ab]1
mdadm --assemble /dev/md1 /dev/sd[ab]2

You should now have both your arrays up and running. The next step is to unlock your encrypted device:

1
cryptsetup luksOpen /dev/md1 cryptdisk

After entering your passphrase, your device will be unlocked. Next, make the logical volumes available, and then check they are correct:

1
2
vgchange --available y vgroup
lvscan

At this point, you are ready to mount the devices and chroot:

1
2
mkdir /mnt/arch
mount /dev/mapper/vgroup-lvroot /mnt/arch

The next steps are straight from the wiki:

1
2
3
4
cd /mnt/arch
mount -t proc proc proc/
mount -t sysfs sys sys/
mount -o bind /dev dev/

Mount the other parts of the system that you need to use in your recovery – in this case, I need my /boot partition:

1
mount /dev/md0 boot/

Now chroot to the device and define your shell:

1
chroot . /bin/bash

The wiki has some good advice about customizing your prompt to reinforce the fact that you are in a chroot:

1
export PS1="(chroot) $PS1"

With everything mounted, it is just a matter of performing your maintenance. To reinstall grub:

1
2
3
4
5
6
# grub
grub> find /grub/stage1
grub> device (hd0) /dev/sda
grub> root (hd0,0)
grub> setup (hd0)
grub> quit

Repeat for /dev/sdb and both your drives will be bootable in the event that one fails.

With the maintenance accomplished, all that remains is to exit the chroot and unmount the devices cleanly:

1
2
3
4
5
exit
umount {proc,sys,dev,boot...}
cd ..
umount arch/
reboot

Simple.

Creative Commons image by MPD01605

Comments