【轉載】linux自動分割槽指令碼

renjixinchina發表於2013-06-04
最近在做一個ORACLE資料倉儲的專案,由於儲存量巨大,lun的數量有幾百個。不管是用裸裝置還是ASM都需要把這些lun做分割槽。由於lun太多,如果一個一個手工分割槽,不但工作量巨大,且容易出錯或者疏漏。

而本專案要做的分割槽非常簡單,每一個lun分一個區,單個區佔用lun的所有空間,因此可以透過指令碼自動處理此類工作。

以下是具體步驟:

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 <n
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的磁碟都已經被正確分割槽。
如果需要更復雜的分割槽,只需要在命令集合列表中填寫合適的指令引數即可。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15747463/viewspace-762890/,如需轉載,請註明出處,否則將追究法律責任。

相關文章