#!/bin/ksh ############################################################# # # Module: mirror_stripe.ksh # # Date: 7 September, 1999 # # Purpose: # This script is used to stripe and mirror # disks using HP-UX LVM. HP-LVM does not # natively support mirrored stripes, # it either stripes or mirrors, but not both. # ############################################################# # # Can only run as root # if [[ "${LOGNAME}" != "root" ]]; then echo "Must be run as root" exit fi # # Usage # if [[ "${1}" = "" ]];then echo "Usage: $0 " exit; else configfilename=$1 fi ###################################### # # Call the configuration section. # ###################################### . ${configfilename} ###################################### # # Processing Section # ###################################### # # Calculate the next available volume group id. # { cat << XXX ibase=16 obase=10 XXX } > /tmp/maxvgid ll /dev/*/group | awk '{printf("%s+010000\n", toupper(substr($6, 3)))}' | sort | tail -1 >> /tmp/maxvgid tmpvgid=`bc < /tmp/maxvgid` vgid=`printf "0x%06s\n" $tmpvgid` rm /tmp/maxvgid # # Create Physical Volumes on the disk # # Check if the Volume Group already exists echo "Creating volume group ${vgname}" if [[ ! -a /dev/${vgname} ]] ; then mkdir /dev/${vgname} mknod /dev/${vgname}/group c 64 ${vgid} echo "Created volume group ${vgname}" else # Check to be sure the group file exists # for the vgname directory. if [[ ! -c /dev/${vgname}/group ]] ; then mknod /dev/${vgname}/group c 64 ${vgid} echo "Created volume group ${vgname}" else echo "Volume group ${vgname} already exists" fi fi # # Create the primary volume group # echo "Adding disks to volume group ${vgname}" let i=0 while [[ $i -lt $num_primary_disks ]]; do pvcreate -f /dev/rdsk/${primary_disk[$i]} vgextend -g primary /dev/${vgname} /dev/dsk/${primary_disk[$i]} let i=$i+1 done # # Create the mirror volume group # let i=0 while [[ $i -lt $num_stripe_disks ]]; do pvcreate -f /dev/rdsk/${mirror_disk[$i]} vgextend -g mirror /dev/${vgname} /dev/dsk/${mirror_disk[$i]} let i=$i+1 done echo "Finished adding disks to volume group ${vgname}" # # Create the logical volumes # # # Loop through each logical volume. # let i=0 echo "Creating ${num_logical_volumes} logical volumes" while [[ $i -lt $num_logical_volumes ]]; do ########################################### # # If the version does not support # "distributed" mirrors, then use # the brute-force striping+mirroring, # otherwise use the lvcreate options # that allow HP Mirror-UX to do the # dirty work for you. # # HP-UX versions from B.10.20 forward # support the distributed flag for # lvcreate. # ########################################### if [[ `uname -r` < "B.10.20" ]]; then echo "Version="`uname -r` " using lvextend method -- this could take a while" # # Use the brute-force lvextend stripe/mirror method # lvcreate -n $1 -s g /dev/${vgname} # # Calculate the starting stripe # and the current logical volume size. # if [[ -a /dev/${vgname}/${lv_name[$i]} ]]; then let ii=`/etc/lvdisplay /dev/${vgname}/${lv_name[$i]} | grep "LV Size" | awk '{print $4}'` # This will re-start at the appropriate stripe let jj=$ii%$num_stripe_disks let jj=$jj+${lv_start_stripe[$i]} let jj=$jj%$num_stripe_disks else let ii=0 let jj=${lv_start_stripe[$i]} fi # # Loop until all extents are added. # while [[ $ii -lt ${lv_size[$i]} ]]; do lvextend -L $ii /dev/${vgname}/$lv_name[$i] /dev/dsk/${primary_disk[$jj]} lvextend -m 1 /dev/${vgname}/$lv_name[$i] /dev/dsk/${mirror_disk[$jj]} # Increment the lvsize. let ii=$ii+1; # Calculate the next stripe. let jj=$jj+1; let jj=$jj%$num_stripe_disks done else # # Use the Mirror-UX distributed flag for lvcreate # echo "Version="`uname -r` " using lvcreate with -D" lvcreate -n $1 -m 1 -s g -D y -L ${lv_size[$i]} /dev/${vgname} let ii=${lv_size[$i]} fi echo "Created logical volume ${lv_name[$i]} - ${ii} MB" let i=$i+1 done echo "Finished creating ${i} logical volumes"