Chinaunix首页 | 论坛 | 博客
  • 博客访问: 138405
  • 博文数量: 33
  • 博客积分: 15
  • 博客等级: 民兵
  • 技术积分: 42
  • 用 户 组: 普通用户
  • 注册时间: 2012-09-22 10:23
个人简介

嵌入式带动整个社会!

文章分类
文章存档

2015年(4)

2014年(15)

2013年(8)

2012年(6)

分类: LINUX

2013-06-21 11:11:41

  1. #!/bin/sh

  2. #屏蔽信号
  3. #trap '' 2 20

  4. #日志开关
  5. DEBUG=1
  6. [ $DEBUG -eq 1 ] && LOG="/tmp/log" || LOG="/dev/null"

  7. #打印等待提示
  8. echo_fun(){
  9.     echo ""
  10.     echo -n " Please waiting "
  11.     while [ -e "/tmp/echo.tmp" ]
  12.     do
  13.         echo -n ". "
  14.         sleep 2
  15.     done
  16. }

  17. #大于128磁盘 分区格式化 安装grub 拷贝系统文件
  18. fun(){
  19.     dd if=/dev/zero of=$3 bs=512 count=1 &>/dev/null

  20.     if [ "$2" -le 128000000 ];then
  21.         echo ""
  22.         echo " ******************************************************"
  23.         echo " * The HardDisk Space Is Not Enough! *"
  24.         echo " * Press Anykey To PowerOFF..... *"
  25.         echo " ******************************************************"
  26.         read -n1 -s x
  27.         case $x in
  28.         *)
  29.             poweroff
  30.             sleep 1000
  31.             ;;
  32.         esac

  33.     else
  34.         touch /tmp/echo.tmp
  35.         echo_fun &
  36.         i=$[$1 / 10]
  37.         if [ "$i" -lt 4 ];then
  38.             i=4
  39.         fi
  40.         i=$[$1 - $i]
  41.         
  42.         sed 's/SIZE/'"$i"'/' fdk | fdisk $3 &>>$LOG

  43.         for((j=1;j<=3;j++))
  44.         do
  45.             mkfs.ext3 $3$j &>>$LOG
  46.             tune2fs -i 0 -c 0 $3$j &>>$LOG
  47.             mkdir /hd$j &>>$LOG
  48.             mount -t ext3 $3$j /hd$j &>>$LOG
  49.         done

  50.         cp -R /boot/ /hd1/
  51.         k=$[$4 - 1]
  52.         sed 's/SIZE/'"$k"'/' conf | grub &>>$LOG
  53.         
  54.         for i in $(cat dir)
  55.         do
  56.             mkdir $i &>>$LOG
  57.         done
  58.         
  59.         eject &>/dev/null
  60.         rm /tmp/echo.tmp
  61.         echo ""
  62.         echo ""
  63.         echo " ******************************************************"
  64.         echo " * Completed! Please Press Anykey To Reboot... *"
  65.         echo " ******************************************************"
  66.         read -n1 -s x
  67.         case $x in
  68.         *)
  69.             reboot
  70.             sleep 1000
  71.             ;;
  72.         esac
  73.     fi
  74. }

  75. #列出磁盘
  76. hd="fdisk -l 2>/dev/null | awk -F' |:' '/[sh]d.:/{print \$2}'"
  77. #列出簇
  78. cy="fdisk -l 2>/dev/null | awk '/[sh]d.:/{getline;print \$5}'"
  79. #列出字节
  80. by="fdisk -l 2>/dev/null | awk '/[sh]d.:/{print \$5}'"
  81. #计算磁盘数量
  82. num=$(fdisk -l 2>/dev/null | awk '/[sh]d.:/{k++}END{print k+0}')

  83. if [ "$num" -eq 0 ];then
  84.     echo ""
  85.     echo " ******************************************************"
  86.     echo " * Error! The HardDisk Is Undiscovered! *"
  87.     echo " * Press Anykey To PowerOFF..... *"
  88.     echo " ******************************************************"
  89.     case $x in
  90.     *)
  91.         poweroff
  92.         sleep 1000
  93.         ;;
  94.     esac

  95. elif [ "$num" -eq 1 ];then
  96.     disk_cy=$(eval $cy)
  97.     disk_by=$(eval $by)
  98.     disk=$(eval $hd)
  99.     fun $disk_cy $disk_by $disk $num

  100. else
  101.     echo ""
  102.     echo " ******************************************************"
  103.     echo " * Please select the HardDisk: *"
  104.     echo " ******************************************************"
  105.     for((i=1;i<=$num;i++))
  106.     do
  107.         echo " [$i] - $(fdisk -l 2>/dev/null | awk -F' |,' '/[sh]d.:/{print $2,$3,$4}' | sed -n ''"$i"'p')"
  108.     done
  109.     
  110.     while :
  111.     do
  112.         read -n1 -s x
  113.         if [[ "$x" =~ [1-$num] ]];then
  114.             disk_cy=$(eval $cy | sed -n ''"$x"'p')
  115.             disk_by=$(eval $by | sed -n ''"$x"'p')
  116.             disk=$(eval $hd | sed -n ''"$x"'p')
  117.             fun $disk_cy $disk_by $disk $x
  118.         else
  119.             echo ""
  120.             echo " ******************************************************"
  121.             echo " * Please Enter The Number! *"
  122.             echo " ******************************************************"
  123.         fi
  124.         done
  125. fi
阅读(1815) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~