The basic steps are the following:
- Create an USB-Stick with a livesystem of Ubuntu (I used Ubuntu 20.04)
- Boot the system from the USB-Stick
- Assemble raid, unlock the encryption, mount volume group and partition for preparation of chroot
- chroot to the system to fix
- install mdadm, fix content of crypttab, /etc/modules, update-initramfs and update-grub
- reboot the system
Here a little more detail for steps 3 and 5:
Save the script for step 5 before step 3 to let it be put to the right spot by the script of step 3. I putted everything in scripts, so I was able to resume my work more easily.
Step 3 (save this to some volume available in the livesystem to make it reproducible, adapt directories to your setup):
#!/bin/bash
# script to assemble the raid, open the encryption, open the volume group and mount all partitions for inspection for a system configured as in https://superuser.com/questions/1020806/how-to-install-ubuntu-15-10-on-an-encrypted-raid-1
# the directory in which the system to inspect is mounted
MOUNT_DIRECTORY="/media/system_to_fix"
if [ -d "$MOUNT_DIRECTORY" ]; then
echo "$MOUNT_DIRECTORY already exists, please delete (after checking) and start again"
exit
fi
# the name of the script to fix the broken system for execution in the chroot
CHROOT_SCRIPT_SOURCE_FILE="install_mdadm_and_fix_grub_in_chroot.sh"
# the path to the script file
CHROOT_SCRIPT_SOURCE_PATH="/media/ubuntu/stick/$CHROOT_SCRIPT_SOURCE_FILE"
if [ ! -f "$CHROOT_SCRIPT_SOURCE_PATH" ]; then
echo "$CHROOT_SCRIPT_SOURCE_PATH doesn't exists, please check and start again"
exit
fi
read -p "verify that your system is setup according to https://superuser.com/questions/1020806/how-to-install-ubuntu-15-10-on-an-encrypted-raid-1 or adapt accordingly"
sudo apt-get install mdadm cryptsetup
echo "assemble raid"
sudo mdadm --assemble --scan
echo "open ecrypted partition 2 in raid"
sudo cryptsetup luksOpen /dev/md0p2 lukslvm
sudo vgchange -a y
echo "updating volumn group metadata, as this was not up to data and caused a warning"
sudo vgck --updatemetadata vgubuntu
echo "creating directories for mounting"
sudo mkdir $MOUNT_DIRECTORY
sudo mkdir $MOUNT_DIRECTORY/root
sudo mkdir $MOUNT_DIRECTORY/root/home
echo "mounting root"
sudo mount /dev/mapper/vgubuntu-root $MOUNT_DIRECTORY/root
echo "mounting home"
sudo mount /dev/mapper/vgubuntu-home $MOUNT_DIRECTORY/root/home
echo "mounting boot"
sudo mount /dev/md0p1 $MOUNT_DIRECTORY/root/boot/
echo "mounting dev from livesystem"
sudo mount -o rbind /dev $MOUNT_DIRECTORY/root/dev
echo "mounting proc from livesystem"
sudo mount -t proc proc $MOUNT_DIRECTORY/root/proc/
echo "mounting sys from livesystem"
sudo mount -t sysfs sys $MOUNT_DIRECTORY/root/sys
echo "copy resolv.conf from livesystem to system to inspect/fix"
sudo cp /etc/resolv.conf $MOUNT_DIRECTORY/root/etc/resolv.conf
echo "copy script for execution in chroot to $MOUNT_DIRECTORY/root/tmp/$CHROOT_SCRIPT_SOURCE_FILE"
sudo cp $CHROOT_SCRIPT_SOURCE_PATH $MOUNT_DIRECTORY/root/tmp/$CHROOT_SCRIPT_SOURCE_FILE
echo "chroot setup, call 'sudo chroot $MOUNT_DIRECTORY/root /bin/bash' to chroot and execute sh /tmp/$CHROOT_SCRIPT_SOURCE_FILE"
Don't forget to chroot before executing the next script.
Step 5 (save this to "install_mdadm_and_fix_grub_in_chroot.sh" on some volume available in the livesystem to make it reproducible, adapt directories to your setup):
#!/bin/bash
# script to fix installation of mdadm, content of crypttab, /etc/modules and execution of update-initramfs and update-grup or exection in chroot of a system configured as in https://superuser.com/questions/1020806/how-to-install-ubuntu-15-10-on-an-encrypted-raid-1
echo "updating package cache and install emacs and mdadm"
sudo apt-get update
sudo apt-get install emacs mdadm
read -p "reading UUID of root device /dev/md0p2"
blkid /dev/md0p2
read -p "edit crypttab add line 'lukslvm UUID=<VOLUME_ID> none luks'"
emacs /etc/crypttab
read -p "edit modules add line 'dm-crypt'"
emacs /etc/modules
update-initramfs -u -k all
read -p "add 'kopt=root=/dev/mapper/vgubuntu-root' to 'GRUB_CMDLINE_LINUX_DEFAULT' in /etc/default/grub"
emacs /etc/default/grub
echo "updating grub"
sudo update-grub
echo "reboot and enjoy ;)"
During fixing I had an issue with updating the initramfs:
cryptsetup: WARNING: target 'lukslvm'
This prevented the solution to the initial issue. I didn't really figure out what solved this issue. It was "magically" fixed after I added some convenience features in my scripts. The only difference I can remember, is that I mounted "/home" too, which I didn't in the previous version of my script. But this should not influence the crypt configuration at all, at least what I would expect.