Changeset 298 in MondoRescue
- Timestamp:
- Jan 11, 2006, 12:44:18 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.06/mindi/analyze-my-lvm
r275 r298 36 36 37 37 Die() { 38 39 38 echo "$1" >> /dev/stderr 39 exit 1 40 40 } 41 41 … … 43 43 44 44 GetValueFromField() { 45 46 45 local res 46 sed s/' '/~/ "$1" | tr -s ' ' ' ' | sed s/'~ '/'~'/ | grep -i "$2~" | cut -d'~' -f2,3,4,5 | tr '~' ' ' | gawk '{ if ($2=="MB") {printf "%sm",$1;} else if ($2=="KB") {printf "%sk",$1;} else if ($2=="GB") {printf "%sg",$1;} else {print $0;};}' 47 47 } 48 48 49 49 50 50 GetLastBit() { 51 52 53 54 55 i=$(($i-1))56 res=`echo "$1" | cut -d'/' -f$i`57 58 51 local i res 52 i=20 53 res="" 54 while [ ! "$res" ] ; do 55 i=$(($i-1)) 56 res=`echo "$1" | cut -d'/' -f$i` 57 done 58 echo "$res" 59 59 } 60 60 61 61 62 62 ProcessLogicalVolume() { 63 local LV_full_string fname logical_volume volume_group device 64 LV_full_string=$1 65 [ ! -e "$1" ] && Die "Cannot find LV file $1" 66 volume_group=`echo "$LV_full_string" | cut -d'/' -f3` 67 logical_volume=`echo "$LV_full_string" | cut -d'/' -f4` 68 if [ $lvmversion = 2 ]; then 69 device=$LV_full_string 70 params=`GenerateLvcreateParameters $device` 71 echo "# lvm lvcreate$params -n $logical_volume $volume_group" 72 else 73 fname=/proc/lvm/VGs/$volume_group/LVs/$logical_volume 74 if [ ! -e "$fname" ] ; then 75 echo "Warning - cannot find $volume_group's $logical_volume LV file" 76 else 77 device=`GetValueFromField $fname "name:"` 78 params=`GenerateLvcreateParameters $device` 79 echo "# lvcreate$params -n $logical_volume $volume_group" 80 fi 81 fi 63 local LV_full_string fname logical_volume volume_group device 64 LV_full_string=$1 65 [ ! -e "$1" ] && Die "Cannot find LV file $1" 66 volume_group=`echo "$LV_full_string" | cut -d'/' -f3` 67 logical_volume=`echo "$LV_full_string" | cut -d'/' -f4` 68 if [ $lvmversion = 2 ]; then 69 device=$LV_full_string 70 params=`GenerateLvcreateParameters $device` 71 else 72 fname=/proc/lvm/VGs/$volume_group/LVs/$logical_volume 73 if [ ! -e "$fname" ] ; then 74 echo "Warning - cannot find $volume_group's $logical_volume LV file" 75 else 76 device=`GetValueFromField $fname "name:"` 77 params=`GenerateLvcreateParameters $device` 78 fi 79 fi 80 echo "# $LVMCMD lvcreate$params -n $logical_volume $volume_group" 82 81 } 83 82 84 83 85 84 GenerateLvcreateParameters() { 86 local device stripes stripesize device fname allocation output readahead 87 fname=/tmp/PLF.$$.txt 88 device=$1 89 output="" 90 if [ $lvmversion = 2 ]; then 91 lvm lvdisplay $device > $fname 92 else 93 lvdisplay $device > $fname 94 fi 95 stripes=`GetValueFromField $fname "Stripes"` 96 stripesize=`GetValueFromField $fname "Stripe size (MByte)"`m 97 [ "$stripesize" = "m" ] && stripesize=`GetValueFromField $fname "Stripe size (KByte)"`k 98 [ "$stripesize" = "k" ] && stripesize="" 99 allocation=`GetValueFromField $fname "LV Size"` 100 [ ! "`echo "$allocation" | grep "[k,m,g]"`" ] && allocation="$allocation"m 101 if echo "$allocation" | grep -x ".*g" > /dev/null 2> /dev/null ; then 102 val=`echo "$allocation" | sed s/g//` 103 allocation=`echo "$val" | awk '{c=$1; printf "%d", c*1024;}'`m 104 fi 105 readahead=`GetValueFromField $fname "Read ahead sectors"` 106 rm -f $fname 107 [ "$stripes" ] && output="$output -i $stripes" 108 [ "$stripesize" ] && output="$output -I $stripesize" 109 [ "$allocation" ] && output="$output -L $allocation" 110 [ "$readahead" ] && output="$output -r $readahead" 111 echo "$output" 85 local device stripes stripesize device fname allocation output readahead 86 fname=/tmp/PLF.$$.txt 87 device=$1 88 output="" 89 $LVMCMD lvdisplay $device > $fname 90 stripes=`GetValueFromField $fname "Stripes"` 91 stripesize=`GetValueFromField $fname "Stripe size (MByte)"`m 92 [ "$stripesize" = "m" ] && stripesize=`GetValueFromField $fname "Stripe size (KByte)"`k 93 [ "$stripesize" = "k" ] && stripesize="" 94 allocation=`GetValueFromField $fname "LV Size"` 95 [ ! "`echo "$allocation" | grep "[k,m,g]"`" ] && allocation="$allocation"m 96 if echo "$allocation" | grep -x ".*g" > /dev/null 2> /dev/null ; then 97 val=`echo "$allocation" | sed s/g//` 98 allocation=`echo "$val" | awk '{c=$1; printf "%d", c*1024;}'`m 99 fi 100 readahead=`GetValueFromField $fname "Read ahead sectors"` 101 rm -f $fname 102 [ "$stripes" ] && output="$output -i $stripes" 103 [ "$stripesize" ] && output="$output -I $stripesize" 104 [ "$allocation" ] && output="$output -L $allocation" 105 [ "$readahead" ] && output="$output -r $readahead" 106 echo "$output" 112 107 } 113 108 … … 115 110 116 111 GenerateVgcreateParameters() { 117 local current_VG device fname incoming VG_info_file max_logical_volumes max_physical_volumes physical_extent_size output blanklines 118 current_VG=$1 119 VG_info_file=/tmp/$$.vg-info.txt 120 if [ $lvmversion = 2 ]; then 121 lvm vgdisplay $current_VG > $VG_info_file 122 else 123 vgdisplay $current_VG > $VG_info_file 124 fi 125 max_logical_volumes=`GetValueFromField "$VG_info_file" "MAX LV"` 126 [ $max_logical_volumes -ge 256 ] && max_logical_volumes=255 127 max_physical_volumes=`GetValueFromField "$VG_info_file" "MAX PV"` 128 [ $max_physical_volumes -ge 256 ] && max_physical_volumes=255 129 physical_extent_size=`GetValueFromField "$VG_info_file" "PE Size"` 130 output="" 131 [ "$max_logical_volumes" ] && output="$output -l $max_logical_volumes" 132 [ "$max_physical_volumes" ] && output="$output -p $max_physical_volumes" 133 [ "$physical_extent_size" ] && output="$output -s $physical_extent_size" 134 echo "$output" 135 rm -f $VG_info_file 112 local current_VG device fname incoming VG_info_file max_logical_volumes max_physical_volumes physical_extent_size output blanklines 113 current_VG=$1 114 VG_info_file=/tmp/$$.vg-info.txt 115 $LVMCMD vgdisplay $current_VG > $VG_info_file 116 max_logical_volumes=`GetValueFromField "$VG_info_file" "MAX LV"` 117 [ $max_logical_volumes -ge 256 ] && max_logical_volumes=255 118 max_physical_volumes=`GetValueFromField "$VG_info_file" "MAX PV"` 119 [ $max_physical_volumes -ge 256 ] && max_physical_volumes=255 120 physical_extent_size=`GetValueFromField "$VG_info_file" "PE Size"` 121 output="" 122 [ "$max_logical_volumes" ] && output="$output -l $max_logical_volumes" 123 [ "$max_physical_volumes" ] && output="$output -p $max_physical_volumes" 124 [ "$physical_extent_size" ] && output="$output -s $physical_extent_size" 125 echo "$output" 126 rm -f $VG_info_file 136 127 } 137 128 … … 141 132 142 133 ProcessVolumeGroup() { 143 local current_VG physical_volumes i list_of_devices VG_params 144 current_VG=$1 145 if [ $lvmversion = 2 ]; then 146 VG_params=`GenerateVgcreateParameters $current_VG` 147 list_of_devices=`lvm pvs | grep "$current_VG" | awk '{print $1}'` 148 echo "# lvm vgcreate $current_VG$VG_params $list_of_devices" 149 echo "# lvm vgchange -a y $current_VG" 150 else 151 info_file=/proc/lvm/VGs/$current_VG/group 152 physical_volumes=`ls /proc/lvm/VGs/$current_VG/PVs` 153 VG_params=`GenerateVgcreateParameters $current_VG` 154 list_of_devices="" 155 for i in $physical_volumes ; do 156 fname=/proc/lvm/VGs/$current_VG/PVs/$i 157 device=`GetValueFromField $fname "name:"` 158 list_of_devices="$list_of_devices $device" 159 done 160 echo "# vgcreate $current_VG$VG_params$list_of_devices" 161 echo "# vgchange -a y $current_VG" 162 fi 134 local current_VG physical_volumes i list_of_devices VG_params 135 current_VG=$1 136 if [ $lvmversion = 2 ]; then 137 VG_params=`GenerateVgcreateParameters $current_VG` 138 list_of_devices=`$LVMCMD pvs | grep "$current_VG" | awk '{print $1}'` 139 else 140 info_file=/proc/lvm/VGs/$current_VG/group 141 physical_volumes=`ls /proc/lvm/VGs/$current_VG/PVs` 142 VG_params=`GenerateVgcreateParameters $current_VG` 143 list_of_devices="" 144 for i in $physical_volumes ; do 145 fname=/proc/lvm/VGs/$current_VG/PVs/$i 146 device=`GetValueFromField $fname "name:"` 147 list_of_devices="$list_of_devices $device" 148 done 149 fi 150 echo "# $LVMCMD vgcreate $current_VG$VG_params $list_of_devices" 151 echo "# $LVMCMD vgchange -a y $current_VG" 163 152 } 164 153 … … 166 155 167 156 ListAllPhysicalVolumes() { 168 169 lvmpvscan 2> /dev/null | grep 'PV' | awk '{print $2}'170 171 pvscan 2> /dev/null | grep '"' | cut -d'"' -f2172 157 if [ $lvmversion = 2 ]; then 158 $LVMCMD pvscan 2> /dev/null | grep 'PV' | awk '{print $2}' 159 else 160 pvscan 2> /dev/null | grep '"' | cut -d'"' -f2 161 fi 173 162 } 174 163 175 164 176 165 ListAllVolumeGroups() { 177 if [ $lvmversion = 2 ]; then 178 lvm vgdisplay 2> /dev/null | awk '/^ *VG Name/ {print $3;}' 179 else 180 vgdisplay 2> /dev/null | awk '/^VG Name/ {print $3;}' 181 fi 166 $LVMCMD vgdisplay 2> /dev/null | awk '/^ *VG Name/ {print $3;}' 182 167 } 183 168 184 169 185 170 ListLvmDrivesAndPartitions() { 186 if [ $lvmversion = 2 ]; then 187 lvm vgdisplay -v |grep "PV Name" | awk '{print $3}' 188 else 189 vgdisplay -v |grep "PV Name" | awk '{print $4}' 190 fi 171 $LVMCMD vgdisplay -v |grep "PV Name" | awk '{print $3}' 191 172 } 192 173 … … 194 175 195 176 PrettifyList() { 196 197 198 199 echo -en "$i "200 201 177 local i 178 echo -en "$1" 179 for i in $2 ; do 180 echo -en "$i " 181 done 182 echo "" 202 183 } 203 184 204 185 205 186 ListAllLogicalVolumes() { 206 207 lvmlvscan | grep "'" | cut -d"'" -f2208 209 lvscan | grep '"' | cut -d'"' -f2210 187 if [ $lvmversion = 2 ]; then 188 $LVMCMD lvscan | grep "'" | cut -d"'" -f2 189 else 190 lvscan | grep '"' | cut -d'"' -f2 191 fi 211 192 } 212 193 … … 214 195 215 196 WriteShutdownScript() { 216 local i 217 echo "" 218 echo "Finally, to shut down and delete the volumes, do this:-" 219 if [ $lvmversion = 2 ]; then 197 local i 198 echo "" 199 echo "Finally, to shut down and delete the volumes, do this:-" 220 200 for i in `ListAllLogicalVolumes` ; do 221 echo "( lvmlvremove -f $i)"201 echo "($LVMCMD lvremove -f $i)" 222 202 done 223 203 for i in `ListAllVolumeGroups` ; do 224 echo "( lvmvgchange -a n $i)"204 echo "($LVMCMD vgchange -a n $i)" 225 205 done 226 206 for i in `ListAllVolumeGroups` ; do 227 echo "(lvm vgremove $i)" 228 done 229 echo "(rmmod dm-mod & rmmod dm_mod & )" 230 else 231 for i in `ListAllLogicalVolumes` ; do 232 echo "(lvremove -f $i)" 233 done 234 for i in `ListAllVolumeGroups` ; do 235 echo "(vgchange -a n $i)" 236 done 237 for i in `ListAllVolumeGroups` ; do 238 echo "(vgremove $i)" 239 done 240 echo "(rmmod lvm-mod)" 241 fi 207 echo "($LVMCMD vgremove $i)" 208 done 209 if [ $lvmversion = 2 ]; then 210 echo "(rmmod dm-mod & rmmod dm_mod & )" 211 else 212 echo "(rmmod lvm-mod)" 213 fi 242 214 } 243 215 … … 247 219 which lvmdiskscan 2>/dev/null 2>&1 || Die "Cannot find lvmdiskscan. Are you sure you're using LVM?" 248 220 if [ -e "/proc/lvm/global" ] && [ "`tr -s '\t' ' ' < /proc/lvm/global | grep "0 VGs 0 PVs 0 LVs"`" != "" ] ; then 249 221 exit 0 250 222 fi 251 223 … … 262 234 263 235 if which lvm 2>/dev/null; then 264 version=`lvm version | grep "LVM version" | awk '{print $3}'` 265 i="`echo "$version" | cut -d'.' -f1`" 266 echo "i=$i" 267 if [ "$i" -ge "2" ] ; then 268 # if [ $version >= "2.00" ]; then 269 lvmversion=2 270 fi 236 version=`lvm version | grep "LVM version" | awk '{print $3}'` 237 i="`echo "$version" | cut -d'.' -f1`" 238 echo "i=$i" 239 if [ "$i" -ge "2" ] ; then 240 lvmversion=2 241 fi 271 242 fi 272 243 273 244 if [ $lvmversion = 2 ]; then 274 echo "LVM version >= 2.0 found." 245 echo "LVM version >= 2.0 found." 246 LVMCMD="lvm" 247 else 248 LVMCMD="" 275 249 fi 276 250 … … 281 255 echo "To get started, type:-" 282 256 if [ $lvmversion = 2 ]; then 283 echo "(insmod dm-mod)" 284 echo "(insmod dm_mod)" 285 echo "# lvm vgchange -an" 257 echo "(insmod dm-mod)" 258 echo "(insmod dm_mod)" 286 259 else 287 288 echo "# vgchange -an" 289 fi 260 echo "(insmod lvm-mod)" 261 fi 262 echo "# $LVMCMD vgchange -an" 290 263 for i in `ListAllPhysicalVolumes` ; do 291 # echo "# dd if=/dev/zero of=$i bs=512 count=1" 292 if [ $lvmversion = 2 ]; then 293 echo "# echo y | lvm pvcreate -ff $i" 294 else 295 echo "# echo y | pvcreate -ff $i" 296 fi 297 done 298 if [ $lvmversion = 2 ]; then 299 echo "# lvm vgscan; echo" 300 else 301 echo "# vgscan; echo" 302 fi 264 echo "# echo y | $LVMCMD pvcreate -ff $i" 265 done 266 echo "# $LVMCMD vgscan; echo" 303 267 echo "" 304 268 echo "Create and activate the VG's (volume groups)." 305 269 all_volume_groups=`ListAllVolumeGroups` 306 270 for current_VG in $all_volume_groups ; do 307 308 309 310 271 if [ $lvmversion -ne 2 ]; then 272 echo "# rm -Rf /dev/$current_VG" 273 fi 274 ProcessVolumeGroup $current_VG 311 275 done 312 276 echo "" … … 314 278 all_logical_volumes=`ListAllLogicalVolumes` 315 279 for current_LV in $all_logical_volumes ; do 316 280 ProcessLogicalVolume $current_LV 317 281 done 318 282 echo "" 319 if [ $lvmversion = 2 ]; then 320 echo "# lvm vgscan" 321 else 322 echo "# vgscan" 323 fi 283 echo "# $LVMCMD vgscan" 324 284 echo "Now you may format the LV's:-" 325 285 for i in `ListAllLogicalVolumes` ; do 326 286 echo "(mkfs -t foo $i or something like that)" 327 287 done 328 288 WriteShutdownScript
Note:
See TracChangeset
for help on using the changeset viewer.