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的磁盘都已经被正确分区。
如果需要更复杂的分区,只需要在命令集合列表中填写合适的指令参数即可。