source: MondoRescue/branches/2.2.9/mondo/src/restore-scripts/mondo/format-and-kludge-vfat@ 2186

Last change on this file since 2186 was 2186, checked in by Bruno Cornec, 15 years ago

Adds support of special partiion names (ida, cciss, mapth) for format-and-kludge-vfat

  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1#!/bin/sh
2#
3# MondoRescue script: format-and-kludge-vfat
4#
5# $1 = device, e.g. /dev/hda1
6#
7# This script requires parted and ms-sys
8#
9
10LogIt() {
11 echo "$1" >> /dev/stderr
12}
13
14
15ExitHere() {
16 echo "Exiting here for testing. "
17 exit 1
18}
19
20Die() {
21 LogIt "(format-and-kludge-vfat) $1" 1
22 cat /tmp/fakv.log
23 exit 1
24}
25
26GetPartitionFdiskType() {
27 local drive device ftype
28 device=$1
29 drive=$2
30 ftype=`parted2fdisk -l $drive | grep $device | tr '*' ' ' | tr -s '\t' ' ' | cut -d' ' -f5`
31 case $ftype in
32# "b" | "c")
33# the above is correct but mondorestore creates partition with FAT12, so:
34 "b" | "c" | "1")
35 echo "fat32"
36 ;;
37 "4" | "e")
38 echo "fat16"
39 ;;
40 *)
41 Die "Error: Unsuitable partition type $ftype (or device $device doesn't exist)"
42 ;;
43 esac
44 exit 0
45}
46
47
48# -------------- main ------------
49
50LogIt "format-and-kludge-vfat --- starting"
51
52touch /tmp/fakv.log
53
54if [ "$#" -eq "2" ] ; then
55 LogIt "Note: Script called with two parameters. Only one needed - the device." 1
56 LogIt " Embleer files are gorn - please ask DevTeam to update his code. ;-)" 1
57elif [ "$#" -ne "1" ] ; then
58 LogIt "Usage: format-and-kludge-vfat <device>" 1
59 exit 1
60fi
61
62retval=0
63
64device=$1
65echo $device | grep -Eq "/cciss/|/mapper/|/ida/"
66if [ $? -eq "0" ]; then
67 drive=`echo $device | sed s/[0-9p]*[0-9]//`
68else
69 drive=`echo $drive | sed s/[0-9]*[0-9]//`
70fi
71partition=`echo $device | sed s\%$drive\%\%`
72
73type=`GetPartitionFdiskType $device $drive`
74res=$?
75retval=$(($retval+$res))
76if [ "$res" -ne "0" ]; then
77 exit 1
78fi
79LogIt "Formatting device $device (drive $drive, partition $partition, type $type)" 2
80parted $drive mkfs $partition $type 2> /tmp/fakv.log > /dev/null
81res=$?
82retval=$(($retval+$res))
83if [ "$res" -ne "0" ]; then
84 LogIt "Errors occurred while formatting $device!" 1
85 cat /tmp/fakv.log
86 exit 1
87fi
88if [ "$device" != "/dev/hda1" ] && [ "$device" != "/dev/sda1" ] ; then
89 LogIt "OK, this is not /dev/hda1 or /dev/sda1; so, I shan't kludge it." 1
90 exit 0
91fi
92LogIt "Setting the boot flag for $device" 2
93parted $drive set $partition boot on 2> /tmp/fakv.log > /dev/null
94res=$?
95retval=$(($retval+$res))
96if [ "$res" -ne "0" ]; then
97 LogIt "Errors occurred while setting the boot flag for $device!" 1
98 cat /tmp/fakv.log
99 exit 1
100fi
101if [ "`uname -m`" != "ia64" ] ; then
102 LogIt "Fixing the boot block of $device with ms-sys" 2
103 ms-sys -w $device 2> /tmp/fakv.log > /dev/null
104 res=$?
105 retval=$(($retval+$res))
106 if [ "$res" -ne "0" ]; then
107 LogIt "Errors occurred while fixing the boot block of $device!" 1
108 cat /tmp/fakv.log
109 exit 1
110 fi
111fi
112[ ! -e "/mnt/tmpK" ] && mkdir /mnt/tmpK
113mount $device -t vfat /mnt/tmpK || Die "Can't mount device $device"
114size=`df -m -P /mnt/tmpK | tr -s ' ' ' ' | cut -d' ' -f2 | tail -n 1`
115umount /mnt/tmpK || Die "Can't unmount /mnt/tmpK"
116
117ideal_size=`grep "$device " /tmp/mountlist.txt | tr -s ' ' ' ' | cut -d' ' -f4`
118if [ "$ideal_size" = "" ]; then
119 LogIt "format-and-kludge-vfat --- can't find $device in mountlist" 1
120 exit 0
121fi
122LogIt "ideal_size = $ideal_size" 2
123ideal_size=$(($ideal_size/1024))
124difference=$(($ideal_size-$size))
125[ "$difference" -lt "0" ] && difference=$(((-1)*$difference))
126LogIt "ideal_size=$ideal_size; size=$size; difference=$difference"
127if [ "$difference" -gt "64" ] ; then
128 retval=$(($retval+1))
129 LogIt "(format-and-kludge-vfat-new) Size mismatch. Did kludge work?" 1
130else
131 LogIt "Size matches. (Well, nearly.) Good." 2
132fi
133
134if [ "$retval" -eq "0" ] ; then
135 LogIt "$device was successfully formatted and prepared" 1
136else
137 LogIt "$device failed to be formatted and prepared" 1
138 cat /tmp/fakv.log
139fi
140LogIt "(by format-and-kludge-vfat)"
141
142LogIt "format-and-kludge-vfat --- leaving (retval=$retval)"
143exit $retval
Note: See TracBrowser for help on using the repository browser.