umount_usb(){ mnt=`df -h | grep /root/usb | wc -l` count=0 while [ $mnt -eq 1 -a $count -le 5 ] do umount -f /root/usb/ mnt=`df -h | grep /root/usb | wc -l` count=`expr $count + 1` sleep 1 if [ $count -ge 5 ];then exit fi done } umount_usb echo -e "d\n1\nd\n2\nd\n3\nd\n4\n\nw" | fdisk /dev/sda sleep 1 echo -e "n\np\n1\n1\n\nw" | fdisk /dev/sda sleep 1 umount_usb if [ $1 == "ext4" ];then echo -e "\ny" | mkfs.ext4 -T largefile /dev/sda1 sleep 1 mount -t ext4 /dev/sda1 /root/usb else mkfs.vfat -F 32 /dev/sda1 sleep 1 mount -t vfat /dev/sda1 /root/usb fi