[673] | 1 | #!/bin/bash
|
---|
[275] | 2 | #
|
---|
| 3 | # $Id: analyze-my-lvm 3639 2016-12-21 19:09:47Z bruno $
|
---|
| 4 | #
|
---|
[1] | 5 |
|
---|
| 6 | Die() {
|
---|
[298] | 7 | echo "$1" >> /dev/stderr
|
---|
[963] | 8 | exit -1
|
---|
[1] | 9 | }
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | GetValueFromField() {
|
---|
[298] | 14 | local res
|
---|
[3275] | 15 | grep -i "$2" "$1" | perl -p -e 's/\s*(.*)\s\s\s+(.+)$/$2/;s/\sT[i]*B/t/;s/\sG[i]*B/g/;s/\sM[i]*B/m/;s/\sK[i]*B/k/'
|
---|
[1] | 16 | }
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | GetLastBit() {
|
---|
[298] | 20 | local i res
|
---|
| 21 | i=20
|
---|
| 22 | res=""
|
---|
| 23 | while [ ! "$res" ] ; do
|
---|
| 24 | i=$(($i-1))
|
---|
| 25 | res=`echo "$1" | cut -d'/' -f$i`
|
---|
| 26 | done
|
---|
| 27 | echo "$res"
|
---|
[1] | 28 | }
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | ProcessLogicalVolume() {
|
---|
[298] | 32 | local LV_full_string fname logical_volume volume_group device
|
---|
| 33 | LV_full_string=$1
|
---|
[2244] | 34 | if [ ! -e "$1" ]; then
|
---|
| 35 | echo "WARNING - cannot find LV file $1" | tee -a /dev/stderr
|
---|
| 36 | return
|
---|
| 37 | fi
|
---|
[298] | 38 | volume_group=`echo "$LV_full_string" | cut -d'/' -f3`
|
---|
| 39 | logical_volume=`echo "$LV_full_string" | cut -d'/' -f4`
|
---|
| 40 | if [ $lvmversion = 2 ]; then
|
---|
| 41 | device=$LV_full_string
|
---|
| 42 | params=`GenerateLvcreateParameters $device`
|
---|
[1] | 43 | else
|
---|
[298] | 44 | fname=/proc/lvm/VGs/$volume_group/LVs/$logical_volume
|
---|
| 45 | if [ ! -e "$fname" ] ; then
|
---|
[2244] | 46 | echo "WARNING - cannot find $volume_group's $logical_volume LV file" | tee -a /dev/stderr
|
---|
| 47 | return
|
---|
[298] | 48 | else
|
---|
| 49 | device=`GetValueFromField $fname "name:"`
|
---|
| 50 | params=`GenerateLvcreateParameters $device`
|
---|
| 51 | fi
|
---|
[1] | 52 | fi
|
---|
[2566] | 53 |
|
---|
| 54 | # Exclude LVs member of that env var
|
---|
| 55 | if [ "$MINDI_EXCLUDE_DEVS" ] ; then
|
---|
[2995] | 56 | list_of_devices="`mindi --nolog --readalllink $LV_full_string 2> /dev/null`"
|
---|
[2567] | 57 | l=""
|
---|
| 58 | for d in $list_of_devices; do
|
---|
| 59 | l="$l `GiveMapperOfdm $d`"
|
---|
| 60 | done
|
---|
| 61 | list_of_devices="`echo $l | sort -u`"
|
---|
[2852] | 62 | for ed in `echo $MINDI_EXCLUDE_DEVS | sed 's/|/ /g'`; do
|
---|
[2566] | 63 | if [ "`echo " $list_of_devices" | grep " $ed"`" != "" ]; then
|
---|
| 64 | echo "Not including device $LV_full_string as it was excluded"
|
---|
| 65 | return
|
---|
| 66 | fi
|
---|
| 67 | done
|
---|
| 68 | fi
|
---|
[2534] | 69 | # Do not process LV whose VG are excluded
|
---|
[2537] | 70 | if [ -f $MINDI_TMP/excludedvgs ]; then
|
---|
[2684] | 71 | if [ "`grep -x $volume_group $MINDI_TMP/excludedvgs`" != "" ]; then
|
---|
[2565] | 72 | echo "Not including LV $logical_volume as VG $volume_group was excluded"
|
---|
[2566] | 73 | return
|
---|
[2537] | 74 | fi
|
---|
[2534] | 75 | fi
|
---|
[2566] | 76 |
|
---|
[3312] | 77 | echo "# echo y | $LVMCMD lvcreate$params -n $logical_volume $volume_group"
|
---|
[1] | 78 | }
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | GenerateLvcreateParameters() {
|
---|
[298] | 82 | local device stripes stripesize device fname allocation output readahead
|
---|
[1487] | 83 | fname=$MINDI_TMP/PLF.$$.txt
|
---|
[3432] | 84 | fname2=$MINDI_TMP/PLF2.$$.txt
|
---|
[298] | 85 | device=$1
|
---|
| 86 | output=""
|
---|
[3016] | 87 | $LVMCMD lvdisplay $device | cat > $fname
|
---|
[298] | 88 | stripes=`GetValueFromField $fname "Stripes"`
|
---|
| 89 | stripesize=`GetValueFromField $fname "Stripe size (MByte)"`m
|
---|
| 90 | [ "$stripesize" = "m" ] && stripesize=`GetValueFromField $fname "Stripe size (KByte)"`k
|
---|
| 91 | [ "$stripesize" = "k" ] && stripesize=""
|
---|
[3432] | 92 | currentLE=`GetValueFromField $fname "Current LE"`
|
---|
| 93 | vgname=`GetValueFromField $fname "VG Name"`
|
---|
| 94 | $LVMCMD vgdisplay $vgname | cat > $fname2
|
---|
| 95 | totalLE=`GetValueFromField $fname2 "Total PE"`
|
---|
[3559] | 96 | ratio=`perl -e '$per='$currentLE'*100/'$totalLE' ; print int($per)'`
|
---|
| 97 | if [ $ratio -eq 0 ]; then
|
---|
| 98 | # In that case, restoration will fail with 0% so use value
|
---|
| 99 | output="$output -l $currentLE"
|
---|
| 100 | else
|
---|
| 101 | allocation=`perl -e 'print int('$ratio')."%VG"'`
|
---|
| 102 | output="$output -l $allocation"
|
---|
| 103 | fi
|
---|
[298] | 104 | readahead=`GetValueFromField $fname "Read ahead sectors"`
|
---|
[3432] | 105 | rm -f $fname $fname2
|
---|
[298] | 106 | [ "$stripes" ] && output="$output -i $stripes"
|
---|
| 107 | [ "$stripesize" ] && output="$output -I $stripesize"
|
---|
| 108 | [ "$readahead" ] && output="$output -r $readahead"
|
---|
| 109 | echo "$output"
|
---|
[1] | 110 | }
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | GenerateVgcreateParameters() {
|
---|
[298] | 115 | local current_VG device fname incoming VG_info_file max_logical_volumes max_physical_volumes physical_extent_size output blanklines
|
---|
| 116 | current_VG=$1
|
---|
[1487] | 117 | VG_info_file=$MINDI_TMP/$$.vg-info.txt
|
---|
[2342] | 118 | # We use cat here as a way to avoid SElinux to prevent us from writing in $VG_info_file
|
---|
| 119 | $LVMCMD vgdisplay $current_VG | cat > $VG_info_file
|
---|
[298] | 120 | max_logical_volumes=`GetValueFromField "$VG_info_file" "MAX LV"`
|
---|
| 121 | [ $max_logical_volumes -ge 256 ] && max_logical_volumes=255
|
---|
| 122 | max_physical_volumes=`GetValueFromField "$VG_info_file" "MAX PV"`
|
---|
| 123 | [ $max_physical_volumes -ge 256 ] && max_physical_volumes=255
|
---|
| 124 | physical_extent_size=`GetValueFromField "$VG_info_file" "PE Size"`
|
---|
| 125 | output=""
|
---|
| 126 | [ "$max_logical_volumes" ] && output="$output -l $max_logical_volumes"
|
---|
| 127 | [ "$max_physical_volumes" ] && output="$output -p $max_physical_volumes"
|
---|
| 128 | [ "$physical_extent_size" ] && output="$output -s $physical_extent_size"
|
---|
| 129 | echo "$output"
|
---|
| 130 | rm -f $VG_info_file
|
---|
[1] | 131 | }
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | ProcessVolumeGroup() {
|
---|
[298] | 136 | local current_VG physical_volumes i list_of_devices VG_params
|
---|
| 137 | current_VG=$1
|
---|
| 138 | if [ $lvmversion = 2 ]; then
|
---|
| 139 | VG_params=`GenerateVgcreateParameters $current_VG`
|
---|
[2702] | 140 | current_PVs=`$LVMCMD pvscan | grep " $current_VG " | awk '{print $2}' | tr '\n' ' '`
|
---|
[2571] | 141 | list_of_devices=$current_PVs
|
---|
[298] | 142 | else
|
---|
| 143 | info_file=/proc/lvm/VGs/$current_VG/group
|
---|
| 144 | physical_volumes=`ls /proc/lvm/VGs/$current_VG/PVs`
|
---|
| 145 | VG_params=`GenerateVgcreateParameters $current_VG`
|
---|
| 146 | list_of_devices=""
|
---|
| 147 | for i in $physical_volumes ; do
|
---|
[2700] | 148 | fname=/proc/lvm/VGs/$current_VG/PVs/$i
|
---|
| 149 | device=`GetValueFromField $fname "name:"`
|
---|
| 150 | list_of_devices="$list_of_devices $device"
|
---|
[298] | 151 | done
|
---|
[2571] | 152 | current_PVs=$list_of_devices
|
---|
[298] | 153 | fi
|
---|
[2072] | 154 | l=""
|
---|
| 155 | if [ -f /etc/multipath.conf ]; then
|
---|
[2567] | 156 | # If multipath check which type of devide are given, mpath prefered
|
---|
[2072] | 157 | for d in $list_of_devices; do
|
---|
[2995] | 158 | l="$l `mindi --nolog --readalllink $d 2> /dev/null`"
|
---|
[2072] | 159 | l="$l `GiveMapperOfdm $d`"
|
---|
| 160 | done
|
---|
[2567] | 161 | list_of_devices="`echo $l | sort -u`"
|
---|
[2072] | 162 | fi
|
---|
| 163 |
|
---|
[2564] | 164 | if [ "$MINDI_EXCLUDE_DEVS" ] ; then
|
---|
[2852] | 165 | for ed in `echo $MINDI_EXCLUDE_DEVS | sed 's/|/ /g'`; do
|
---|
[2532] | 166 | if [ "`echo " $list_of_devices" | grep " $ed"`" != "" ]; then
|
---|
[2534] | 167 | echo $current_VG >> $MINDI_TMP/excludedvgs
|
---|
[2532] | 168 | return
|
---|
| 169 | fi
|
---|
| 170 | done
|
---|
| 171 | fi
|
---|
[2571] | 172 | echo "# $LVMCMD vgcreate $current_VG$VG_params $current_PVs"
|
---|
[298] | 173 | echo "# $LVMCMD vgchange -a y $current_VG"
|
---|
[1] | 174 | }
|
---|
| 175 |
|
---|
| 176 |
|
---|
| 177 |
|
---|
| 178 | ListAllPhysicalVolumes() {
|
---|
[298] | 179 | if [ $lvmversion = 2 ]; then
|
---|
[2620] | 180 | $LVMCMD pvscan 2> /dev/null | grep 'PV' | grep -v unknown | awk '{print $2}' > $MINDI_TMP/pv.tmp
|
---|
[298] | 181 | else
|
---|
[2072] | 182 | pvscan 2> /dev/null | grep '"' | cut -d'"' -f2 > $MINDI_TMP/pv.tmp
|
---|
[298] | 183 | fi
|
---|
[2532] | 184 |
|
---|
| 185 | rm -f $MINDI_TMP/pv.tmp2
|
---|
| 186 | for d in `cat $MINDI_TMP/pv.tmp`; do
|
---|
| 187 | # Skip devices excluded, coming from mondoarchive
|
---|
| 188 | skip=0
|
---|
[2616] | 189 | l=""
|
---|
[2995] | 190 | l="$l `mindi --nolog --readalllink $d 2> /dev/null`"
|
---|
[2567] | 191 | l="$l `GiveMapperOfdm $d`"
|
---|
| 192 | list_of_devices="`echo $l | sort -u`"
|
---|
[2564] | 193 | if [ "$MINDI_EXCLUDE_DEVS" ] ; then
|
---|
[2852] | 194 | for ed in `echo $MINDI_EXCLUDE_DEVS | sed 's/|/ /g'`; do
|
---|
[2567] | 195 | if [ "`echo " $list_of_devices " | grep " $ed"`" != "" ]; then
|
---|
[2532] | 196 | skip=1
|
---|
| 197 | continue
|
---|
| 198 | fi
|
---|
| 199 | done
|
---|
| 200 | fi
|
---|
| 201 | if [ $skip -eq 1 ]; then
|
---|
| 202 | continue
|
---|
| 203 | fi
|
---|
| 204 | echo $d >> $MINDI_TMP/pv.tmp2
|
---|
| 205 | done
|
---|
| 206 |
|
---|
[2072] | 207 | if [ -f /etc/multipath.conf ]; then
|
---|
[2567] | 208 | # If multipath check which type of devide are given, mpath prefered
|
---|
[2554] | 209 | if [ -f $MINDI_TMP/pv.tmp2 ]; then
|
---|
[2567] | 210 | l=""
|
---|
[2554] | 211 | for d in `cat $MINDI_TMP/pv.tmp2`; do
|
---|
| 212 | skip=0
|
---|
[2995] | 213 | l="$l `mindi --nolog --readalllink $d 2> /dev/null`"
|
---|
[2567] | 214 | l="$l `GiveMapperOfdm $d`"
|
---|
| 215 | list_of_devices="`echo $l | sort -u`"
|
---|
[2564] | 216 | if [ "$MINDI_EXCLUDE_DEVS" ] ; then
|
---|
[2852] | 217 | for ed in `echo $MINDI_EXCLUDE_DEVS | sed 's/|/ /g'`; do
|
---|
[2567] | 218 | if [ "`echo " $list_of_devices " | grep " $ed"`" != "" ]; then
|
---|
[2554] | 219 | skip=1
|
---|
| 220 | continue
|
---|
| 221 | fi
|
---|
| 222 | done
|
---|
| 223 | fi
|
---|
| 224 | if [ $skip -eq 1 ]; then
|
---|
| 225 | continue
|
---|
| 226 | fi
|
---|
| 227 | GiveMapperOfdm $d
|
---|
| 228 | done
|
---|
| 229 | fi
|
---|
[2072] | 230 | else
|
---|
[2554] | 231 | if [ -f $MINDI_TMP/pv.tmp2 ]; then
|
---|
| 232 | cat $MINDI_TMP/pv.tmp2
|
---|
| 233 | fi
|
---|
[2072] | 234 | fi
|
---|
[2532] | 235 | rm -f $MINDI_TMP/pv.tmp $MINDI_TMP/pv.tmp2
|
---|
[1] | 236 | }
|
---|
| 237 |
|
---|
| 238 |
|
---|
| 239 | ListAllVolumeGroups() {
|
---|
[298] | 240 | $LVMCMD vgdisplay 2> /dev/null | awk '/^ *VG Name/ {print $3;}'
|
---|
[1] | 241 | }
|
---|
| 242 |
|
---|
[2072] | 243 | GiveMapperOfdm () {
|
---|
[1] | 244 |
|
---|
[3001] | 245 | major=`stat -L -c "%t" $1 2> /dev/null`
|
---|
| 246 | minor=`stat -L -c "%T" $1 2> /dev/null`
|
---|
[2072] | 247 |
|
---|
| 248 | for i in `ls /dev/mapper/*`; do
|
---|
[3001] | 249 | mj=`stat -L -c "%t" $i`
|
---|
| 250 | mn=`stat -L -c "%T" $i`
|
---|
[2072] | 251 | if [ "$mj" = "$major" ] && [ "$mn" = "$minor" ]; then
|
---|
| 252 | echo "$i"
|
---|
| 253 | return
|
---|
| 254 | fi
|
---|
| 255 | done
|
---|
| 256 | echo $1
|
---|
| 257 | }
|
---|
| 258 |
|
---|
[3066] | 259 | GiveVGLVOfdm () {
|
---|
[2072] | 260 |
|
---|
[3066] | 261 | major=`stat -L -c "%t" $1 2> /dev/null`
|
---|
| 262 | minor=`stat -L -c "%T" $1 2> /dev/null`
|
---|
| 263 |
|
---|
| 264 | for v in `vgs --noheadings | awk '{print $1}'`; do
|
---|
| 265 | for i in `ls /dev/$v/*`; do
|
---|
| 266 | mj=`stat -L -c "%t" $i`
|
---|
| 267 | mn=`stat -L -c "%T" $i`
|
---|
| 268 | if [ "$mj" = "$major" ] && [ "$mn" = "$minor" ]; then
|
---|
| 269 | echo "$i"
|
---|
| 270 | return
|
---|
| 271 | fi
|
---|
| 272 | done
|
---|
| 273 | done
|
---|
| 274 | echo $1
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 |
|
---|
[1] | 278 | ListLvmDrivesAndPartitions() {
|
---|
[2531] | 279 | # We get partitions in this loop not devices
|
---|
[2424] | 280 | for d in `$LVMCMD vgdisplay -v 2> /dev/null | grep "PV Name" | sed 's/(#)//' | awk '{print $3}'`; do
|
---|
[2526] | 281 | # If multipath check which type of devices are given, mpath prefered
|
---|
[2424] | 282 | if [ -f /etc/multipath.conf ]; then
|
---|
[2526] | 283 | i=`GiveMapperOfdm $d`
|
---|
[2536] | 284 | rep=$i
|
---|
[2424] | 285 | else
|
---|
[2536] | 286 | rep=$d
|
---|
[2424] | 287 | fi
|
---|
[2536] | 288 | skip=0
|
---|
[2564] | 289 | if [ "$MINDI_EXCLUDE_DEVS" ] ; then
|
---|
[2852] | 290 | for ed in `echo $MINDI_EXCLUDE_DEVS | sed 's/|/ /g'`; do
|
---|
[2536] | 291 | if [ "`echo " $rep " | grep " $ed"`" != "" ]; then
|
---|
| 292 | skip=1
|
---|
| 293 | continue
|
---|
| 294 | fi
|
---|
| 295 | done
|
---|
| 296 | fi
|
---|
| 297 | if [ $skip -eq 1 ]; then
|
---|
| 298 | continue
|
---|
| 299 | fi
|
---|
| 300 | echo $rep
|
---|
[2424] | 301 | done
|
---|
[1] | 302 | }
|
---|
| 303 |
|
---|
| 304 |
|
---|
| 305 |
|
---|
| 306 | PrettifyList() {
|
---|
[298] | 307 | local i
|
---|
| 308 | echo -en "$1"
|
---|
| 309 | for i in $2 ; do
|
---|
| 310 | echo -en "$i "
|
---|
| 311 | done
|
---|
| 312 | echo ""
|
---|
[1] | 313 | }
|
---|
| 314 |
|
---|
[2925] | 315 | ListAllLogicalVolumesSortedBydm() {
|
---|
[3029] | 316 | rm -f $MINDI_TMP/sorteddm
|
---|
| 317 | for d in `ListAllLogicalVolumes` ; do
|
---|
| 318 | dm=`mindi --nolog --readalllink $d 2> /dev/null | tail -1`
|
---|
| 319 | echo "$dm|$d" >> $MINDI_TMP/sorteddm
|
---|
| 320 | done
|
---|
| 321 | if [ -f $MINDI_TMP/sorteddm ]; then
|
---|
[3037] | 322 | cut -d'-' -f2- $MINDI_TMP/sorteddm | sort -t'|' -n | cut -d'|' -f2
|
---|
[3029] | 323 | fi
|
---|
[2925] | 324 | }
|
---|
[1] | 325 |
|
---|
| 326 | ListAllLogicalVolumes() {
|
---|
[298] | 327 | if [ $lvmversion = 2 ]; then
|
---|
[2244] | 328 | $LVMCMD lvscan 2> /dev/null | grep "'" | grep -iw "ACTIVE" | cut -d"'" -f2
|
---|
[298] | 329 | else
|
---|
[2244] | 330 | lvscan 2> /dev/null | grep '"' | grep -iw "ACTIVE" | cut -d'"' -f2
|
---|
[298] | 331 | fi
|
---|
[1] | 332 | }
|
---|
| 333 |
|
---|
| 334 |
|
---|
| 335 |
|
---|
| 336 | WriteShutdownScript() {
|
---|
[298] | 337 | local i
|
---|
| 338 | echo ""
|
---|
| 339 | echo "Finally, to shut down and delete the volumes, do this:-"
|
---|
[1] | 340 | for i in `ListAllLogicalVolumes` ; do
|
---|
[298] | 341 | echo "($LVMCMD lvremove -f $i)"
|
---|
[1] | 342 | done
|
---|
| 343 | for i in `ListAllVolumeGroups` ; do
|
---|
[298] | 344 | echo "($LVMCMD vgchange -a n $i)"
|
---|
[1] | 345 | done
|
---|
| 346 | for i in `ListAllVolumeGroups` ; do
|
---|
[298] | 347 | echo "($LVMCMD vgremove $i)"
|
---|
[1] | 348 | done
|
---|
[298] | 349 | if [ $lvmversion = 2 ]; then
|
---|
| 350 | echo "(rmmod dm-mod & rmmod dm_mod & )"
|
---|
| 351 | else
|
---|
| 352 | echo "(rmmod lvm-mod)"
|
---|
| 353 | fi
|
---|
[1] | 354 | }
|
---|
| 355 |
|
---|
| 356 |
|
---|
| 357 |
|
---|
| 358 | # -------------------------------- main -----------------------------------
|
---|
[2579] | 359 |
|
---|
[3063] | 360 | # These exports are needed to avoid bad formating of display commands (, instead of . for separator e.g.)
|
---|
| 361 | # Fix #654
|
---|
| 362 | export LANG=C
|
---|
| 363 | export LANGUAGE=C
|
---|
[3639] | 364 | # avoids messagesa round leaked fd - Cf lvm man page
|
---|
| 365 | export LVM_SUPPRESS_FD_WARNINGS=1
|
---|
[3063] | 366 |
|
---|
[2579] | 367 | if [ "$1" = "--givemapperofdm" ] ; then
|
---|
| 368 | shift
|
---|
| 369 | if [ _"$1" != _"" ] ; then
|
---|
| 370 | GiveMapperOfdm $1
|
---|
| 371 | fi
|
---|
| 372 | exit 0
|
---|
| 373 | fi
|
---|
| 374 |
|
---|
[3066] | 375 | if [ "$1" = "--givevglvofdm" ] ; then
|
---|
| 376 | shift
|
---|
| 377 | if [ _"$1" != _"" ] ; then
|
---|
| 378 | GiveVGLVOfdm $1
|
---|
| 379 | fi
|
---|
| 380 | exit 0
|
---|
| 381 | fi
|
---|
[2579] | 382 |
|
---|
[3066] | 383 |
|
---|
[963] | 384 | which lvmdiskscan 2>/dev/null 2>&1 || Die "lvmdiskscan not found. Won't handle LVM."
|
---|
[2044] | 385 | if [ -e "/proc/lvm/global" ] && [ "`tr -s '\t' ' ' < /proc/lvm/global | grep "0 VGs 0 PVs 0 LVs"`" != "" ]; then
|
---|
| 386 | exit 1
|
---|
[1] | 387 | fi
|
---|
| 388 |
|
---|
[2565] | 389 | if [ _"$MINDI_TMP" = _"" ]; then
|
---|
| 390 | # Launched stdalone, so create a temp dir
|
---|
[2719] | 391 | STDALONE="true"
|
---|
[3499] | 392 | TMPDIR=${TMPDIR:=/tmp}
|
---|
| 393 | if [ ! -d $TMPDIR ]; then
|
---|
| 394 | mkdir -p $TMPDIR
|
---|
| 395 | fi
|
---|
[2565] | 396 | MINDI_TMP=`mktemp -d $TMPDIR/mindi.XXXXXXXXXX`
|
---|
| 397 | if [ $? -ne 0 ]; then
|
---|
| 398 | df $TMPDIR
|
---|
| 399 | Die "Unable to create a temporary directory ! Check space on $TMPDIR"
|
---|
| 400 | fi
|
---|
| 401 | if [ _"$MINDI_TMP" = _"" ]; then
|
---|
| 402 | Die "MINDI_TMP is empty, aborting"
|
---|
| 403 | fi
|
---|
| 404 | if [ _"$MINDI_TMP" = _"/" ]; then
|
---|
| 405 | Die "MINDI_TMP is /, aborting"
|
---|
| 406 | fi
|
---|
| 407 | fi
|
---|
| 408 |
|
---|
[2170] | 409 | # Older lvmdiskscan use --help, newer --version
|
---|
| 410 | lvmopt="--help"
|
---|
| 411 | lvmdiskscan $lvmopt 2>&1 | grep -q -- "--version"
|
---|
| 412 | if [ $? -eq 0 ]; then
|
---|
| 413 | lvmopt="--version"
|
---|
| 414 | fi
|
---|
| 415 |
|
---|
| 416 |
|
---|
[299] | 417 | lvmversion=`lvmdiskscan --help 2>&1 |
|
---|
[1] | 418 | grep -E "Logical Volume Manager|LVM version:" |
|
---|
| 419 | cut -d: -f2 | cut -d. -f1 |
|
---|
| 420 | awk '{print $NF}' |
|
---|
| 421 | sed -e 's/ //g'`
|
---|
| 422 |
|
---|
[97] | 423 | if which lvm 2>/dev/null; then
|
---|
[298] | 424 | version=`lvm version | grep "LVM version" | awk '{print $3}'`
|
---|
| 425 | i="`echo "$version" | cut -d'.' -f1`"
|
---|
| 426 | echo "i=$i"
|
---|
| 427 | if [ "$i" -ge "2" ] ; then
|
---|
| 428 | lvmversion=2
|
---|
| 429 | fi
|
---|
[1] | 430 | fi
|
---|
| 431 |
|
---|
| 432 | if [ $lvmversion = 2 ]; then
|
---|
[298] | 433 | echo "LVM version >= 2.0 found."
|
---|
| 434 | LVMCMD="lvm"
|
---|
| 435 | else
|
---|
| 436 | LVMCMD=""
|
---|
[1] | 437 | fi
|
---|
| 438 |
|
---|
[2565] | 439 | rm -f $MINDI_TMP/excludedvgs
|
---|
[1] | 440 | all_lvm_drives_and_partitions=`ListLvmDrivesAndPartitions`
|
---|
| 441 | echo "Just before you extrapolate mountlist to include RAID partitions,"
|
---|
| 442 | echo "extrapolate it to include the following LVM drives and partitions:-"
|
---|
| 443 | PrettifyList ">>>>> " "$all_lvm_drives_and_partitions"
|
---|
| 444 | echo "To get started, type:-"
|
---|
| 445 | if [ $lvmversion = 2 ]; then
|
---|
[298] | 446 | echo "(insmod dm-mod)"
|
---|
| 447 | echo "(insmod dm_mod)"
|
---|
[1] | 448 | else
|
---|
[298] | 449 | echo "(insmod lvm-mod)"
|
---|
[1] | 450 | fi
|
---|
[298] | 451 | echo "# $LVMCMD vgchange -an"
|
---|
[1] | 452 | for i in `ListAllPhysicalVolumes` ; do
|
---|
[298] | 453 | echo "# echo y | $LVMCMD pvcreate -ff $i"
|
---|
[1] | 454 | done
|
---|
[706] | 455 | echo "# $LVMCMD vgscan"
|
---|
[1] | 456 | echo ""
|
---|
| 457 | echo "Create and activate the VG's (volume groups)."
|
---|
| 458 | all_volume_groups=`ListAllVolumeGroups`
|
---|
| 459 | for current_VG in $all_volume_groups ; do
|
---|
[298] | 460 | if [ $lvmversion -ne 2 ]; then
|
---|
| 461 | echo "# rm -Rf /dev/$current_VG"
|
---|
| 462 | fi
|
---|
| 463 | ProcessVolumeGroup $current_VG
|
---|
[1] | 464 | done
|
---|
| 465 | echo ""
|
---|
| 466 | echo "Finally, create the LV's (logical volumes)."
|
---|
[2925] | 467 | all_logical_volumes=`ListAllLogicalVolumesSortedBydm`
|
---|
[1] | 468 | for current_LV in $all_logical_volumes ; do
|
---|
[298] | 469 | ProcessLogicalVolume $current_LV
|
---|
[1] | 470 | done
|
---|
| 471 | echo ""
|
---|
[298] | 472 | echo "# $LVMCMD vgscan"
|
---|
[1] | 473 | echo "Now you may format the LV's:-"
|
---|
| 474 | for i in `ListAllLogicalVolumes` ; do
|
---|
[298] | 475 | echo "(mkfs -t foo $i or something like that)"
|
---|
[1] | 476 | done
|
---|
[2565] | 477 | rm -f $MINDI_TMP/excludedvgs
|
---|
[1] | 478 | WriteShutdownScript
|
---|
[2719] | 479 | if [ _"$STDALONE" = _"true" ]; then
|
---|
| 480 | rm -rf $MINDI_TMP
|
---|
| 481 | fi
|
---|
[1] | 482 | exit 0
|
---|
| 483 |
|
---|
| 484 |
|
---|
| 485 |
|
---|