source: MondoRescue/branches/3.1/mindi/analyze-my-lvm@ 2937

Last change on this file since 2937 was 2937, checked in by Bruno Cornec, 12 years ago

svn merge -r 2849:2935 ../3.0

  • Adds 3 binaries called potentially by udev o support USB key mount at restore time (Victor Gattegno)
  • mindi only sets the boot flag of a USB device if none is present already (should avoid flip/flop situation)
  • Fix a compatibility bug in analyze-my-lvm whete exclude lists with '|' was incorrectly analyzed (' ' still expected)
  • Precise that -J is not supported by mondorestore yet.
  • Fix a compatibility bug in mindi where exclude lists with '|' was incorrectly analyzed (' ' still expected)
  • Install an MBR on USB devices when possible
  • Improve error message in case mondorestore isn't found
  • Adds support for more virtio devices for KVM restore
  • Improve mbr.bin handling
  • Fix an issue in test of FindKernel for Xen and non Xen cases
    • Fix #492 by removing an extra useless fi
    • Move fvat nd fat modules to CDROM_MODS in order to have them in the initrd to support saving logs to a USB device e.g.
    • Fix an error when dmidecode reports comments before system name
    • Fix previous broken patch on comment management for bkphw
    • Improve msgs printed during kbd analysis
    • Fix a small remaining pb with new comment support
    • Try to again improve the mount/umount stuff in mondo -Adds mention to OEL, CentOS, ScientifLinux as RHEL clones
  • Fix a panadoid_free done on the wrong variable (solve a memory leak)
  • Solve #495 by skipping the potential (auto-read-only) when analyzin /proc/mdstat result
  • Fix some markup in man pages
  • adds the post-nuke script sample for Debian (Guillaume Pernot/Andrée Leidenfrost)
  • Avoid a useless umount when changing of afio set, let insist_on_cd check and perform if needed
  • Copy everything under .ssh of root account to allow for sshfs mount without passwd at restore time.
  • Adds support for bnx2i driver
  • Try to fix #496 by supporting the protocol in the output of the mount command (sshfs#...)
  • Uses the -d option of the mount command to avoid leaving loop devices in use. Probably provoked by the usage of a more recent busybox, but anyway that option doesn't hurt, and does nothing for non-loop devices. Should fix the problems reported on the ML with NFS and more than 8 ISO images (8 being the default number of loop devices available)
  • Attempt to fix #436 by adding some newtDrawForm where appropriate.
  • Fix bugs in the kernel detection routine of mindi (some echo were done without capturing their output, confusing the return). This should also help the Xen detection issue
  • Change the logging function to be nearer from 2.2.10, and start using some
  • Initialize some global fields with an empty string, now that newt Draws more regularly progress forms
  • Mindi progression still not good, but showing now 3% when calling mindi. Would need a specific handling for the progress bar to evolve more afterwards
  • Add compatibility with the latest SSSTK + PSP content for HP ProLiant + branding homogeneous now. We only take conrep out of the SSSTK pending a package availability. Using hpacuscripting now. Review of parameters called following test made.
  • Fix #501 by pushing BOOT_SIZE to 36864 for certain Ubuntu cases
  • Fix some remaining inconsistencis in the ProLiant HW backup. ready for usage.
  • Fix an issue on udevadm call (needs an intermediate variable)
  • Fix a remaining ProLiant tool call
  • Remove again some wrong variable initialization for Net in order to not have strange messages now we call Draw more often
  • Adds support for hwaddr (MAC addresses) at restore time, and map to the correct NIC if it's found at restore time (based on code from Stefan Heijmans)
  • Try to Fix #499 by changing init in order to never exit, and rebooting using sysrq in /proc (not portable). Maybe should move to using a real init, and a separated rcS script.
  • Fixes the shell msg error by using setsid as per Busybox FAQ
  • Fix #491 by correctly checking Xen kernel used for a dom0 env (apollo13)
  • Improves logging in Die()
  • Improve again ProLiant HW support, by adding references to the yet to come SSSTK rpm so that conrep is called at its future right place.
  • Improve mindi support for kernel 3.x
  • Fix #499 for good, by using a real init from busybox and moving our init script to etc/init.d/rcS. We also now call the reboot from busybox to exit, which indeed reset the system correctly (in a VM at least which wasn't the case before). Reauires a new mindi-busybox as well.
  • Attempt to solve #503 by handling /lib64 separately for udev and only if not a link (to /lib) for Ubuntu 64
  • Improve again previous tests for bug #503
  • Improve -d option description for NFS
  • Allow http download for ftp content
  • New italian mirror
  • Fix #505 by documenting environment variables
    • Fix a bug where on OBDR mode compression was turned off to create the OBDR content but not back on (report from the mailing list)
  • solve http://trac.mondorescue.org/ticket/520 by Victor Gattegno
  • Fix #524 as option -U needs a size also
  • Removes useless gendf option
  • Fix #511 now stabgrub is called also after conf file modifications
  • Adds support for SUID binaries
  • remove a useless xenkernelname variable from mindi
  • Should fix #512 by clearing old scratchdir before changing to a new
  • Simplify the function engaging SCSI for Smart Array controllers, and support as many controller as we have
  • Add some binaries used on SLES 10 by udev
  • Fix a syntax issue in newt-specific.c
  • Fix a memory free bug where a used variable was freed to early
  • Fix a memory free bug where a used variable was misused in asprintf/free
  • Fix #498 by using an external program (hpsa_obdr_mode) which can set the mode of the tape to CD-ROM or Sequential at will.

