Added device manager multipath support for root file system
v2 cover Added device manager multipath support for root file system
This is implemented using an initramfs, built by core-image-cgl-initramfs image recipe. Multipath device configurations are done using kernel boot parameters.
Original implementation was done by: Mats Liljegren <[email protected]>
Changes from v1:
Split patch into 3 smaller patches
Dropped core-image inheritance, it's already inherited by core-image-lsb Dropped the conf_setup script as its not needed anymore - the multipath-tools recipe from meta-virtualization has been dropped.
Adrian Dudau (3):
packagegroup-cgl-middleware: Add multipath-tools Add an initramfs image
Add initrdscripts
meta-cgl-common/conf/distro/poky-cgl.conf | 1 + meta-cgl-common/images/core-image-cgl-initramfs.bb | 20 +++ meta-cgl-common/images/core-image-cgl.bb | 2 + .../packagegroups/packagegroup-cgl-middleware.bb | 8 +- .../recipes-core/initrdscripts/files/init-boot.sh | 179 +++++++++++++++++++++ .../initrdscripts/initramfs-cgl-boot_1.0.bb | 14 ++ 6 files changed, 217 insertions(+), 7 deletions(-) create mode 100644 meta-cgl-common/images/core-image-cgl-initramfs.bb create mode 100644 meta-cgl-common/recipes-core/initrdscripts/files/init-boot.sh create mode 100644 meta-cgl-common/recipes-core/initrdscripts/initramfs-cgl-boot_1.0.bb
Signature · 1 line
1.9.1
PATCH v2 1/3 packagegroup-cgl-middleware: Add multipath-tools
Remove the other multipath related packages which are not necessary.
CGL requirements AVL.7.1.*
--- meta-cgl-common/packagegroups/packagegroup-cgl-middleware.bb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
meta-cgl-common/packagegroups/packagegroup-cgl-middleware.bb +1 -7
@@ -18,14 +18,8 @@ DHCP = " \ " MULTIPATH_TOOLS = " \ - libmpathpersist \ - mpathpersist \ + multipath-tools \ kpartx \ - libmultipath \ - multipath \ - multipathd \ - libmultipath-dev \ - libmpathpersist-dev \ " RDEPENDS_packagegroup-cgl-middleware = "\
Signature · 1 line
1.9.1
PATCH v2 2/3 Add an initramfs image
In reply to Adrian DudauThis is needed to enable multipath support for the rootfs. The ext3 support is needed to load the image onto the disk.
CGL requirements AVL.7.1.*
--- meta-cgl-common/conf/distro/poky-cgl.conf | 1 + meta-cgl-common/images/core-image-cgl-initramfs.bb | 20 ++++++++++++++++++++ meta-cgl-common/images/core-image-cgl.bb | 2 ++ 3 files changed, 23 insertions(+) create mode 100644 meta-cgl-common/images/core-image-cgl-initramfs.bb
meta-cgl-common/conf/distro/poky-cgl.conf +1 -0
@@ -3,4 +3,5 @@ require conf/distro/poky-selinux.conf DISTRO = "poky-cgl" +IMAGE_CLASSES += "image_types_uboot" PREFERRED_PROVIDER_virtual/refpolicy="refpolicy-targeted"
meta-cgl-common/images/core-image-cgl-initramfs.bb new file +20 -0
@@ -0,0 +1,20 @@ +require core-image-cgl.bb + +# Recipe is based on core-image-minimal.bb +DESCRIPTION = "Initramfs used to mount multipath device as root file system" + +PACKAGE_INSTALL = "initramfs-cgl-boot busybox base-passwd udev ${ROOTFS_BOOTSTRAP_INSTALL}" + +# Do not pollute the initrd image with rootfs features +IMAGE_FEATURES = "" + +export IMAGE_BASENAME = "core-image-cgl-initramfs" +IMAGE_LINGUAS = "" + +LICENSE = "MIT" + +IMAGE_FSTYPES = "cpio.gz.u-boot" + +IMAGE_ROOTFS_SIZE = "8192" + +BAD_RECOMMENDATIONS += "busybox-syslog"
meta-cgl-common/images/core-image-cgl.bb +2 -0
@@ -21,6 +21,8 @@ IMAGE_INSTALL += "\ kernel-modules \ " +IMAGE_FSTYPES += " ext3.gz" + # kexec-tools doesn't work on Mips KEXECTOOLS_mips ?= "" KEXECTOOLS_mipsel ?= ""
Signature · 1 line
1.9.1
PATCH v2 3/3 Add initrdscripts
In reply to Adrian DudauThese scripts are used to load the rootfs onto multipath devices.
Scripts originally developed by: Mats Liljegren <[email protected]>
CGL requirements AVL.7.1.*
--- .../recipes-core/initrdscripts/files/init-boot.sh | 179 +++++++++++++++++++++ .../initrdscripts/initramfs-cgl-boot_1.0.bb | 14 ++ 2 files changed, 193 insertions(+) create mode 100644 meta-cgl-common/recipes-core/initrdscripts/files/init-boot.sh create mode 100644 meta-cgl-common/recipes-core/initrdscripts/initramfs-cgl-boot_1.0.bb
meta-cgl-common/recipes-core/initrdscripts/files/init-boot.sh new file +179 -0
@@ -0,0 +1,179 @@ +#!/bin/sh -eu + +# Fail function, either called explicitly or when shell will quit +fail () { + # Avoid recursive traps + trap '' ERR EXIT + + # If message provided, print it + [ -n '${1:-}' ] && echo $@ + + # Generic error message and shell access + echo "Error occured, giving a shell" + exec sh +} + +trap fail ERR EXIT + +interrupt () { + echo "User interrupt received, giving a shell. When exiting shell, execution will continue." + sh +} + +trap interrupt INT + +# Find session ID for an iSCSI disk given its IQN name +iqn_to_sid () { + iscsiadm -m session | fgrep $1 | sed -r 's/.*\[([0-9])\].*/\1/' +} + +# Find device name, without path, for an iSCSI disk given its IQN name +iqn_to_dev () { + iscsiadm -m session -r $(iqn_to_sid $1) -P3 | sed -rn 's/.*Attached scsi disk ([a-zA-Z0-9_]+).*/\1/p' +} + +# Parse input parameters expecting name=value pairs. +# Name only matches known parameters. +# On match, set variable <name> to value <value>. +# E.g. given "parse_cmdline trythis="ok, do it" +# the shell variable "trythis" will now have the value "ok, do it". +parse_cmdline () { + iscsi_chap_user="" + iscsi_chap_pwd="" + iscsi_dev="" + iscsi_debug=0 + + while [ -n "${1:-}" ]; do + name="${1%%=*}" + val="${1#*=}" + case $name in + iscsi_chap_user|iscsi_chap_pw) + eval $name=\"$val\";; + iscsi_dev) + eval $name=\"$iscsi_dev $val\" + ;; + iscsi_debug) + set -x + iscsi_debug=1 + ;; + esac + shift + done + + [ -n "${iscsi_dev}" ] || fail "Mandatory kernel boot parameter 'iscsi_dev' not given." + +} + +PATH=/sbin:/bin:/usr/sbin:/usr/bin + +echo "Mounting /proc" +mount -t proc proc /proc + +KERNEL_CMDLINE="$(cat /proc/cmdline)" + +echo "Parsing kernel parameters" +parse_cmdline $KERNEL_CMDLINE + +echo "Mounting /sys" +mount -t sysfs sysfs /sys + +# udev is needed for multipath +echo "Starting udev" +/etc/init.d/udev start + +# Add CHAP autenthication, if given as kernel boot parameters +echo "Configuring iSCSI" +[ -n "$iscsi_chap_user" -o -n "$iscsi_chap_pw" ] && cat <<EOF >> /etc/iscsi/iscsid.conf +node.session.auth.authmethod = CHAP +EOF +[ -n "$iscsi_chap_user" ] && cat <<EOF >> /etc/iscsi/iscsid.conf +node.session.auth.username = $iscsi_chap_user +EOF +[ -n "$iscsi_chap_pw" ] && cat <<EOF >> /etc/iscsi/iscsid.conf +node.session.auth.password = $iscsi_chap_pw +EOF + +echo >> /etc/iscsi/iscsid.conf + +echo "Starting iSCSI daemon" +/etc/init.d/iscsid restart + +echo "Discovering iSCSI devices" + +for dev in $iscsi_dev; do + target_ip="${dev%%:*}" + dev_name="${dev#*:}" + echo "Logging in to iscsi devices: $dev_name, target: $target_ip" + iscsiadm --mode discoverydb --type sendtargets --discover --portal $target_ip + iscsiadm --mode node --targetname $dev_name --login --portal $target_ip +done + +echo "Configuring multipath" +cat <<EOF > /etc/multipath.conf +defaults { + path_grouping_policy multibus + # If no path, then queue requests + no_path_retry queue +} +devices { + device { + vendor IET + product VIRTUAL-DISK + path_grouping_policy multibus + } +} +blacklist { + devnode ".*" +} +blacklist_exceptions { +$(for dev in $iscsi_dev; do + echo " devnode \"^$(iqn_to_dev ${dev#*:})\"" + done) + property ".*" +} +EOF + +echo "Starting multipath daemon" +# Make sure lock file directory exists +mkdir -p /var/lock/subsys/multipathd +/etc/init.d/multipathd start + +mpath_template='/dev/disk/by-id/dm-uuid-mpath-*' + +echo "Waiting for mpath device to appear" +while [ -z "$(ls $mpath_template 2>/dev/null)" ]; do + sleep 1 +done +MPATH_DEV="$(ls $mpath_template)" +echo "mpath device: $MPATH_DEV" + +echo "Mounting mpath device $MPATH_DEV" +mount $MPATH_DEV /mnt + +echo "Stopping multipath daemon" +# Should be using "/etc/init.d/multipathd stop", but did not work. +# Got "killall: /sbin/multipathd: no process killed". +# Kill the process based on the saved pid. +kill $(cat /run/multipathd.pid) + +echo "Moving iscsi pid and lock files" +cp /run/iscsid.pid /mnt/run/iscsid.pid +cp /run/lock/iscsi/* /mnt/run/lock/iscsi + +# In case iscsi_debug is given, open a shell at this point +if [ $iscsi_debug -eq 1 ]; then + echo "iscsi_debug given, opening a shell. When exiting shell, boot will continue." + sh +fi + +# udev needs to be restart when real init runs, so stop it +echo "Stopping udev" +/etc/init.d/udev stop + +echo "Moving sys, proc and dev mounts to new root" +mount --move /sys /mnt/sys +mount --move /proc /mnt/proc +mount --move /dev /mnt/dev + +echo "Switching to new root" +exec switch_root /mnt /sbin/init $KERNEL_CMDLINE
meta-cgl-common/recipes-core/initrdscripts/initramfs-cgl-boot_1.0.bb new file +14 -0
@@ -0,0 +1,14 @@ +SUMMARY = "Support for having multipath iSCSI devices as root file system" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COREBASE}/meta-cgl/COPYING.MIT;md5=838c366f69b72c5df05c96dff79b35f2" +SRC_URI = "file://init-boot.sh" + +do_install() { + install -m 0755 ${WORKDIR}/init-boot.sh ${D}/init +} + +inherit allarch + +RDEPENDS_${PN} += "multipath-tools kpartx iscsi-initiator-utils" + +FILES_${PN} += " /init "
Signature · 1 line
1.9.1