- 论坛徽章:
- 0
|
我用的脚本, autodisk /dev/hdc /Data 自动分区格式化 mount 到 /Data
#!/bin/sh
echo "is this right? $0 $1 $2"
FDISK=/sbin/fdisk
GREP=/bin/grep
PARTED=/sbin/parted
TUNE2FS=/sbin/tune2fs
MKREISERFS=/sbin/mkreiserfs
CUT=/bin/cut
SEQ=/bin/seq
MOUNT_POINT=$2
PARTITIONNAME=$11
FILE_FLAG=$MOUNT_POINT/.formated.ok
FLAG_STRING="init ok"
HDA="/dev/hda"
if [ "$HDA" = "$1" ]; then
echo dont use $1 please;
exit 0;
fi
if mount|grep $MOUNT_POINT; then
echo $MOUNT_POINT has been mounted, please umount it first!
exit 0;
fi
if $FDISK -l $1| $GREP $1>/dev/null; then
echo disk $1 found !
else
echo no disk $1 !
exit 0;
fi
function mount_and_init {
if mount $PARTITIONNAME $MOUNT_POINT; then
echo "$FLAG_STRING">$FILE_FLAG
echo partition $PARTITIONNAME mount to $MOUNT_POINT is ready now!
else
echo mount failed!
fi
}
function mkpart_ext2 {
echo $PARTED $1 mkpartfs primary ext2 $2 $3
$PARTED $1 mkpartfs primary ext2 $2 $3
mount_and_init $1
}
function mkpart_ext3 {
echo $PARTED $1 mkpartfs primary ext2 $2 $3
$PARTED $1 mkpartfs primary ext2 $2 $3
$TUNE2FS -j -c 0 -i 0 $PARTITIONNAME
mount_and_init $1
}
function mkpart_reiserfs {
echo $PARTED $1 mkpart primary $2 $3
$PARTED $1 mkpart primary $2 $3>/dev/null
echo y|$MKREISERFS $PARTITIONNAME>/dev/null
mount_and_init $1
}
function mkpart {
mkpart_reiserfs $1 $2 $3
}
function remkpart {
echo repartition it now...
for i in `$SEQ 20 1`; do
$PARTED $1 rm $i>/dev/null
done
mkpart $1 $2 $3
}
echo "check partion $11, if not exist, create a temp partion"
if $FDISK -l $1| $GREP $11; then
echo "find partion $11">/dev/null
else
echo "make a temp partion so parted can get disk size"
$PARTED $1 mkpart primary 0 100 >/dev/null
fi
STARTSIZE=0
# for old parted, output is like : Disk geometry for /dev/hdc: 0.000-38901.125 megabytes
# for new parted, output is like : Disk /dev/hdc: 40.1GB
#STOPSIZE=`$PARTED $1 print | $GREP megabytes | $CUT -d: -f 2| $CUT -d- -f2|$CUT -d' ' -f1`
STOPSIZE=`$PARTED $1 unit MB print | $GREP $1 | $CUT -d: -f 2| $CUT -dM -f1`
echo $1 size is $STOPSIZE MB
echo mount $PARTITIONNAME to /Data , and check if has file $FILE_FLAG
echo if so, everything is ok
echo or remove all partitions on it, and create one ext2 partition,
echo and mount it to /Data, and write "$FLAG_STRING" to $FILE_FLAG
echo now check $PARTITIONNAME
if $FDISK -l $1| $GREP $11; then
echo $11 exist, mount it to $MOUNT_POINT and check it
if mount $PARTITIONNAME $MOUNT_POINT; then
if $GREP "$FLAG_STRING" $FILE_FLAG; then
echo partition is ok!
else
echo no $FILE_FLAG or no "$FLAG_STRING" in $FILE_FLAG, maybe not seye disk
umount $MOUNT_POINT
remkpart $1 $STARTSIZE $STOPSIZE
fi
else
echo mount $11 to $MOUNT_POINT failed, maybe bad partition.
remkpart $1 $STARTSIZE $STOPSIZE
fi
else
echo no partition $11 , now create partition $11;
mkpart $1 $STARTSIZE $STOPSIZE
fi |
|