That program will have to be downloaded from http://cciss.sf.net

  • Adds support for the route command in mindi-busybox
  • Force block size back to 32768 in OBDR mode after skipping the 2 tape marks, to read the additional rootfs data corerctly - Fix #498 for good it seems
  • Adds support for a new pata_atiixp driver
  • Fix #525 and improve printing when no /etc/raidtab, but still md devices
  • Exclude /run similarly to /sys and /proc
  • Fix a bug in mindi when having multiple swap partiions with same starting string (/dev/dm-1 and /dev/dm-16). We now add a space in the grep to avoid mischoice.
  • Fix grub installation if we had to go in the hack part which wasn't using the correct variables to make decisions !
  • Remove all mention of mondorescue.com from code
  • Fix some website typo on the download page and precise that we now develop on Mageia
  • Exclude sysfs devpts and tmpfs partitions found in RHEL 6.2 from analyze by mindi (made error messages)
  • Force activation of first partition which should not be optional as everything is destroyed before
  • Fix a bug in analyze-my-lvm where LVs were created in random order (the one of lvscan) instead of using the dm-xxx order, which creates issues at restore time between the mapping created then and the one we had at backup time which could be inconssistent

-mondoarchive now exists if the mt command is missing when needed

  • Proper fix for analyze-my-lvm
  • Fix #500 and #473 by adding support of old metadata format for mdadm if using grub < 0.9x or lilo on a md boot device (to be tested)
  • Really never inject or eject when the -e option is passed or device is inappropriate (USB, Net, ...)
  • Fix #577 by having factor back as a float (not a long ! it's a decimal value) and making the appropriate cast.
  • Fix #578 by improving the regexp used for CD/DVD detection with -scanbus option
  • Adds more verbosity when LVM creation fails.
  • Fix #579 by checking with pipes on both sides of the string
  • debugfs should be excluded from the device considered for fstab analysis
  • Property svn:keywords set to Id
