source: MondoRescue/branches/3.2/mondo/src/restore-scripts/mondo/mr-make-me-bootable@ 3542

Last change on this file since 3542 was 3542, checked in by Bruno Cornec, 8 years ago
  • Rename all mondorestore scripts with the mr- prefix and adapt callers
  • Place these scripts in /usr/bin on the restore media
  • Fix a mindi bug where these scripts were not copied anymore with previous modifications around removal of cd
  • Property svn:keywords set to Id
  • Property svn:unix-mode set to 755
File size: 1.9 KB
Line 
1#!/bin/sh
2#
3# $Id: mr-make-me-bootable 3542 2016-03-24 16:48:03Z bruno $
4#
5
6
7if [ "$#" -ne "2" ] && [ "$#" -ne "3" ] ; then
8 echo "mr-make-me-bootable <fname> <drive> [noaction]"
9 exit 1
10fi
11
12drivetouse=$2
13boot_drv=""
14boot_part=""
15root_drv=""
16root_part=""
17if [ ! "$LOGFILE" ]; then
18 LOGFILE="/tmp/mondorestore2.log"
19fi
20dummy="$3"
21
22activepart=`mr-parted2fdisk -l $drivetouse 2>/dev/null | tr -s '\t' ' ' | grep "$drivetouse" | grep '*' | cut -d' ' -f1`
23
24for i in `cat $1 | tr -s '\t' ' ' | cut -d' ' -f1 | grep -vE "/dev/fd|none|#"` ; do
25 # Warning wrong if LVM !
26 drive=`echo $i | sed -e 's/[0-9]*$//' -e 's/\([0-9]\)p$/\1/'`
27 if [ "$drivetouse" = "$drive" ]; then
28 # We can continue as this is the drive we ned to work on
29 partno=`echo $i | sed -e 's/^.*[^0-9]\([0-9]*\)$/\1/'`
30 mountpt=`grep "$i " $1 | tr -s '\t' ' ' | cut -d' ' -f2`
31
32 if [ "$mountpt" = "/" ] ; then
33 root_drv=$drive
34 root_part=$partno
35 elif [ "$mountpt" = "/boot" ] ; then
36 boot_drv=$drive
37 boot_part=$partno
38 fi
39 fi
40done
41
42if [ "$boot_drv" ] ; then
43 drive=$boot_drv
44 partno=$boot_part
45elif [ "$root_drv" ] ; then
46 drive=$root_drv
47 partno=$root_part
48else
49 driveline=`grep -E '[ ]/boot[ ]' $1`
50 [ ! "$driveline" ] && driveline=`grep -E '[ ]/[ ]' $1`
51 partno=`echo "$driveline" | cut -d' ' -f1 | awk -F "[a-z]" '{print $NF;}'`
52# echo "driveline=$driveline --> partno=$partno"
53fi
54
55if [ "$drive" ] ; then
56 if [ "$partno" = "0" ] || [ ! "$partno" ] ; then
57 partno="1"
58 fi
59 cmd=""
60 for p in "$activepart"; do
61 # First desactivate active partitions (coming from previous usage)
62 cmd="${cmd}a\n$p\n"
63 if [ "$dummy" != "" ] ; then
64 echo "Will desactivate $p on $drive" >> $LOGFILE
65 fi
66 done
67 # Then activate the one which should
68 if [ "$dummy" != "" ] ; then
69 echo "Would activate $partno on $drive" >> $LOGFILE
70 else
71 echo -en "${cmd}a\n$partno\np\nw\n" | mr-parted2fdisk $drive >> $LOGFILE 2>> $LOGFILE
72 fi
73fi
74exit 0
Note: See TracBrowser for help on using the repository browser.