shell脚本实现对系统的自动分区
2012-04-10 01:30
627 查看
#!/bin/bash
function print {
if [ $# = 2 ]; then
if [ "$1" = "warning" ]; then
echo -e "\033[33m\033[5m$2\033[0m"
elif [ "$1" = "error" ]; then
echo -e "\033[31m\033[5m$2\033[0m"
elif [ "$1" = "notice" ]; then
echo -e "\033[36m\033[5m$2\033[0m"
fi
echo $2
elif [ $# = 1 ]; then
echo -e "\033[32m\033[5m$1\033[0m"
echo $1
fi
return
}
#定义显示颜色方案
function format_disk()
{
fdisk /dev/sda << EOF
d
1
d
2
d
3
d
4
n
p
1
+1G
n
p
2
+20G
n
p
3
wq
EOF
print "==============fdsik sda to three parttions====================="
return 0
}
#分区大小为boot 1GB swap 20GB /根分区余下空间全用
function MKFS()
{
partprobe
mkfs.reiserfs -q /dev/sda1
[ $? != 0 ] && print "error" "mkfs sda1 is failed" && exit 0
mkswap /dev/sda2
[ $? != 0 ] && print "error" "mkswap sda2 is failed" && exit 0
swapon /dev/sda2
[ $? != 0 ] && print "error" "swapon sda2 is failed" && exit 0
mkfs.reiserfs -q /dev/sda3
[ $? != 0 ] && print "error" "mkfs sda3 is failed" && exit 0
print "===================make filesystem is OK===================="
return 0
}
#分区类型为reiserfs
function main()
{
format_disk;
MKFS
}
main
itnihao 2012年3月8日于成都
本文出自 “itnihao的运维技术博客” 博客,请务必保留此出处http://itnihao.blog.51cto.com/1741976/830366
function print {
if [ $# = 2 ]; then
if [ "$1" = "warning" ]; then
echo -e "\033[33m\033[5m$2\033[0m"
elif [ "$1" = "error" ]; then
echo -e "\033[31m\033[5m$2\033[0m"
elif [ "$1" = "notice" ]; then
echo -e "\033[36m\033[5m$2\033[0m"
fi
echo $2
elif [ $# = 1 ]; then
echo -e "\033[32m\033[5m$1\033[0m"
echo $1
fi
return
}
#定义显示颜色方案
function format_disk()
{
fdisk /dev/sda << EOF
d
1
d
2
d
3
d
4
n
p
1
+1G
n
p
2
+20G
n
p
3
wq
EOF
print "==============fdsik sda to three parttions====================="
return 0
}
#分区大小为boot 1GB swap 20GB /根分区余下空间全用
function MKFS()
{
partprobe
mkfs.reiserfs -q /dev/sda1
[ $? != 0 ] && print "error" "mkfs sda1 is failed" && exit 0
mkswap /dev/sda2
[ $? != 0 ] && print "error" "mkswap sda2 is failed" && exit 0
swapon /dev/sda2
[ $? != 0 ] && print "error" "swapon sda2 is failed" && exit 0
mkfs.reiserfs -q /dev/sda3
[ $? != 0 ] && print "error" "mkfs sda3 is failed" && exit 0
print "===================make filesystem is OK===================="
return 0
}
#分区类型为reiserfs
function main()
{
format_disk;
MKFS
}
main
itnihao 2012年3月8日于成都
本文出自 “itnihao的运维技术博客” 博客,请务必保留此出处http://itnihao.blog.51cto.com/1741976/830366
相关文章推荐
- Linux基础之-利用shell脚本实现自动监控系统服务
- 用shell脚本实现自动分区
- Shell脚本实现在Linux系统中自动安装JDK
- linux系统shell脚本实现 恶意扫描服务器密码 自动屏蔽
- Shell脚本实现在Linux系统中自动安装JDK
- shell脚本实现MBR、GPT自动分区及格式化
- Linux基础之-利用shell脚本实现自动监控系统服务
- Shell脚本实现自动输入密码登录服务器
- Linux使用Shell脚本实现ftp的自动上传下载
- Android自动化技术之自动monkey:shell脚本实现自动创建模拟器、启动模拟器、自动安装apk并进行monkey测试
- 用expect实现的自动登录到多台服务器的shell脚本
- 用shell脚本监控linux系统 自动发送邮件
- CentOS6、7 LVM逻辑卷分区自动扩容Shell脚本编程思路与实例
- zabbix系列(九)zabbix3.0实现自动触发zabbix-agent端shell脚本任务
- RPM包安装mysql,采用shell脚本实现自动安装、配置与卸载
- shell脚本实现系统监视统计与数据备份
- shell实现增加删除Linux系统用户脚本(密码为随机)
- shell脚本实现批量自动redis反弹shell攻击
- python 实现 Centos 7.1 下系统自动分区并mount到/data*
- 用shell脚本实现linux系统上wifi模式(STA和soft AP)的转换