File size: 11.5 KB
Line 
1#!/bin/bash
2#
3# $Id: analyze-my-lvm 2937 2012-01-28 00:51:28Z bruno $
4#
5
6Die() {
7 echo "$1" >> /dev/stderr
8 exit -1
9}
10
11
12
13GetValueFromField() {
14 local res
15 sed s/' '/~/ "$1" | tr -s ' ' ' ' | sed s/'~ '/'~'/ | grep -i "$2~" | cut -d'~' -f2,3,4,5 | tr '~' ' ' | gawk '{ if ($2=="MB") {printf "%dm",$1;} else if ($2=="MiB") {printf "%dm",$1;} else if ($2=="KB") {printf "%dk",$1;} else if ($2=="KiB") {printf "%dk",$1;} else if ($2=="GB") {printf "%fg",$1;} else if ($2=="GiB") {printf "%fg",$1;} else if ($2=="TB") {printf "%dt",$1;} else if ($2=="TiB") {printf "%dt",$1;} else {print $0;};}'
16}
17
18
19GetLastBit() {
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"
28}
29
30
31ProcessLogicalVolume() {
32 local LV_full_string fname logical_volume volume_group device
33 LV_full_string=$1
34 if [ ! -e "$1" ]; then
35 echo "WARNING - cannot find LV file $1" | tee -a /dev/stderr
36 return
37 fi
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`
43 else
44 fname=/proc/lvm/VGs/$volume_group/LVs/$logical_volume
45 if [ ! -e "$fname" ] ; then
46 echo "WARNING - cannot find $volume_group's $logical_volume LV file" | tee -a /dev/stderr
47 return
48 else
49 device=`GetValueFromField $fname "name:"`
50 params=`GenerateLvcreateParameters $device`
51 fi
52 fi
53
54 # Exclude LVs member of that env var
55 if [ "$MINDI_EXCLUDE_DEVS" ] ; then
56 list_of_devices="`mindi --readalllink $LV_full_string`"
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`"
62 for ed in `echo $MINDI_EXCLUDE_DEVS | sed 's/|/ /g'`; do
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
69 # Do not process LV whose VG are excluded
70 if [ -f $MINDI_TMP/excludedvgs ]; then
71 if [ "`grep -x $volume_group $MINDI_TMP/excludedvgs`" != "" ]; then
72 echo "Not including LV $logical_volume as VG $volume_group was excluded"
73 return
74 fi
75 fi
76
77 echo "# $LVMCMD lvcreate$params -n $logical_volume $volume_group"
78}
79
80
81GenerateLvcreateParameters() {
82 local device stripes stripesize device fname allocation output readahead
83 fname=$MINDI_TMP/PLF.$$.txt
84 device=$1
85 output=""
86 $LVMCMD lvdisplay $device > $fname
87 stripes=`GetValueFromField $fname "Stripes"`
88 stripesize=`GetValueFromField $fname "Stripe size (MByte)"`m
89 [ "$stripesize" = "m" ] && stripesize=`GetValueFromField $fname "Stripe size (KByte)"`k
90 [ "$stripesize" = "k" ] && stripesize=""
91 allocation=`GetValueFromField $fname "LV Size"`
92 [ ! "`echo "$allocation" | grep "[k,m,g]"`" ] && allocation="$allocation"m
93 if echo "$allocation" | grep -E '^.*g$' > /dev/null 2> /dev/null ; then
94 val=`echo "$allocation" | sed s/g//`
95 allocation=`echo "$val" | awk '{c=$1; printf "%d", c*1024;}'`m
96 fi
97 readahead=`GetValueFromField $fname "Read ahead sectors"`
98 rm -f $fname
99 [ "$stripes" ] && output="$output -i $stripes"
100 [ "$stripesize" ] && output="$output -I $stripesize"
101 [ "$allocation" ] && output="$output -L $allocation"
102 [ "$readahead" ] && output="$output -r $readahead"
103 echo "$output"
104}
105
106
107
108GenerateVgcreateParameters() {
109 local current_VG device fname incoming VG_info_file max_logical_volumes max_physical_volumes physical_extent_size output blanklines
110 current_VG=$1
111 VG_info_file=$MINDI_TMP/$$.vg-info.txt
112 # We use cat here as a way to avoid SElinux to prevent us from writing in $VG_info_file
113 $LVMCMD vgdisplay $current_VG | cat > $VG_info_file
114 max_logical_volumes=`GetValueFromField "$VG_info_file" "MAX LV"`
115 [ $max_logical_volumes -ge 256 ] && max_logical_volumes=255
116 max_physical_volumes=`GetValueFromField "$VG_info_file" "MAX PV"`
117 [ $max_physical_volumes -ge 256 ] && max_physical_volumes=255
118 physical_extent_size=`GetValueFromField "$VG_info_file" "PE Size"`
119 output=""
120 [ "$max_logical_volumes" ] && output="$output -l $max_logical_volumes"
121 [ "$max_physical_volumes" ] && output="$output -p $max_physical_volumes"
122 [ "$physical_extent_size" ] && output="$output -s $physical_extent_size"
123 echo "$output"
124 rm -f $VG_info_file
125}
126
127
128
129
130
131ProcessVolumeGroup() {
132 local current_VG physical_volumes i list_of_devices VG_params
133 current_VG=$1
134 if [ $lvmversion = 2 ]; then
135 VG_params=`GenerateVgcreateParameters $current_VG`
136 current_PVs=`$LVMCMD pvscan | grep " $current_VG " | awk '{print $2}' | tr '\n' ' '`
137 list_of_devices=$current_PVs
138 else
139 info_file=/proc/lvm/VGs/$current_VG/group
140 physical_volumes=`ls /proc/lvm/VGs/$current_VG/PVs`
141 VG_params=`GenerateVgcreateParameters $current_VG`
142 list_of_devices=""
143 for i in $physical_volumes ; do
144 fname=/proc/lvm/VGs/$current_VG/PVs/$i
145 device=`GetValueFromField $fname "name:"`
146 list_of_devices="$list_of_devices $device"
147 done
148 current_PVs=$list_of_devices
149 fi
150 l=""
151 if [ -f /etc/multipath.conf ]; then
152 # If multipath check which type of devide are given, mpath prefered
153 for d in $list_of_devices; do
154 l="$l `mindi --readalllink $d`"
155 l="$l `GiveMapperOfdm $d`"
156 done
157 list_of_devices="`echo $l | sort -u`"
158 fi
159
160 if [ "$MINDI_EXCLUDE_DEVS" ] ; then
161 for ed in `echo $MINDI_EXCLUDE_DEVS | sed 's/|/ /g'`; do
162 if [ "`echo " $list_of_devices" | grep " $ed"`" != "" ]; then
163 echo $current_VG >> $MINDI_TMP/excludedvgs
164 return
165 fi
166 done
167 fi
168 echo "# $LVMCMD vgcreate $current_VG$VG_params $current_PVs"
169 echo "# $LVMCMD vgchange -a y $current_VG"
170}
171
172
173
174ListAllPhysicalVolumes() {
175 if [ $lvmversion = 2 ]; then
176 $LVMCMD pvscan 2> /dev/null | grep 'PV' | grep -v unknown | awk '{print $2}' > $MINDI_TMP/pv.tmp
177 else
178 pvscan 2> /dev/null | grep '"' | cut -d'"' -f2 > $MINDI_TMP/pv.tmp
179 fi
180
181 rm -f $MINDI_TMP/pv.tmp2
182 for d in `cat $MINDI_TMP/pv.tmp`; do
183 # Skip devices excluded, coming from mondoarchive
184 skip=0
185 l=""
186 l="$l `mindi --readalllink $d`"
187 l="$l `GiveMapperOfdm $d`"
188 list_of_devices="`echo $l | sort -u`"
189 if [ "$MINDI_EXCLUDE_DEVS" ] ; then
190 for ed in `echo $MINDI_EXCLUDE_DEVS | sed 's/|/ /g'`; do
191 if [ "`echo " $list_of_devices " | grep " $ed"`" != "" ]; then
192 skip=1
193 continue
194 fi
195 done
196 fi
197 if [ $skip -eq 1 ]; then
198 continue
199 fi
200 echo $d >> $MINDI_TMP/pv.tmp2
201 done
202
203 if [ -f /etc/multipath.conf ]; then
204 # If multipath check which type of devide are given, mpath prefered
205 if [ -f $MINDI_TMP/pv.tmp2 ]; then
206 l=""
207 for d in `cat $MINDI_TMP/pv.tmp2`; do
208 skip=0
209 l="$l `mindi --readalllink $d`"
210 l="$l `GiveMapperOfdm $d`"
211 list_of_devices="`echo $l | sort -u`"
212 if [ "$MINDI_EXCLUDE_DEVS" ] ; then
213 for ed in `echo $MINDI_EXCLUDE_DEVS | sed 's/|/ /g'`; do
214 if [ "`echo " $list_of_devices " | grep " $ed"`" != "" ]; then
215 skip=1
216 continue
217 fi
218 done
219 fi
220 if [ $skip -eq 1 ]; then
221 continue
222 fi
223 GiveMapperOfdm $d
224 done
225 fi
226 else
227 if [ -f $MINDI_TMP/pv.tmp2 ]; then
228 cat $MINDI_TMP/pv.tmp2
229 fi
230 fi
231 rm -f $MINDI_TMP/pv.tmp $MINDI_TMP/pv.tmp2
232}
233
234
235ListAllVolumeGroups() {
236 $LVMCMD vgdisplay 2> /dev/null | awk '/^ *VG Name/ {print $3;}'
237}
238
239GiveMapperOfdm () {
240
241major=`stat -c "%t" $1 2> /dev/null`
242minor=`stat -c "%T" $1 2> /dev/null`
243
244for i in `ls /dev/mapper/*`; do
245 mj=`stat -c "%t" $i`
246 mn=`stat -c "%T" $i`
247 if [ "$mj" = "$major" ] && [ "$mn" = "$minor" ]; then
248 echo "$i"
249 return
250 fi
251done
252echo $1
253}
254
255
256ListLvmDrivesAndPartitions() {
257 # We get partitions in this loop not devices
258 for d in `$LVMCMD vgdisplay -v 2> /dev/null | grep "PV Name" | sed 's/(#)//' | awk '{print $3}'`; do
259 # If multipath check which type of devices are given, mpath prefered
260 if [ -f /etc/multipath.conf ]; then
261 i=`GiveMapperOfdm $d`
262 rep=$i
263 else
264 rep=$d
265 fi
266 skip=0
267 if [ "$MINDI_EXCLUDE_DEVS" ] ; then
268 for ed in `echo $MINDI_EXCLUDE_DEVS | sed 's/|/ /g'`; do
269 if [ "`echo " $rep " | grep " $ed"`" != "" ]; then
270 skip=1
271 continue
272 fi
273 done
274 fi
275 if [ $skip -eq 1 ]; then
276 continue
277 fi
278 echo $rep
279 done
280}
281
282
283
284PrettifyList() {
285 local i
286 echo -en "$1"
287 for i in $2 ; do
288 echo -en "$i "
289 done
290 echo ""
291}
292
293ListAllLogicalVolumesSortedBydm() {
294 for d in `ListAllLogicalVolumes` ; do
295 dm=`mindi --readalllink $d | tail -1`
296 echo "$dm|$d" >> $MINDI_TMP/sorteddm
297 done
298 sort -t'|' $MINDI_TMP/sorteddm | cut -d'|' -f2
299}
300
301ListAllLogicalVolumes() {
302 if [ $lvmversion = 2 ]; then
303 $LVMCMD lvscan 2> /dev/null | grep "'" | grep -iw "ACTIVE" | cut -d"'" -f2
304 else
305 lvscan 2> /dev/null | grep '"' | grep -iw "ACTIVE" | cut -d'"' -f2
306 fi
307}
308
309
310
311WriteShutdownScript() {
312 local i
313 echo ""
314 echo "Finally, to shut down and delete the volumes, do this:-"
315 for i in `ListAllLogicalVolumes` ; do
316 echo "($LVMCMD lvremove -f $i)"
317 done
318 for i in `ListAllVolumeGroups` ; do
319 echo "($LVMCMD vgchange -a n $i)"
320 done
321 for i in `ListAllVolumeGroups` ; do
322 echo "($LVMCMD vgremove $i)"
323 done
324 if [ $lvmversion = 2 ]; then
325 echo "(rmmod dm-mod & rmmod dm_mod & )"
326 else
327 echo "(rmmod lvm-mod)"
328 fi
329}
330
331
332
333# -------------------------------- main -----------------------------------
334
335if [ "$1" = "--givemapperofdm" ] ; then
336 shift
337 if [ _"$1" != _"" ] ; then
338 GiveMapperOfdm $1
339 fi
340 exit 0
341fi
342
343
344which lvmdiskscan 2>/dev/null 2>&1 || Die "lvmdiskscan not found. Won't handle LVM."
345if [ -e "/proc/lvm/global" ] && [ "`tr -s '\t' ' ' < /proc/lvm/global | grep "0 VGs 0 PVs 0 LVs"`" != "" ]; then
346 exit 1
347fi
348
349if [ _"$MINDI_TMP" = _"" ]; then
350 # Launched stdalone, so create a temp dir
351 STDALONE="true"
352 MINDI_TMP=`mktemp -d $TMPDIR/mindi.XXXXXXXXXX`
353 if [ $? -ne 0 ]; then
354 df $TMPDIR
355 Die "Unable to create a temporary directory ! Check space on $TMPDIR"
356 fi
357 if [ _"$MINDI_TMP" = _"" ]; then
358 Die "MINDI_TMP is empty, aborting"
359 fi
360 if [ _"$MINDI_TMP" = _"/" ]; then
361 Die "MINDI_TMP is /, aborting"
362 fi
363fi
364
365# Older lvmdiskscan use --help, newer --version
366lvmopt="--help"
367lvmdiskscan $lvmopt 2>&1 | grep -q -- "--version"
368if [ $? -eq 0 ]; then
369 lvmopt="--version"
370fi
371
372
373lvmversion=`lvmdiskscan --help 2>&1 |
374 grep -E "Logical Volume Manager|LVM version:" |
375 cut -d: -f2 | cut -d. -f1 |
376 awk '{print $NF}' |
377 sed -e 's/ //g'`
378
379if which lvm 2>/dev/null; then
380 version=`lvm version 2> /dev/null | grep "LVM version" | awk '{print $3}'`
381 i="`echo "$version" | cut -d'.' -f1`"
382 echo "i=$i"
383 if [ "$i" -ge "2" ] ; then
384 lvmversion=2
385 fi
386fi
387
388if [ $lvmversion = 2 ]; then
389 echo "LVM version >= 2.0 found."
390 LVMCMD="lvm"
391else
392 LVMCMD=""
393fi
394
395rm -f $MINDI_TMP/excludedvgs
396all_lvm_drives_and_partitions=`ListLvmDrivesAndPartitions`
397echo "Just before you extrapolate mountlist to include RAID partitions,"
398echo "extrapolate it to include the following LVM drives and partitions:-"
399PrettifyList ">>>>> " "$all_lvm_drives_and_partitions"
400echo "To get started, type:-"
401if [ $lvmversion = 2 ]; then
402 echo "(insmod dm-mod)"
403 echo "(insmod dm_mod)"
404else
405 echo "(insmod lvm-mod)"
406fi
407echo "# $LVMCMD vgchange -an"
408for i in `ListAllPhysicalVolumes` ; do
409 echo "# echo y | $LVMCMD pvcreate -ff $i"
410done
411echo "# $LVMCMD vgscan"
412echo ""
413echo "Create and activate the VG's (volume groups)."
414all_volume_groups=`ListAllVolumeGroups`
415for current_VG in $all_volume_groups ; do
416 if [ $lvmversion -ne 2 ]; then
417 echo "# rm -Rf /dev/$current_VG"
418 fi
419 ProcessVolumeGroup $current_VG
420done
421echo ""
422echo "Finally, create the LV's (logical volumes)."
423all_logical_volumes=`ListAllLogicalVolumesSortedBydm`
424for current_LV in $all_logical_volumes ; do
425 ProcessLogicalVolume $current_LV
426done
427echo ""
428echo "# $LVMCMD vgscan"
429echo "Now you may format the LV's:-"
430for i in `ListAllLogicalVolumes` ; do
431 echo "(mkfs -t foo $i or something like that)"
432done
433rm -f $MINDI_TMP/excludedvgs
434WriteShutdownScript
435if [ _"$STDALONE" = _"true" ]; then
436 rm -rf $MINDI_TMP
437fi
438exit 0
439
440
441
Note: See TracBrowser for help on using the repository browser.