当前位置:首页 > 电子 > 正文内容

linux系统 硬盘自动挂载 自动格式化 脚本

admin6年前 (2018-09-04)电子4204

mkdir /data1

mkdir /data2

mkdir /data3

mkdir /data4


 mkfs.xfs /dev/sdb1


echo "/dev/sdb1 /data1 xfs defaults 0 0" >> /etc/fstab

echo "/dev/sdc1 /data2 xfs defaults 0 0" >> /etc/fstab

echo "/dev/sdd1 /data3 xfs defaults 0 0" >> /etc/fstab

echo "/dev/sde1 /data4 xfs defaults 0 0" >> /etc/fstab






#!/bin/bash

# Author: Vtrois <seaton@vtrois.com>
# Project URL: https://www.vtrois.com
# Description: Auto fdisk for SpacePack Tools
# Github URL: https://github.com/Vtrois/Auto-fdisk
# WEB IDE DEMO

export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
clear
printf "
===========================================================================
                                Auto fdisk
      SpacePack tools for CentOS, CoreOS, Debian, openSUSE and Ubuntu
   For more information please visit https://github.com/Vtrois/Auto-fdisk
===========================================================================
"
echo -e "\n\033[36mStep 1: Initializing script and check root privilege\033[0m"
if [ "$(id -u)" = "0" ];then  
	echo -e "\033[33mIs running, please wait!\033[0m"
  	yum -y install e4fsprogs > /dev/null 2>&1
	echo -e "\033[32mSuccess, the script is ready to be installed!\033[0m"
else
	echo -e "\033[31mError, this script must be run as root!\n\033[0m"
	exit 1
fi
echo -e "\n\033[36mStep 2: Show all active disks:\033[0m"
fdisk -l 2>/dev/null | grep -o "Disk /dev/vd[b-z]"
echo -e -n "\n\033[36mStep 3: Please choose the disk(e.g., /dev/vdb and q to quit):\033[0m"
read Disk
if [ $Disk == q ];then
	exit
fi
until fdisk -l 2>/dev/null | grep -o "Disk /dev/vd[b-z]" | grep "Disk $Disk" &>/dev/null;do
echo -e -n "\033[31mOops, something went wrong, please try again (e.g., /dev/vdb or q to quit):\033[0m"
	read Disk
	if [ $Disk == q ];then
		exit
	fi
done
while mount | grep "$Disk" > /dev/null 2>&1;do
	echo -e "\033[31m\nYour disk has been mounted:\033[0m"
	mount | grep "$Disk"
	echo -e -n "\033[31m\nForce uninstalling? [y/n]:\033[0m"
	read Umount
	until [ $Umount == y -o $Umount == n ];do
		echo -e -n "\033[31mOops, something went wrong, please try again [y/n]:\033[0m"
		read Umount
	done
	if [ $Umount == n ];then
		exit
	else
		echo -e "\033[33mIs running, please wait!\033[0m"
		for i in `mount | grep "$Disk" | awk '{print $3}'`;do
			fuser -km $i >/dev/null
			umount $i >/dev/null
			sleep 2
		done
		echo -e "\033[32mSuccess, the disk is unloaded!\033[0m"
	fi
	echo -e -n "\n\033[36mReady to begin to format the disk? [y/n]:\033[0m"
	read Choice
	until [ $Choice == y -o $Choice == n ];do
		echo -e -n "\033[31mOops, something went wrong, please try again [y/n]:\033[0m"
		read Choice
	done
	if [ $Choice == n ];then
		exit
	else
		echo -e "\033[33mIs running, please wait!\033[0m"
		dd if=/dev/zero of=$Disk bs=512 count=1 &>/dev/null
		sleep 2
	sync
	fi
	echo -e "\033[32mSuccess, the disk has been formatted!\033[0m"
