>>> 此貼的回復 >> #---------------------choice disk start----------------# if [ "$(fdisk /dev/hda -l)" ]; then TMP="hda" HD_DEVICE="/dev/hda" elif [ "$(fdisk /dev/hdb -l)" ]; then TMP="hdb" HD_DEVICE="/dev/hdb" elif [ "$(fdisk /dev/hdc -l)" ]; then TMP="hdc" HD_DEVICE="/dev/hdc" else echo "Error: Unable open the hard disk, please check it!" exit 1 fi #---------------------choice disk end----------------#
HD_SIZE=`fdisk ${HD_DEVICE} -s`
echo -n "Do you want to continue? [yes/no] " read ANSWER case ${ANSWER} in y | yes ) ;; * ) echo "Exit linux restore." exit 3 ;; esac
#---------------------unmount all partions start----------------# echo "unmount all partions..." PARTLIST=`fdisk ${HD_DEVICE} -l | grep "${HD_DEVICE}[[:digit:]]" | cut -d ' ' -f 1 | sed s/^.*${TMP}//` for i in $PARTLIST; do umount ${HD_DEVICE}$i &> /dev/null done #---------------------unmount all partions end----------------#
#free your swap OLD_SWAP=`fdisk -l | grep -w "Linux swap" | cut -d" " -f1` if [ $OLD_SWAP ]; then swapoff $OLD_SWAP 2> /dev/null fi
#---------------------Remving all partitions start----------------# echo "Remving all partitions..." parted -s ${HD_DEVICE} mklabel msdos for ik in $PARTLIST; do if [ $ik = 4 ] then #[Leon]: skip extended partions continue fi #remove primary and logical partions parted -s ${HD_DEVICE} rm $ik &> /dev/null done #remove extended partions parted -s ${HD_DEVICE} rm 4 &> /dev/null #---------------------Remving all partitions end----------------#
echo "After removing all partions: " parted ${HD_DEVICE} print
echo "The system will restore linux to the hard disk." echo "This process may need 5 minutes , you can have a rest and enjoy your coffee." echo echo "Creating partitions ..."
#---------------------Creating partitions start-----------------------------------# HD_SIZE=`expr ${HD_SIZE} / 1000` HD_SIZE=`expr ${HD_SIZE} - 1500`
#create primary partitions #1./boot partitions ${HD_DEVICE}1 parted ${HD_DEVICE} mkpart primary ext3 0.031 101.975 > /dev/null mkfs.ext3 ${HD_DEVICE}1 > /dev/null
#2. /root partitions ${HD_DEVICE}2 parted ${HD_DEVICE} mkpart primary ext3 101.975 2048.000 > /dev/null mkfs.ext3 ${HD_DEVICE}2 > /dev/null