1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # $Id: mr-make-me-bootable 3542 2016-03-24 16:48:03Z bruno $
|
---|
4 | #
|
---|
5 |
|
---|
6 |
|
---|
7 | if [ "$#" -ne "2" ] && [ "$#" -ne "3" ] ; then
|
---|
8 | echo "mr-make-me-bootable <fname> <drive> [noaction]"
|
---|
9 | exit 1
|
---|
10 | fi
|
---|
11 |
|
---|
12 | drivetouse=$2
|
---|
13 | boot_drv=""
|
---|
14 | boot_part=""
|
---|
15 | root_drv=""
|
---|
16 | root_part=""
|
---|
17 | if [ ! "$LOGFILE" ]; then
|
---|
18 | LOGFILE="/tmp/mondorestore2.log"
|
---|
19 | fi
|
---|
20 | dummy="$3"
|
---|
21 |
|
---|
22 | activepart=`mr-parted2fdisk -l $drivetouse 2>/dev/null | tr -s '\t' ' ' | grep "$drivetouse" | grep '*' | cut -d' ' -f1`
|
---|
23 |
|
---|
24 | for 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
|
---|
40 | done
|
---|
41 |
|
---|
42 | if [ "$boot_drv" ] ; then
|
---|
43 | drive=$boot_drv
|
---|
44 | partno=$boot_part
|
---|
45 | elif [ "$root_drv" ] ; then
|
---|
46 | drive=$root_drv
|
---|
47 | partno=$root_part
|
---|
48 | else
|
---|
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"
|
---|
53 | fi
|
---|
54 |
|
---|
55 | if [ "$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
|
---|
73 | fi
|
---|
74 | exit 0
|
---|