done
echo -e "\n\033[36mStep 4: The disk is partitioning and formatting\033[0m"
echo -e "\033[33mIs running, please wait!\033[0m"
fdisk_mkfs() {
fdisk -S 56 $1 << EOF
n
p
1
wq
EOF

sleep 2
mkfs.ext4 ${1}1
}
fdisk_mkfs $Disk > /dev/null 2>&1
echo -e "\033[32mSuccess, the disk has been partitioned and formatted!\033[0m"
echo -e "\n\033[36mStep 5: Make a directory and mount it\033[0m"
echo -e -n "\033[33mPlease enter a location to mount (e.g., /data):\033[0m"
read Mount
mkdir $Mount > /dev/null 2>&1
mount ${Disk}1 $Mount
echo -e "\033[32mSuccess, the mount is completed!\033[0m"
echo -e "\n\033[36mStep 6: Write configuration to /etc/fstab and mount device\033[0m"
echo ${Disk}1 $Mount 'ext4 defaults 0 0' >> /etc/fstab
echo -e "\033[32mSuccess, the /etc/fstab is Write!\033[0m"
echo -e "\n\033[36mStep 7: Show information about the file system on which each FILE resides\033[0m"
df -h
sleep 2
echo -e "\n\033[36mStep 8: Show the write configuration to /etc/fstab\033[0m"
cat /etc/fstab


扫描二维码推送至手机访问。

版权声明:本文由视觉博客发布,如需转载请注明出处。

本文链接:http://www.cqroom.cn/post/71.html

“linux系统 硬盘自动挂载 自动格式化 脚本” 的相关文章

labVIEW调用C# dll 步骤

labVIEW调用C# dll 步骤

labVIEW选用的版本是2010,C#选用的是VS20101.打开VS 2010,选择 文件》新建》项目 如下图所示:图12.输入名称并点击确认,如下图所示图23.编辑类,简单的编辑一个加法,如下图所示:图34.点击 项目》ClassLibrary 属性,如下图所示:图4图65.点击解决方案管理器...

STM32 中断向量表的位置 、重定向

STM32 中断向量表的位置 、重定向

这篇文章已经说了STM32的启动过程: http://www.cqroom.cn/post/39.html 我们也知道怎么跳到main函数了,那么,中断发生后,又是怎么跑到中断入口地址的呢? 从stm32f10x.s可以看到,已经定义好了一大堆...

物联网 WIFI 一键配置原理(smartconfig) ESP8266/QCA4004

物联网 WIFI 一键配置原理(smartconfig) ESP8266/QCA4004

物联网 WIFI 一键配置原理(smartconfig) ESP8266/QCA4004 自从物联网问世以来,如何使得物 能够联网有了很多的方式,目前运用非常广的WIFI,今天就总结下自这个方面,也对于有需要的盆友也希望有抛砖引玉之效果。 来看个知乎...

FAT32文件格式详解

FAT32文件格式详解

说明: MBR :Master Boot Record ( 主引导记录)  DBR :DOS Boot Record ( 引导扇区) ...

如何看懂电路图(一)--基本的电路符号

如何看懂电路图(一)--基本的电路符号

电子设备中有各种各样的图。能够说明它们工作原理的是电原理图,简称电路图。 电路图有两种,一种是说明模拟电子电路工作原理的。它用各种图形符号表示电阻器、电容器、开关、晶体管等实物,用线条把元器件和单元电路按工作原理的关系连接起来。这种图长期以来就一直被叫做电路图。 另一种...

如何看懂电路图(二)-电源电路

如何看懂电路图(二)-电源电路

前 面介绍了电路图中的元器件的作用和符号。一张电路图通常有几十乃至几百个,它们的连线纵横交叉,形式变化多端,初学者往往不知道该从什么地方开始, 怎样才能读懂它。其实电子电路本身有很强的规律性,不管多复杂的电路,经过分析可以发现,它是由少数几个单元电路组成的。好象孩子们玩的积木,虽然只有十 来...

评论列表

访客
访客 IP:四川省
6年前 (2018-09-30)

我靠!你那个老鼠太逗了,我玩了一下午!

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。