[1] | 1 | #!/bin/sh
|
---|
[3542] | 2 | #
|
---|
| 3 | # $Id: mr-make-me-bootable 3542 2016-03-24 16:48:03Z bruno $
|
---|
| 4 | #
|
---|
[1] | 5 |
|
---|
| 6 |
|
---|
[3057] | 7 | if [ "$#" -ne "2" ] && [ "$#" -ne "3" ] ; then
|
---|
[3542] | 8 | echo "mr-make-me-bootable <fname> <drive> [noaction]"
|
---|
[1] | 9 | exit 1
|
---|
| 10 | fi
|
---|
| 11 |
|
---|
[3057] | 12 | drivetouse=$2
|
---|
[1] | 13 | boot_drv=""
|
---|
| 14 | boot_part=""
|
---|
| 15 | root_drv=""
|
---|
| 16 | root_part=""
|
---|
[3057] | 17 | if [ ! "$LOGFILE" ]; then
|
---|
| 18 | LOGFILE="/tmp/mondorestore2.log"
|
---|
| 19 | fi
|
---|
| 20 | dummy="$3"
|
---|
[1] | 21 |
|
---|
[3377] | 22 | activepart=`mr-parted2fdisk -l $drivetouse 2>/dev/null | tr -s '\t' ' ' | grep "$drivetouse" | grep '*' | cut -d' ' -f1`
|
---|
[3057] | 23 |
|
---|
[680] | 24 | for i in `cat $1 | tr -s '\t' ' ' | cut -d' ' -f1 | grep -vE "/dev/fd|none|#"` ; do
|
---|
[2196] | 25 | # Warning wrong if LVM !
|
---|
[1] | 26 | drive=`echo $i | sed -e 's/[0-9]*$//' -e 's/\([0-9]\)p$/\1/'`
|
---|
[3057] | 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`
|
---|
[1] | 31 |
|
---|
| 32 | if [ "$mountpt" = "/" ] ; then
|
---|
| 33 | root_drv=$drive
|
---|
[3057] | 34 | root_part=$partno
|
---|
[1] | 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
|
---|
[911] | 49 | driveline=`grep -E '[ ]/boot[ ]' $1`
|
---|
| 50 | [ ! "$driveline" ] && driveline=`grep -E '[ ]/[ ]' $1`
|
---|
[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
|
---|
[3057] | 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
|
---|
[1] | 68 | if [ "$dummy" != "" ] ; then
|
---|
[3071] | 69 | echo "Would activate $partno on $drive" >> $LOGFILE
|
---|
[3057] | 70 | else
|
---|
[3377] | 71 | echo -en "${cmd}a\n$partno\np\nw\n" | mr-parted2fdisk $drive >> $LOGFILE 2>> $LOGFILE
|
---|
[3057] | 72 | fi
|
---|
[1] | 73 | fi
|
---|
| 74 | exit 0
|
---|