source: MondoRescue/branches/2.2.10/mondo/src/restore-scripts/mondo/grub-MR@ 2696

Last change on this file since 2696 was 2696, checked in by Bruno Cornec, 13 years ago
  • Adds preliminary support for hpacucli. Needs test
  • Fix a compilation issue due to bad fatal_error call (no param allowed)
  • Fix some HTML syntax issues in the docs page + link to Wiki articles
  • Boot size pushed to 20MB
  • A bit more precise for error msg from PBDI
  • Exits if the protocol used is not recognized (error with -n fs:// typo)
  • Adds support for r8169 net driver
  • Fix a cast issue
  • Precise a test case to avoid ambiguity
  • Die and related functions placed before any other code as used early, and ash doesn't support function declaration. So will solve #446 by exiting mindi before doing anything weird in it.
  • Fix #445 with another technical solution to avoid vg with similar names to b wrongly excluded (vgroot and vgroot-san e.g.) (Michael Shapiro)
  • Fix a bug on exclusion of path with common content (/home and /path/home e.g.) which was handled correctly only in a certain order (John Pearson <johnp_at_gtagalenco.com.au>)
  • mount-media function is now placed in libmondo-devices.c as used by more programs.
  • Avoids calling mount_media when it's not mandatory (change the way mondorestore was working up to now but could solve some bugs reported)
  • Add xhci support to mindi.
  • Rewrite Xen kernel support to use TryToFindKernelPath systematically.
  • mindi now copies also the /lib/firmware content in order to have it for drivers needing it (bnx2 reported)
  • Push MAX_STR_LEN to 512 to allow supporting more exclude dir (2.2.10 and dyn allocation is the way to go there)
  • Add virtio driver to mindi
  • Initialize extra_cdrom_params in any case tp avoid passing null to cdrecord later on
  • Also escapes white spaces in gen_aux_list to avoid issues in getfacl call
  • Adds multiple missing drivers to mindi (mega_sr, ide_gd_mod, pata_jmicron, cp210x, dca, raid6_pq, xor async_tx, async_memcpy, async_xor)
  • Fix #434 by really testing thet udevd is not running already (chucky)
  • Adds support of pata_sil680 driver
  • Fix again #412 !! by removing calls to tee which voids the return value of the previous command
  • The way grub.unsupported was called for opensuse 11.2 was wrong. It should be done bfore calling grub-install which also exists. And tested for existence. Now this should fix #412.
  • Try to provide a workaround in code to the #401 (over-allocation of space due to rounding errors)
  • Fix a bug when using ACLs and file with spaces in their names by adding double quotes in getfacl invocation (Tom Mortell tomm_at_dslextreme.com). Also adding the same quotes on the touch commands made earlier.
  • Points to the current latest presentation instead of the old one
  • mondo-ref-card added to the docs web page
  • Add the mondoarchive reference card (Lester Wade)
  • Change useless comments for more useful ones
  • mindi is now able to handle compressed kernel with .gz or .bz2 suffix (case of OpenSuSE 11.2)
  • Improves logging for external binary
  • Improve Xen kernel detection and avoid false detection (Michael Shapiro)
  • Updated P2V doc from Lester Wade (lester.wade_at_hp.com)

Baclports from 2.2.9
svn merge -r 2650:2695 svn+ssh://bruno@svn.mondorescue.org/mondo/svn/mondorescue/branches/2.2.9 .

  • Property svn:keywords set to Id
  • Property svn:unix-mode set to 755
File size: 5.4 KB
Line 
1#!/bin/sh
2#
3# $Id: grub-MR 2696 2011-01-25 09:34:40Z bruno $
4#
5# grub-MR ------ a rudimentary replacement for grub-install
6#
7#
8
9Die() {
10 echo "$1" >> /dev/stderr
11 exit 1
12}
13
14
15FindBootPart() {
16 local i
17 bootpart=""
18 BOOTPATHNAME=""
19 for sz in /boot / ; do
20 bootpart=`grep " $sz " $2 | cut -d' ' -f1 | head -n1`
21 [ "$bootpart" ] && [ -e "/mnt/RESTORING/$bootpart" ] && break
22 done
23 [ ! "$bootpart" ] && Die "Cannot find boot partition in mountlist"
24
25 if [ "$sz" = "/boot" ] ; then
26 BOOTPATHNAME=/grub
27 else
28 BOOTPATHNAME=/boot/grub
29 fi
30 if [ -e "$MNT_RESTORING/boot/grub/stage1" ] ; then
31 echo "Alright then."
32 return
33 fi
34
35 cd $MNT_RESTORING
36 for i in usr/lib/grub/* ; do
37 echo "Checking $i"
38 if [ -e "$i/stage1" ] ; then
39 BOOTPATHNAME=/$i
40 mkdir -p /boot/grub
41 cp -au $i/* /boot/grub/
42 echo "BOOTPATHNAME is now $BOOTPATHNAME"
43 return 0
44 fi
45 done
46 cd /
47 echo "Cannot find BOOTPATHNAME"
48 return 1
49}
50
51FindPathOfRESTExe() {
52 local path
53 for path in /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin \
54/bin /sbin ; do
55 if [ -f "/mnt/RESTORING/$path/$1" ] ; then
56 echo "/mnt/RESTORING/$path/$1"
57 return
58 fi
59 done
60 which grub
61}
62
63
64try_grub_hack() {
65 local driveno extraline partno
66 driveno=$1
67 partno=$2
68 extraline="$3"
69
70 echo -en "\
71 device (hd$driveno) $mbrdev\n\
72 $extraline\n\
73 root (hd$driveno,$partno)\n\
74 setup (hd$driveno)\n\
75 quit \n" > /tmp/feed.txt
76 cat /tmp/feed.txt
77 log_file=/tmp/grub.output
78 if [ "$MNT_RESTORING" ] ; then
79 chroot $MNT_RESTORING grub --batch < /tmp/feed.txt > $log_file
80 else
81 grub --batch < /tmp/feed.txt > $log_file
82 fi
83 cat $log_file
84 if grep "Error [0-9]*: " $log_file >/dev/null; then
85 return 1
86 else
87 return 0
88 fi
89}
90
91
92# ---------------------------------- main -----------------------------------
93
94if [ "$#" -ne "2" ] ; then
95 Die "grub-MR <MBR drive> <mountlist filename>; e.g. grub-MR /dev/hda $MINDI_CACHE/mountlist.txt"
96fi
97[ ! -f "$2" ] && Die "mountlist file not found"
98
99if [ -e "/mnt/RESTORING/boot" ] ; then
100 MNT_RESTORING=/mnt/RESTORING
101else
102 MNT_RESTORING=""
103fi
104
105# For some OpenSuSE
106res=1
107if [ "$MNT_RESTORING" ] ; then
108 if [ -x $MNT_RESTORING/usr/sbin/grub-install.unsupported ]; then
109 echo "Now I'll use grub-install.unsupported in chroot" >> $LOGFILE
110 chroot $MNT_RESTORING /usr/sbin/grub-install.unsupported $1 >> $LOGFILE 2>> $LOGFILE
111 res=$?
112 echo "grub-install.unsupported in chroot returned $res" >> $LOGFILE
113 fi
114else
115 if [ -x /usr/sbin/grub-install.unsupported ]; then
116 echo "Now I'll use grub-install.unsupported locally" >> $LOGFILE
117 /usr/sbin/grub-install.unsupported $1 >> $LOGFILE 2>> $LOGFILE
118 res=$?
119 echo "grub-install.unsupported returned $res" >> $LOGFILE
120 fi
121fi
122[ "$res" -eq "0" ] && exit 0
123
124echo "Now I'll use grub-install" >> $LOGFILE
125if [ "$MNT_RESTORING" ] ; then
126 chroot $MNT_RESTORING grub-install $1 >> $LOGFILE 2>> $LOGFILE
127 res=$?
128else
129 grub-install $1 >> $LOGFILE 2>> $LOGFILE
130 res=$?
131fi
132echo "grub-install returned $res" >> $LOGFILE
133[ "$res" -eq "0" ] && exit 0
134
135echo "Trying a hack" >> $LOGFILE
136FindBootPart $1 $2 2>&1 | tee -a $LOGFILE
137mbrdev=`echo $1 | sed 's/\([^0-9]*\)[0-9]*$/\1/'`
138if echo $bootpart | grep "/cciss/" > /dev/null ; then
139 partno=`basename $bootpart | cut -d'p' -f2`
140 mbrdev=`echo $mbrdev | cut -d'p' -f1`
141elif echo $bootpart | grep "/mapper/mpath" > /dev/null ; then
142 partno=`basename $bootpart | cut -d'p' -f3`
143 mbrdev=`echo $mbrdev | cut -d'p' -f1`
144else
145 partno=`basename $bootpart | sed 's/[a-z]*//'`
146fi
147if [ ! "$partno" ] ; then
148 partno=0
149else
150 partno=$(($partno-1))
151fi
152if echo $bootpart | grep "/md" > /dev/null ; then
153 # FIXME: Why this if not used later
154 base=`basename $bootpart`
155 line=`grep $base /proc/mdstat | head -n1`
156 echo "mbrdev was $mbrdev" 2>&1 | tee -a $LOGFILE
157 mbrdev=`parted2fdisk -l | grep /dev/ | head -n1 | tr ':' ' ' | cut -d' ' -f2`
158 echo "mbrdev is $mbrdev" 2>&1 | tee -a $LOGFILE
159 partno="0"; # cheating - FIXME
160fi
161echo ".............Cool." 2>&1 | tee -a $LOGFILE
162
163grub=`FindPathOfRESTExe grub`
164mkdir -p /boot
165[ "$MNT_RESTORING" ] && ln -sf /mnt/RESTORING/boot/grub /boot/grub
166
167# ---------------------------------
168
169for driveno in 0 1 2 ; do
170 try_grub_hack $driveno $partno "" >> $LOGFILE 2>> $LOGFILE && break
171 try_grub_hack $driveno $partno "find $BOOTPATHNAME/stage1" >> $LOGFILE 2>> $LOGFILE && break
172done
173res=$?
174echo "Hack returned res=$res" >> $LOGFILE
175[ "$res" -eq "0" ] && exit 0
176
177# ---------------------------------
178
179echo "Now I'll use grub-install.patched" >> $LOGFILE
180cp -f `which grub-install.patched` /mnt/RESTORING/sbin
181chroot /mnt/RESTORING grub-install.patched $1 >> $LOGFILE 2>> $LOGFILE
182res=$?
183echo "grub-install.patched returned $res" >> $LOGFILE
184[ "$res" -eq "0" ] && exit 0
185
186# ---------------------------------
187
188if [ -f "/mnt/RESTORING/boot/grub/menu.lst" ]; then
189 grep -vE '^#' /boot/grub/menu.lst > /mnt/RESTORING/tmp/grub.conf
190elif [ -f "/mnt/RESTORING/boot/grub/grub.cfg" ]; then
191 grep -vE '^#' /boot/grub/grub.cfg > /mnt/RESTORING/tmp/grub.conf
192else
193 echo "Unable to find Grub conf file" | tee -a $LOGFILE
194 exit -1
195fi
196echo "Trying to use the existing grub conf file in batch mode" >> $LOGFILE
197cat /mnt/RESTORING/tmp/grub.conf >> $LOGFILE
198chroot /mnt/RESTORING grub --batch < /mnt/RESTORING/tmp/grub.conf
199res=$?
200echo "grub conf file approach returned $res" >> $LOGFILE
201rm -f /mnt/RESTORING/tmp/grub.conf
202[ "$res" -eq "0" ] && exit 0
203
204echo "grub-MR returned res=$res" >> $LOGFILE
205
206exit $res
Note: See TracBrowser for help on using the repository browser.