Merge "Fix for proper LVM support"

This commit is contained in:
Zuul 2018-07-24 07:32:10 +00:00 committed by Gerrit Code Review
commit 9adf12fe4a
5 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,15 @@
=====
lvm
=====
This is the LVM support element for Ubuntu Xenial.
Note that this element requires initramfs-tools and lvm2
packages to be added to the DIB image using -p option.
If this is not the case, an error will be triggered.
This element enables that an image build with a customized
DIB_BLOCK_DEVICE_CONFIG containing LVM volumes will boot
properly.
On CentOS like distributions, you should use dracut-regenerate
element instead of current lvm element.

View File

@ -0,0 +1,3 @@
bootloader
pkg-map
ubuntu-minimal

View File

@ -0,0 +1,65 @@
#!/bin/bash
# Configure grub. Note that the various conditionals here are to handle
# different distributions gracefully.
if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
BOOT_DEV=$IMAGE_BLOCK_DEVICE
# All available devices, handy for some bootloaders...
declare -A DEVICES
eval DEVICES=( $IMAGE_BLOCK_DEVICES )
# This might be better factored out into a per-distro 'install-bootblock'
# helper.
if [ -d /boot/grub2 ]; then
GRUB_CFG=/boot/grub2/grub.cfg
elif [ -d /boot/grub ]; then
GRUB_CFG=/boot/grub/grub.cfg
fi
if type grub2-mkconfig >/dev/null; then
GRUB_MKCONFIG="grub2-mkconfig -o $GRUB_CFG"
else
GRUB_MKCONFIG="grub-mkconfig -o $GRUB_CFG"
fi
# Retrieve root filesystem mount point to check if it is LVM based
ROOTFS=$(awk '$2=="/"{print}' /proc/mounts)
# Standard filesystems are mounted as /dev/mapper/loop* within DIB
# so we need to exclude this case
if echo "$ROOTFS" | grep -qv '/dev/mapper/loop'; then
# LVM based filesystems are mounted as /dev/mapper/<VG_name>-<LV-NAME> within DIB
if echo "$ROOTFS" | grep -q '/dev/mapper/'; then
# Check if initramfs-tools are installed
if [ ! -d /etc/initramfs-tools ]; then
echo "You must have initramfs-tools installed for LVM based root filesystem to work properly"
exit 1
fi
# Check if system supports LVM
if ! type pvs >/dev/null 2>&1; then
echo "You must have lvm2 package installed for LVM based root filesystem to work properly"
exit 1
fi
# Check for appropriate filesystem support (for fsck)
FSTYPE=$(echo $ROOTFS | awk '{print $3}')
if ! type fsck.$FSTYPE >/dev/null 2>&1; then
echo "You must have utility package for $FSTYPE filesystem installed for LVM based root filesystem to work properly (fsck.$FSTYPE is missing)"
exit 1
fi
# Change the current GRUB_DEVICE from LABEL=(cloud)img-rootfs to /dev/mapper/...
sed -i -e "s?^GRUB_DEVICE=.*?GRUB_DEVICE=$(echo $ROOTFS | awk '{print $1}')?" /etc/default/grub
# This is required for LVM2 driver to be included in the
# ramdisk of the image.
echo "lvm2" >> /etc/initramfs-tools/modules
# We need to regenerated the init ramdisk at this point
update-initramfs -u -v
fi
fi
$GRUB_MKCONFIG

View File

@ -0,0 +1,2 @@
lvm2:
initramfs-tools:

View File

@ -0,0 +1,17 @@
#!/bin/bash
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
if [ 'ubuntu' != $DISTRO_NAME ]; then
echo "Only ubuntu is supported for LVM support. The DISTRO is set to $DISTRO_NAME"
exit 1
fi
if [ 'xenial' != $DIB_RELEASE ]; then
echo "Only xenial is supported for LVM support. The DIB_RELEASE is set to $DIB_RELEASE"
exit 1
fi