#!/bin/bash # author: Yeho <lj2007331 at Gmail.com> @ # Notes:oneinstack for Centos/radhat 5+ Debian 6+ and Ubuntu 12+ # # Project Home page: # http://oneinstack.com # Https://github.com/lj2007331/oneinstack Export Path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin Clear printf ############ ########################################################### # OneinStack For Centos/radhat 5+ Debian 6+ and Ubuntu 12+ # # Auto fdisk # # For more information visit http://oneinstack.com # ####################################################################### Echo=echo for CMD in Echo/bin/echo; Todo $cmd >/dev/null 2>&1 | | Continue if! $cmd-E "" | Grep-qe ' ^-e '; Then echo= $cmd Break Fi Done csi=$ ($echo-E "\033[") Cend= "${csi}0m" Cdgreen= "${csi}32m" Cred= "${csi}1;31m" Cgreen= "${csi}1;32m" cyellow= "${csi}1;33m" Cblue= "${csi}1;34m" Cmagenta= "${csi}1;35m" Ccyan= "${csi}1;36m" Csuccess= "$CDGREEN" Cfailure= "$CRED" cquestion= "$CMAGENTA" Cwarning= "$CYELLOW" Cmsg= "$CCYAN" # Check If user is root [$ (id-u)!= "0"] && {echo "${cfailure}error:you must is root to run this script${cend}"; exit 1;} Mount_dir=/data Fstab_file=/etc/fstab Count=0 Tmp1=/tmp/.tmp1 Tmp2=/tmp/.tmp2 > $TMP 1 > $TMP 2 # Check lock file, one time ' let the ' script run one time lockfile=/tmp/.$ (basename $) If [f "$LOCKfile"];then Echo echo "${cwarning}the The script is already exist, please next time to run this script${cend}" Echo Exit Else Echo echo "${cmsg}step 1.No lock file, begin to create lock file and Continue${cend}" Echo Touch $LOCKfile Fi # Check Disk partition Check_disk () { > $LOCKfile For i in ' fdisk-l | grep "Disk" | grep "/dev" | awk ' {print $} ' | Awk-f: ' {print $} ' | grep "VD" Todo device_count=$ (fdisk-l $i | grep "$i" | awk ' {print $} ' | awk-f: ' {print $} ' | wc-l) new_mount=$ (df-h) If [$DEVICE _count-lt 2];then If [-N ' $ (echo $NEW _mount | Grep-w "$i") "-O" $ (grep-v ' ^# ' $FSTAB _file | Grep-v ^$ | awk ' {print $1,$2,$3} ' | Grep-w "$i" | awk ' {print $} ') ' = = = '/'-O ' $ (grep-v ' ^# ' $FSTAB _file | Grep-v ^$ | awk ' {print $1,$2,$3} ' | Grep-w "$i" | awk ' {print $} ') ' = = ' swap '];then echo "${cwarning}the $i disk is mounted${cend}" 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 echo "${cwarning}no free disk need to be fdisk. Exit Script${cend} " Echo RM-RF $LOCKfile Exit 0 Else echo "${cmsg}this system have free disk: ${cend}" For i in ' echo $DISK _list ' Todo echo "$i" count=$ ((count+1)) Done [$count-gt 1] && {echo "${cwarning}this system has at least two free disk, you must manually mount It${cend}"; Exit 0; } Fi } # Check OS Check_os () { os_release=$ (grep "Aliyun Linux release"/etc/issue 2>/dev/null) os_release_2=$ (grep "Aliyun Linux release"/etc/aliyun-release 2>/dev/null) If ["$os _release"] && ["$os _release_2"];then If echo "$os _release" | grep "Release 5" >/dev/null 2>&1;then Os_release=aliyun5 Modify_env Fi Fi } # Install EXT4 Modify_env () { Modprobe EXT4 Yum-y Install E4fsprogs } # fdisk, formating and create the file system Fdisk_fun () { Fdisk-s << EOF N P 1 Wq Eof Sleep 5 MKFS.EXT4 ${1}1 } # Make Directory Make_dir () { echo "${cmsg}step 4.Begin to make Directory${cend}" [-D "$MOUNT _dir"] && MV ${MOUNT_DIR}{,_BK} Mkdir-p $MOUNT _dir echo "$MOUNT _dir" >> $TMP 1 } # Config/etc/fstab and Mount device Main () { For i in ' echo $DISK _list ' Todo Echo echo "${cmsg}step 3.Begin to fdisk free disk${cend}" [-N ' df-h | grep ${i}1 ' "] && {echo" ${cfailure}the ${i}1 already Mount${cend} "; echo; exit 0;} Fdisk_fun $i >/dev/null 2>&1 Echo echo "${i}1" >> $TMP 2 Done Make_dir > $LOCKfile Paste $TMP 2 $TMP 1 > $LOCKfile Echo echo "${cmsg}step 5.Begin to write configuration to/etc/fstab and Mount Device${cend}" While read a B Todo [-Z ' grep ^${a} $FSTAB _file '-a-z ' grep ${b} $FSTAB _file '] && echo ' ${a} $b ext4 defaults 0 0 ' >> $FS Tab_file Done < $LOCKfile Mount-a Echo } # Start Script echo "${cmsg}step 2.Begin to check free disk${cend}" #service mysqld Stop #mv/data/root Check_os Check_disk Main Df-h #mv/root/data/*/data #service mysqld Start RM-RF $LOCKfile $TMP 1 $TMP 2 |