From: Alex Hornung Date: Wed, 7 Jul 2010 22:31:26 +0000 (+0100) Subject: initrd - Update for LVM root support X-Git-Url: https://gitweb.dragonflybsd.org/~lentferj/dragonfly.git/commitdiff_plain/a208b6ca921421a5ad5c1af8c6ce4f5b18f56385 initrd - Update for LVM root support * Also add support for some generic mounting of local volumes (configured via the loader tunable vfs.root.realroot) and scriptable mounting of other kinds of volumes. * Add some more tools to the default mkinitrd set * Add support to mount crypt volumes --- diff --git a/sbin/mkinitrd/mkinitrd.sh b/sbin/mkinitrd/mkinitrd.sh index 298cda4d2d..7e3d2b952c 100644 --- a/sbin/mkinitrd/mkinitrd.sh +++ b/sbin/mkinitrd/mkinitrd.sh @@ -2,8 +2,8 @@ BUILD_DIR="/tmp/initrd" INITRD_SIZE="15m" -BIN_TOOLS="echo ln ls mv rm rmdir sh" -SBIN_TOOLS="mount mount_devfs mount_hammer mount_nfs mount_null mount_procfs mount_tmpfs umount iscontrol cryptsetup lvm" +BIN_TOOLS="echo ln ls mkdir mv rm rmdir sh" +SBIN_TOOLS="mount mount_devfs mount_hammer mount_nfs mount_null mount_procfs mount_tmpfs umount iscontrol cryptsetup lvm sysctl" INITRD_DIRS="bin boot dev etc mnt proc sbin tmp var new_root" CONTENT_DIRS="/usr/share/initrd" diff --git a/share/initrd/Makefile b/share/initrd/Makefile index 3137e06f7f..3f2bacaec8 100644 --- a/share/initrd/Makefile +++ b/share/initrd/Makefile @@ -6,7 +6,7 @@ #add ${VAR_FILES} to FILES= #add a for loop for ${VAR_FILES} -ETC_FILES= rc +ETC_FILES= rc rc.lvm2 rcmount_crypt FILES= ${ETC_FILES} .for file in ${ETC_FILES} diff --git a/share/initrd/rc b/share/initrd/rc index 24e185a96f..c26fd7e25c 100644 --- a/share/initrd/rc +++ b/share/initrd/rc @@ -3,8 +3,58 @@ # echo "Starting shell from md boot" # exec sh +/sbin/mount_tmpfs tmpfs /tmp +/sbin/mount_tmpfs tmpfs /var +mkdir /var/tmp + +rescue_shell() { + echo "Starting recovery shell!" + exec sh + exit 0 +} + +for rcs in /etc/rc.*; do + if [ -x $rcs ]; then + . $rcs + fi +done + echo "Mounting new root" -/sbin/mount -t hammer /dev/da0s1d /new_root + +IFS=':' +REAL_ROOT=`sysctl -n vfs.real_root` +if [ "$?" -ne "0" ]; then + echo "Kernel does not have vfs.real_root sysctl. Please update your" \ + "kernel if you intend to use initrd" + rescue_shell +fi +set -- $REAL_ROOT +TYPE=$1 +unset IFS + +if [ "$TYPE" = "local" ]; then + FSTYPE=$2 + MOUNTFROM=$3 + echo "executing /sbin/mount -t $FSTYPE $4 $MOUNTFROM /new_root" + /sbin/mount -t $FSTYPE $4 $MOUNTFROM /new_root + if [ "$?" -ne "0" ]; then + rescue_shell + fi +else + if [ -x "/etc/rcmount_${TYPE}" ]; then + . /etc/rcmount_${TYPE} $@ + if [ "$?" -ne "0" ]; then + rescue_shell + fi + else + rescue_shell + fi +fi + +rm -rf /var/* +rm -rf /tmp/* +/sbin/umount /var +/sbin/umount /tmp echo "Mounting devfs on new root" #/sbin/mount_devfs /new_root/dev diff --git a/share/initrd/rc.lvm2 b/share/initrd/rc.lvm2 new file mode 100755 index 0000000000..5f27ff8a81 --- /dev/null +++ b/share/initrd/rc.lvm2 @@ -0,0 +1,23 @@ +#!/bin/sh + +if [ ! -x /sbin/lvm ]; then + return 1; +fi + +echo "Configuring LVM volumes" + +if [ ! -d /tmp/lvm2 ]; then + mkdir -p /tmp/lvm2 +fi + +export LVM_SYSTEM_DIR=/tmp/lvm2 + +# Scan for volume groups +/sbin/lvm vgscan --mknodes --ignorelockingfailure &> /dev/null + +# Change volume availability to yes +/sbin/lvm vgchange --ignorelockingfailure -a y > /dev/null + +# Get a list of volumes and display it +LV_LIST=$( /sbin/lvm vgdisplay -C -o vg_name --noheadings 2> /dev/null ) +echo " Activated Volume Groups: $LV_LIST" diff --git a/share/initrd/rcmount_crypt b/share/initrd/rcmount_crypt new file mode 100755 index 0000000000..9fc0a033cc --- /dev/null +++ b/share/initrd/rcmount_crypt @@ -0,0 +1,28 @@ +#!/bin/sh + +if [ ! -x /sbin/cryptsetup ]; then + return 1; +fi + +FSTYPE=$2 +MOUNTFROM=$3 +VOLUME=$4 +OPTIONS=$5 + +# Check if the volume is really a luks volume +/sbin/cryptsetup isLuks $MOUNTFROM +if [ "$?" -ne "0" ]; then + return 1; +fi + +# Open crypto volume +/sbin/cryptsetup $OPTIONS luksOpen $MOUNTFROM $VOLUME +if [ "$?" -ne "0" ]; then + return 2; +fi + +# Mount, as is expected, onto /new_root +mount -t $FSTYPE /dev/mapper/$VOLUME /new_root +if [ "$?" -ne "0" ]; then + return 3; +fi