#!/bin/sh # Scan for, fsck, and mount SAN-based mountpoints with and without LVM # This script makes several assumptions, if your not careful bad things may happen # (what exactly I'm not sure, I haven't tested outside these bounds): # # Assumptions: # * There is only 1 partition on each SAN volume (partition #1) # * All SAN-based volume groups have the word 'iscsi/fc/san' somewhere in their name # * All multipathed physical devices have a device-mapper name that starts with 2 numbers # * Our 3PAR array presents volumes as "350002[..]" # * Our Openfiler presents volumes as "14f70656e66696[..]" # * All filesystems to be mounted are in /etc/fstab and are ext3, with the 'noauto' option # * Nothing is using the mountpoints when 'stop' is issued (to unmount the volumes) # * If your activating a brand new iSCSI volume, and you create a partition on it, either # create one on the first disk of the group(multipath -l) for the volume, or restart # the iSCSI subsystem afterwards, else the physical /dev/ device won't get e2fsck'd # because the /dev/ device doesn't exist. Not a big deal just an example: # * New volume created, multipath -l lists sde sdf sdg sdh as the scsi devices # * You create a partition on /dev/sdg # * System auto creates /dev/sdg1 device # * Despite the partition existing on the other disks sde sdf sdh the system isn't # aware of this yet since it happened transparently so /dev/sde1 does not get # created. This script goes to scan /dev/sde1 (it only attempts to scan the first # disk), does not find the device and fails. This does not appear to impact # the ability to mount the disk. case $1 in start) echo "Scanning and activating SAN-based volume groups" pvscan 2>&1 | grep -v "Incorrect metadata" vgimport -a 2>&1 | grep -v "Incorrect metadata" for i in `lvdisplay -c 2>&1 | grep -v "Incorrect metadata" | grep '\(iscsi-\|san-\|fiber-\|fc-\)' | awk -F : '{print $1}'`; do lvchange -ay $i 2>&1 | grep -v "Incorrect metadata"; done echo "Checking LVM SAN filesystems.." for i in `lvdisplay -c 2>&1 | grep '\(iscsi-\|san-\|fiber-\|fc-\)' | awk -F : '{print $1}' | grep -v "Incorrect metadata"`; do e2fsck -y $i; done echo "Finished checking LVM SAN filesystems.." echo -n "Scanning and mounting multipathed filesystems..." for i in `cat /etc/fstab | egrep "^/dev.*ext3.*noauto" | awk '{print $2}'`; do echo -n "..[${i}].."; mkdir -p $i mount $i; done # this is critical otherwise the OS will not unmount the filesystems # on shutdown and the system may/will hang! touch /var/lock/subsys/mount_san echo "done!" grep -q "cssd run" /etc/inittab RETURN=$? if [ "$RETURN" == 0 ]; then echo -n "Enabling Oracle CSS after mounting volumes." perl -pi -e s'/^#h1(.*)cssd run(.*)/h1${1}cssd run${2}/'g /etc/inittab /sbin/telinit q echo "..done!" fi ;; stop) grep -q "cssd run" /etc/inittab RETURN=$? if [ "$RETURN" == 0 ]; then echo -n "Disabling Oracle CSS before unmounting volumes." perl -pi -e s'/^h1(.*)cssd run(.*)/#h1${1}cssd run${2}/'g /etc/inittab /sbin/telinit q echo "..done!" fi echo -n "Scanning and un-mounting multipathed filesystems..." for i in `cat /etc/fstab | egrep "^/dev.*ext3.*noauto" | awk '{print $2}'`; do echo -n "..[${i}].."; umount $i; done echo "done!" # This assumes the volumes are no longer in use, if they are not it will # fail echo "Scanning and exporting SAN based volume groups.." for i in `lvdisplay -c 2>&1 | grep -v "is exported" | grep -v "Incorrect metadata" | grep '\(iscsi-\|san-\|fiber-\|fc-\)' | awk -F : '{print $1}'`; do lvchange -an $i 2>&1 | grep -v "Incorrect metadata"; done for i in `vgdisplay -c 2>&1 | grep -v "is exported" | grep -v "Incorrect metadata" | grep '\(iscsi-\|san-\|fiber-\|fc-\)' | awk -F : '{print $1}'`; do vgexport $i 2>&1 | grep -v "Incorrect metadata"; done # this isn't as critical, but doesn't hurt. rm -f /var/lock/subsys/mount_san ;; *) echo "Usage: $0 [ start | stop ]" ;; esac exit