initrd.scripts: move media_find, start_volumes, setup_md_devices to 00-fsdev.sh

master
Fabio Erculiani 12 years ago
parent cd20666829
commit c6af477460

@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
. /etc/initrd.d/00-common.sh . /etc/initrd.d/00-common.sh
. /etc/initrd.d/00-devmgr.sh
mount_sysfs() { mount_sysfs() {
mount -t sysfs sysfs /sys -o noexec,nosuid,nodev \ mount -t sysfs sysfs /sys -o noexec,nosuid,nodev \
@ -51,4 +52,165 @@ get_device_fstype() {
bad_msg "Cannot resolve device: ${1}" bad_msg "Cannot resolve device: ${1}"
return 1 return 1
fi fi
} }
media_find() {
# $1 = mount dir name / media name
# $2 = recognition file
# $3 = variable to have the device path
# $4 = actual mount dir path (full path)
# args remaining are possible devices
local media="${1}" recon="${2}" vrbl="${3}" mntdir="${4}"
shift 4
good_msg "Looking for the ${media}"
if [ "$#" -gt "0" ]; then
[ ! -d "${mntdir}" ] && \
mkdir -p "${mntdir}" 2>/dev/null >/dev/null
local mntcddir="${mntdir}"
if [ -n "${ISOBOOT}" ]; then
mntcddir="${mntdir%${media}}iso"
if [ ! -f "${mntcddir}" ]; then
mkdir "${mntcddir}"
fi
fi
for x in ${*}; do
# Check for a block device to mount
if [ ! -b "${x}" ]; then
continue
fi
#
# If disk and it has at least one partition, skip.
# We use /sys/block/${bsn}/${bsn}[0-9]* to make sure that we
# don't skip device mapper devices. Even the craziest scenario
# deserves a fair chance.
#
local bsn=$(basename "${x}")
local bpath="/sys/block/${bsn}"
local parts=$(find "${bpath}/" \
-regex "${bpath}/${bsn}[0-9]" -type d 2>/dev/null)
[ -n "${parts}" ] && continue
good_msg "Attempting to mount media: ${x}"
mount -r -t "${CDROOT_TYPE}" "${x}" "${mntcddir}" >/dev/null 2>&1 \
|| continue
if [ -n "${ISOBOOT}" ] && [ -f "${mntcddir}/${ISOBOOT}" ]; then
mount -o loop "${mntcddir}/${ISOBOOT}" "${mntdir}" && \
good_msg "iso mounted on ${mntdir}"
fi
# Check for the media
if [ -f "${mntdir}/${recon}" ]; then
# Set REAL_ROOT, CRYPT_ROOT_KEYDEV or whatever ${vrbl} is
eval ${vrbl}'='"${x}"
good_msg "Media found on ${x}"
break
else
umount "${mntcddir}"
fi
done
fi
eval local result='$'${vrbl}
[ -n "${result}" ] || bad_msg "Media not found"
}
setup_md_device() {
if ! is_mdev; then
# mdev requires manual device node creation, while udev doesn't
# make sure that all the udev events are complete
is_udev && udevadm settle
return 0
fi
local device=
[ -n "${1}" ] && device="${1}"
[ -z "${1}" ] && device="${REAL_ROOT}"
[ -z "${device}" ] && return 0
local md_dev=$(echo ${device} | sed -e \
's#\(luks:\)\?\(/dev/md\)[[:digit:]]\+#\2#')
if [ "${md_dev}" = "/dev/md" ]; then
good_msg 'Detected root as a md device. Setting up the device node...'
local md_number=$(echo ${device} | sed -e \
's#\(luks:\)\?/dev/md\([[:digit:]]\+\)#\2#')
if [ ! -e "/dev/md${md_number}" ]; then
mknod "/dev/md${md_number}" b 9 "${md_number}" >/dev/null 2>&1
[ $? -ne 0 ] && bad_msg "Creation of /dev/md${md_number} failed..."
fi
mdstart ${MDPART} "/dev/md${md_number}"
fi
}
start_volumes() {
# Here, we check for /dev/device-mapper, and if it exists, we setup a
# a symlink, which should hopefully fix bug #142775 and bug #147015
if [ -e /dev/device-mapper ] && [ ! -e /dev/mapper/control ]; then
mkdir -p /dev/mapper
ln -sf /dev/device-mapper /dev/mapper/control
fi
if [ "${USE_MDADM}" = "1" ]; then
good_msg "Activating md raid devices"
mdadm --assemble --scan || \
bad_msg "mdadm failed to run, skipping raid assembly!"
fi
if [ "${USE_MULTIPATH_NORMAL}" = "1" ]; then
good_msg "Scanning for multipath devices"
multipath -v 0
# TODO(lxnay): horrible sleep!
sleep 2
good_msg "Activating multipath devices"
dmsetup ls --target multipath --exec "/sbin/kpartx -a -v"
fi
if [ "${USE_DMRAID_NORMAL}" = "1" ]; then
good_msg "Activating device-mapper raid devices"
dmraid -ay ${DMRAID_OPTS} || \
bad_msg "dmraid failed to run, skipping raid assembly!"
fi
if [ "${USE_LVM_NORMAL}" = "1" ]; then
for dev in ${RAID_DEVICES}; do
setup_md_device "${dev}"
done
# This is needed for /sbin/lvm to accept the following logic
local cmds="#! /sbin/lvm"
# If there is a cahe, update it. Unbreak at least dmcrypt
[ -d /etc/lvm/cache ] && cmds="${cmds} \nvgscan"
# To activate volumegroups on all devices in the cache
cmds="${cmds} \nvgchange -ay --sysinit"
if is_mdev; then
# To create symlinks so users can use
# real_root=/dev/vg/root
# This needs to run after vgchange, using
# vgchange --mknodes is too early.
cmds+="${cmds} \nvgmknodes --ignorelockingfailure"
fi
# And finally execute it all (/proc/... needed if lvm
# is compiled without readline)
good_msg "Activating Logical Volume Groups"
printf "%b\n" "${cmds}" | lvm /proc/self/fd/0 || \
bad_msg "lvm failed to run, cannot activate logical volumes!"
fi
is_udev && udevadm settle
}

@ -2,6 +2,8 @@
. /etc/initrd.d/00-common.sh . /etc/initrd.d/00-common.sh
. /etc/initrd.d/00-devmgr.sh . /etc/initrd.d/00-devmgr.sh
. /etc/initrd.d/00-fsdev.sh
. /etc/initrd.d/00-crypt.sh
_is_aufs() { _is_aufs() {
@ -268,76 +270,6 @@ _livecd_mount_copy_content() {
mount --bind "${CDROOT_PATH}" "${new_cdroot}" mount --bind "${CDROOT_PATH}" "${new_cdroot}"
} }
media_find() {
# $1 = mount dir name / media name
# $2 = recognition file
# $3 = variable to have the device path
# $4 = actual mount dir path (full path)
# args remaining are possible devices
local media="${1}" recon="${2}" vrbl="${3}" mntdir="${4}"
shift 4
good_msg "Looking for the ${media}"
if [ "$#" -gt "0" ]; then
[ ! -d "${mntdir}" ] && \
mkdir -p "${mntdir}" 2>/dev/null >/dev/null
local mntcddir="${mntdir}"
if [ -n "${ISOBOOT}" ]; then
mntcddir="${mntdir%${media}}iso"
if [ ! -f "${mntcddir}" ]; then
mkdir "${mntcddir}"
fi
fi
for x in ${*}; do
# Check for a block device to mount
if [ ! -b "${x}" ]; then
continue
fi
#
# If disk and it has at least one partition, skip.
# We use /sys/block/${bsn}/${bsn}[0-9]* to make sure that we
# don't skip device mapper devices. Even the craziest scenario
# deserves a fair chance.
#
local bsn=$(basename "${x}")
local bpath="/sys/block/${bsn}"
local parts=$(find "${bpath}/" \
-regex "${bpath}/${bsn}[0-9]" -type d 2>/dev/null)
[ -n "${parts}" ] && continue
good_msg "Attempting to mount media: ${x}"
mount -r -t "${CDROOT_TYPE}" "${x}" "${mntcddir}" >/dev/null 2>&1 \
|| continue
if [ -n "${ISOBOOT}" ] && [ -f "${mntcddir}/${ISOBOOT}" ]; then
mount -o loop "${mntcddir}/${ISOBOOT}" "${mntdir}" && \
good_msg "iso mounted on ${mntdir}"
fi
# Check for the media
if [ -f "${mntdir}/${recon}" ]; then
# Set REAL_ROOT, CRYPT_ROOT_KEYDEV or whatever ${vrbl} is
eval ${vrbl}'='"${x}"
good_msg "Media found on ${x}"
break
else
umount "${mntcddir}"
fi
done
fi
eval local result='$'${vrbl}
[ -n "${result}" ] || bad_msg "Media not found"
}
livecd_init() { livecd_init() {
good_msg "Making tmpfs for ${NEW_ROOT}" good_msg "Making tmpfs for ${NEW_ROOT}"
mount -n -t tmpfs -o mode=0755 tmpfs "${NEW_ROOT}" mount -n -t tmpfs -o mode=0755 tmpfs "${NEW_ROOT}"

@ -46,77 +46,6 @@ crypt_exec() {
fi fi
} }
start_volumes() {
# Here, we check for /dev/device-mapper, and if it exists, we setup a
# a symlink, which should hopefully fix bug #142775 and bug #147015
if [ -e /dev/device-mapper ] && [ ! -e /dev/mapper/control ]; then
mkdir -p /dev/mapper
ln -sf /dev/device-mapper /dev/mapper/control
fi
if [ "${USE_MDADM}" = "1" ]; then
if [ -e "/sbin/mdadm" ]; then
/sbin/mdadm --assemble --scan
else
bad_msg "mdadm not found: skipping mdadm raid assembly!"
fi
fi
if [ "${USE_MULTIPATH_NORMAL}" = "1" ]; then
good_msg "Scanning for multipath devices"
/sbin/multipath -v 0
# TODO(lxnay): horrible sleep!
sleep 2
good_msg "Activating multipath devices"
/sbin/dmsetup ls --target multipath --exec "/sbin/kpartx -a -v"
fi
if [ "${USE_DMRAID_NORMAL}" = "1" ]; then
if [ -e "/sbin/dmraid" ]; then
good_msg "Activating Device-Mapper RAID(s)"
/sbin/dmraid -ay ${DMRAID_OPTS}
else
bad_msg "/sbin/dmraid not found"
fi
fi
if [ "${USE_LVM_NORMAL}" = "1" ]; then
if [ -e "/sbin/lvm" ]; then
if is_mdev; then
for dev in ${RAID_DEVICES}; do
setup_md_device "${dev}"
done
fi
# This is needed for /sbin/lvm to accept the following logic
local cmds="#! /sbin/lvm"
# If there is a cahe, update it. Unbreak at least dmcrypt
[ -d /etc/lvm/cache ] && cmds="${cmds} \nvgscan"
# To activate volumegroups on all devices in the cache
cmds="${cmds} \nvgchange -ay --sysinit"
if is_mdev; then
# To create symlinks so users can use
# real_root=/dev/vg/root
# This needs to run after vgchange, using
# vgchange --mknodes is too early.
cmds+="${cmds} \nvgmknodes --ignorelockingfailure"
fi
# And finally execute it all (/proc/... needed if lvm
# is compiled without readline)
good_msg "Scanning for and activating Volume Groups"
printf "%b\n" "${cmds}" | /sbin/lvm /proc/self/fd/0
else
bad_msg "/sbin/lvm not found: skipping LVM activation"
fi
fi
is_udev && udevadm settle
}
start_iscsi() { start_iscsi() {
if [ ! -e /usr/sbin/iscsistart ]; then if [ ! -e /usr/sbin/iscsistart ]; then
return 0 # disabled return 0 # disabled
@ -362,25 +291,6 @@ start_luks() {
fi fi
} }
setup_md_device() {
local device
[ -z "$1" ] && device="${REAL_ROOT}" || device="$1"
[ -z "${device}" ] && return # LiveCD
if [ $(echo ${device}|sed -e 's#\(luks:\)\?\(/dev/md\)[[:digit:]]\+#\2#') = "/dev/md" ]
then
good_msg 'Detected real_root as a md device. Setting up the device node...'
MD_NUMBER=$(echo ${device}|sed -e 's#\(luks:\)\?/dev/md\([[:digit:]]\+\)#\2#')
if [ ! -e /dev/md${MD_NUMBER} ]
then
mknod /dev/md${MD_NUMBER} b 9 ${MD_NUMBER} >/dev/null 2>&1
[ $? -ne 0 ] && bad_msg "Creation of /dev/md${MD_NUMBER} failed..."
fi
mdstart ${MDPART} /dev/md${MD_NUMBER}
fi
}
resume_init() { resume_init() {
if [ -z "${REAL_RESUME}" ]; then if [ -z "${REAL_RESUME}" ]; then
return 0 return 0

@ -267,7 +267,7 @@ cd /
start_iscsi start_iscsi
# Setup md device nodes if they dont exist # Setup md device nodes if they dont exist
is_mdev && setup_md_device setup_md_device
start_volumes start_volumes
zfs_start_volumes zfs_start_volumes

Loading…
Cancel
Save