您的位置:首页 > 运维架构 > Shell

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: