First, Linux system
The code is as follows |
Copy Code |
#/bin/bash Count=0 Tmp1=/tmp/.tmp1 Tmp2=/tmp/.tmp2 > $tmp 1 > $tmp 2 Fstab_file=/etc/fstab #check lock file, one time is let the script run one time lockfile=/tmp/.$ (basename $) If [-F "$LOCKfile]" Then Echo-e "33[1;40;31mthe script is already exist,please next time to run this script.33[0m" Exit Else Echo-e "33[40;32mstep 1.No lock File,begin to create lock file and continue.33[40;37m" Touch $LOCKfile Fi #check User If [$ (id-u)!= "0"] Then Echo-e "33[1;40;31merror:you must is root to run this script, please use the root to install this script.33[0m" RM-RF $LOCKfile Exit 1 Fi #check disk partition Check_disk () { > $LOCKfile device_list=$ (fdisk-l|grep "Disk" |grep "/dev" |awk ' {print $} ' |awk-f: ' {print $} ' |grep ' XV ') For i in ' echo $device _list ' Todo device_count=$ (fdisk-l $i |grep "$i" |awk ' {print $} ' |awk-f: ' {print $} ' |wc-l) Echo If [$device _count-lt 2] Then now_mount=$ (df-h) If Echo $now _mount|grep-w "$i" >/dev/null 2>&1 Then ECHO-E "33[40;32mthe $i disk is mounted.33[40;37m" Else echo $i >> $LOCKfile echo "You have a free disk,now'll fdisk it and mount it." Fi Fi Done disk_list=$ (Cat $LOCKfile) If ["x$disk_list" = = "X"] Then ECHO-E "33[1;40;31mno free disk need to be fdisk. Exit script.33[0m " RM-RF $LOCKfile Exit 0 Else ECHO-E "33[40;32mthis system have free disk:33[40;37m" For i in ' echo $disk _list ' Todo echo "$i" count=$ ((count+1)) Done Fi } #fdisk, formating and create the file system Fdisk_fun () { Fdisk-s << EOF N P 1 Wq Eof Sleep 5 Mkfs.ext3 ${1}1 } #make Directory Make_dir () { Echo-e "33[40;32mstep 4.Begin to make directory33[40;37m" For j in ' Seq $count ' Todo If [-D "/alidata$j"] Then Echo-e "33[1;40;31m/alidata$j is exists. This script would exit,you must to choose a directory for mount.33[0m RM-RF $LOCKfile $tmp 2 Exit Else echo "/alidata$j" >> $tmp 1 Mkdir/alidata$j Fi Done } #config/etc/fstab and Mount device Main () { For i in ' echo $disk _list ' Todo Echo-e "33[40;32mstep 3.Begin to fdisk free disk.33[40;37m" Fdisk_fun $i echo "${i}1" >> $tmp 2 Done Make_dir > $LOCKfile Paste $tmp 2 $tmp 1 > $LOCKfile Echo-e "33[40;32mstep 5.Begin to write configuration to/etc/fstab and Mount Device.33[40;37m" While read a B Todo If Grep-v ^# $fstab _file|grep ${a} >/dev/null Then Sed-i "s=${a}*=#&=" $fstab _file Fi echo "${a} $b ext3 defaults 0 0" >> $fstab _file Done < $LOCKfile Mount-a } #=========start script=========== Echo-e "33[40;32mstep 2.Begin to check free disk.33[40;37m" Check_disk Main Df-h RM-RF $LOCKfile $tmp 1 $tmp 2 |
Save the script as sh, execute with root!
Go to the command prompt and execute the following command:
c:usersadministrator>DiskPart
Disk ### state size available Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online GB 0 GB (disks that can run the system)
Disk 1 online GB GB (disks that require 4k alignment)
Disk 1 is now the selected disk.
There are no partitions displayed on this disk.
DiskPart successfully cleared the disk.
Diskpart> create partition primary align=1024 (4k partition Alignment)
DiskPart successfully created the specified partition.
Partition ### Type size offset
------------- ---------------- ------- -------
* Partition 1 Main GB 1024 KB (4K alignment has been successful)
Go to Computer Management in Administrative tools and select Disk Management on the left. On disk 1, click Change Drive Letter and path.
Add a valid drive letter.
Then format it, right-click on disk 1 and choose Format.
After confirmation, enter the relevant formatting information and wait for the format to complete.