国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 操作系統 > 正文

自動分區、格式化、掛載腳本

2024-06-28 14:32:54
字體:
來源:轉載
供稿:網友

功能:自動檢測是否有尚未分區的數據盤,格式化新的數據盤并自動掛載

解決了什么問題:一鍵式檢測是否有尚未分區的數據盤,并能對其格式化和自動掛載,省去了復雜的命令和步驟

執行方法:以root身份執行命令

wget http://mirrors.linuxeye.com/scripts/auto_fdisk.shchmod +x auto_fdisk.sh./auto_fdisk.sh

結果:出現如下即自動分區、格式化、掛載成功:

腳本內容如下:

#!/bin/bash# Author:  yeho <lj2007331 AT Gmail.com># BLOG:  https://blog.linuxeye.com## Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+## PRoject home page:#       http://oneinstack.com#       https://github.com/lj2007331/oneinstackexport PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binclearprintf "########################################################################       OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+      ##                             Auto fdisk                              ##       For more information please visit http://oneinstack.com       ########################################################################"echo=echofor cmd in echo /bin/echo; do        $cmd >/dev/null 2>&1 || continue        if ! $cmd -e "" | grep -qE '^-e'; then                echo=$cmd                break        fidoneCSI=$($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 be root to run this script${CEND}"; exit 1; } MOUNT_DIR=/dataFSTAB_FILE=/etc/fstabcount=0TMP1=/tmp/.tmp1TMP2=/tmp/.tmp2> $TMP1> $TMP2# check lock file, one time only let the script run one time LOCKfile=/tmp/.$(basename $0)if [ -f "$LOCKfile" ];then    echo    echo "${CWARNING}The script is already exist, please next time to run this script${CEND}"    echo    exitelse    echo    echo "${CMSG}Step 1.No lock file, begin to create lock file and continue${CEND}"    echo    touch $LOCKfilefi# check disk partitioncheck_disk() {    > $LOCKfile    for i in `fdisk -l | grep "Disk" | grep "/dev" | awk '{print $2}' | awk -F: '{print $1}' | grep "vd"`    do        DEVICE_COUNT=$(fdisk -l $i | grep "$i" | awk '{print $2}' | awk -F: '{print $1}' | 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 $2}')" == '/' -o "$(grep -v '^#' $FSTAB_FILE | grep -v ^$ | awk '{print $1,$2,$3}' | grep -w "$i" | awk '{print $3}')" == 'swap' ];then                echo "${CWARNING}The $i disk is mounted${CEND}"            else                echo $i >> $LOCKfile                echo "You have a free disk, Now will 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`        do            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 oscheck_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 ext4modify_env() {    modprobe ext4    yum -y install e4fsprogs}# fdisk ,formating and create the file systemfdisk_fun() {fdisk -S 56 $1 << EOFnp1wqEOFsleep 5mkfs.ext4 ${1}1}# make directorymake_dir() {    echo "${CMSG}Step 4.Begin to make directory${CEND}"    [ -d "$MOUNT_DIR" ] && mv ${MOUNT_DIR}{,_bk}     mkdir -p $MOUNT_DIR    echo "$MOUNT_DIR" >> $TMP1}# config /etc/fstab and mount devicemain() {    for i in `echo $DISK_LIST`    do        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" >> $TMP2    done    make_dir    > $LOCKfile    paste $TMP2 $TMP1 > $LOCKfile    echo    echo "${CMSG}Step 5.Begin to write configuration to /etc/fstab and mount device${CEND}"    while read a b    do        [ -z "`grep ^${a} $FSTAB_FILE`" -a -z "`grep ${b} $FSTAB_FILE`" ] && echo "${a}	$b	ext4	defaults	0 0" >> $FSTAB_FILE    done < $LOCKfile    mount -a    echo}# start scriptecho "${CMSG}Step 2.Begin to check free disk${CEND}"#service MySQLd stop#mv /data /rootcheck_oscheck_diskmaindf -h#mv /root/data/* /data#service mysqld startrm -rf $LOCKfile $TMP1 $TMP2

 原文:https://blog.linuxeye.com/433.html


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 陕西省| 志丹县| 通州区| 巨野县| 平谷区| 乌拉特后旗| 沂源县| 张家界市| 通河县| 济源市| 迁西县| 佛教| 开远市| 博乐市| 含山县| 凉城县| 汕尾市| 东城区| 镇安县| 乌兰浩特市| 巩义市| 浪卡子县| 霍林郭勒市| 筠连县| 双峰县| 上虞市| 丹阳市| 民丰县| 西乡县| 奉节县| 澜沧| 巴楚县| 云龙县| 揭东县| 鹤壁市| 梅河口市| 博乐市| 隆子县| 新晃| 遵化市| 新绛县|