linux怎么自动分了一个分区吗,【转载】linux自动分区脚本

1. 配置需要分区的磁盘列表

[root@dwdb01 tmp]# more disk.lst

/dev/sddlmlae

/dev/sddlmlaf

2. 编写自动分区脚本

这个脚本很简单,就是把手工处理时的输入放到一个命令集合中:

n: 添加分区

p: 添加分区类型为primary

1: 主分区号为1

1. 从第一个扇区开始

回车:直到最后一个扇区

w: 把分区信息写入磁盘

[root@dwdb01 tmp]# more partition.sh

#!/bin/bash

for disk in `cat disk.lst`;do

dd if=/dev/zero f=$disk bs=512 count=3000

echo -e "fdisk 33[1;32m$disk33[0;39m now..."

fdisk $disk &>/dev/null

p

1

1

w

EOF

echo -e "33[1;34mDone33[0;39m"

done

3. 测试

[root@dwdb01 tmp]# ./partition.sh

3000+0 records in

3000+0 records out

1536000 bytes (1.5 MB) copied, 0.068202 seconds, 22.5 MB/s

fdisk /dev/sddlmlae now...

Done

3000+0 records in

3000+0 records out

1536000 bytes (1.5 MB) copied, 0.071411 seconds, 21.5 MB/s

fdisk /dev/sddlmlaf now...

Done

4. 验证

[root@dwdb01 tmp]# fdisk -l /dev/sddlmlae

Disk /dev/sddlmlae: 214.7 GB, 214748364800 bytes

255 heads, 63 sectors/track, 26108 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sddlmlae1 1 26108 209712478+ 83 Linux

[root@dwdb01 tmp]# fdisk -l /dev/sddlmlaf

Disk /dev/sddlmlaf: 214.7 GB, 214748364800 bytes

255 heads, 63 sectors/track, 26108 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sddlmlaf1 1 26108 209712478+ 83 Linux

可以看到,所有在disk.lst的磁盘都已经被正确分区。

如果需要更复杂的分区,只需要在命令集合列表中填写合适的指令参数即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值