Ext3目前最大可支援至32TiB的磁碟容量,實作上會發現 fdisk
磁碟分割工具無法讀取到超過2TiB分割限制,因此這次實作改採
parted 另個工具,即可解決單磁區超過2TiB的問題。





實作平台:CentOS v5.1
套件版本:parted-1.8.1-12.el5


【步驟一】:首先請先確認系統是否有安裝 parted ?

[root@localhost ~]# rpm -qa | grep parted
pyparted-1.8.1-4.el5
parted-1.8.1-12.el5



【步驟二】:利用 parted 分割磁碟

[root@localhost ~]# parted /dev/sdb
GNU Parted 1.8.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) ?
 check NUMBER                  do a simple check on the file system
 cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition
 help [COMMAND]                 prints general help, or help on COMMAND
 mklabel,mktable LABEL-TYPE           create a new disklabel (partition table)
 mkfs NUMBER FS-TYPE              make a FS-TYPE file system on partititon NUMBER
 mkpart PART-TYPE [FS-TYPE] START END    make a partition
 mkpartfs PART-TYPE FS-TYPE START END    make a partition with a file system
 move NUMBER START END             move partition NUMBER
 name NUMBER NAME                name partition NUMBER as NAME
 print [free|NUMBER|all]              display the partition table, a partition, or all devices
 quit                        exit program
 rescue START END                rescue a lost partition near START and END
 resize NUMBER START END            resize partition NUMBER and its file system
 rm NUMBER                    delete partition NUMBER
 select DEVICE                  choose the device to edit
 set NUMBER FLAG STATE             change the FLAG on partition NUMBER
 toggle [NUMBER [FLAG]]             toggle the state of FLAG on partition NUMBER
 unit UNIT                     set the default unit to UNIT
 version                      displays the current version of GNU Parted and copyright
    information


 # 「?」,查詢相關指令。

(parted) help mklabel
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)

   LABEL-TYPE is one of: aix, amiga, bsd, dvh, gpt, mac, msdos, sun, loop


 # 「help mklabel」,查詢有哪些 Label-type 可用,
   Label-type 一定要選擇「gpt」,否則仍然會有容量的限制。

(parted) mklabel
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be
lost. Do you want to continue?
Yes/No? Yes
New disk label type? [bsd]? gpt


 ( 由於先前已製作過 Label,所以會提示對話,否則未做過的硬碟應該是不會出現上面的提示訊息。 )

 # 「help mkpart」,查詢可設定的檔案系統有哪些?

(parted) help mkpart
mkpart PART-TYPE [FS-TYPE] START END make a partition

   PART-TYPE is one of: primary, logical, extended
   FS-TYPE is one of: ext3, ext2, fat32, fat16, hfsx, hfs+, hfs, jfs, linux-swap, ntfs,
   reiserfs, hp-ufs, sun-ufs, xfs, apfs2, apfs1, asfs, amufs5, amufs4, amufs3, amufs2, amufs1,
   amufs0, amufs, affs7, affs6, affs5, affs4, affs3, affs2, affs1, affs0
   START and END are disk locations, such as 4GB or 10%. Negative values count from the end of
   the disk. For example, -1s specifies exactly the last sector.

   mkpart makes a partition without creating a new file system on the partition. FS-TYPE may
   be specified to set an appropriate partition ID.


 # 「mkpart」,執行磁碟分割。

(parted) mkpart
Partition name? []? primary
File system type? [ext2]? ext3
Start? 0
End? 102400


 ( Partition:primary、extended、logical,可選擇按需求選擇。 )

 # 「mkpartfs」除了分割磁碟外,會將分割的磁碟進行格式化。
   常見的檔案系統外,這裡也能針對 swap 設定。

(parted) mkpartfs
Partition name? []? primary
File system type? [ext2]? linux-swap
Start? 102401
End? 106497


 # 「mkpart」預設切割大小為 MB,上面的是示範採 GB 的設定。

(parted) mkpart
Partition name? []? extended
File system type? [ext2]? ext3
Start? 106G
End? 3995G


 # 單行指令的示範。

(parted) mkpart logical ext3 106G 3995G


 # 最後要確認分割的磁區是否正常,請下「print」或「p」即可查詢。
  上述示範有個小問題,照理來說將「延伸磁區」分割完,再分割「邏輯磁區」後,
  執行「print」,應該會出現邏輯磁區的切割資訊,多次測試後卻發現似乎不會顯示,
  這個問題有點奇怪,事後查詢 /proc/partitions 資訊卻是正確無誤。

(parted) print

Model: Proware R_CentOS5 (scsi)
Disk /dev/sdb: 3995GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number Start End Size File system Name Flags
1 17.4kB 102GB 102GB ext3 primary
2 102GB 106GB 4097MB linux-swap
3 106GB 3995GB 3889GB ext3 extended


 # 離開 parted。

(parted) quit



【步驟三:掛載磁碟】

 # 建立預掛載的目錄。

[root@localhost ~]# mkdir /raid
[root@localhost ~]# mkdir /raid2


 # mke2fs 格式化已分割的磁區。

[root@localhost ~]# mkfs.ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
12500992 inodes, 24999995 blocks
1249999 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
763 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
   32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
   4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.


[root@localhost ~]# mkfs.ext3 /dev/sdb3
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
474677248 inodes, 949341543 blocks
47467077 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
28972 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
   32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
   4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
   102400000, 214990848, 512000000, 550731776, 644972544

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.


 # 掛載分割區。

[root@localhost ~]# mount /dev/sdb1 /raid
[root@localhost ~]# mount /dev/sdb3 /raid2

[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 145G 2.9G 134G 3% /
tmpfs 3.0G 0 3.0G 0% /dev/shm
/dev/sdb1 94G 188M 89G 1% /raid
/dev/sdb3 3.5T 197M 3.4T 1% /raid2


 # 檢查磁碟相關資訊。

[root@localhost ~]# fdisk -l

Disk /dev/sda: 164.6 GB, 164696555520 bytes
255 heads, 63 sectors/track, 20023 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

 Device Boot Start End Blocks Id System
/dev/sda1 * 1 19415 155950956 83 Linux
/dev/sda2 19416 19937 4192965 82 Linux swap / Solaris

WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sdb: 3994.9 GB, 3994999980032 bytes
255 heads, 63 sectors/track, 485697 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

 Device Boot Start End Blocks Id System
/dev/sdb1 1 267350 2147483647+ ee EFI GPT


 # 修改磁碟標籤。

[root@localhost ~]# e2label /dev/sdb1 raid
[root@localhost ~]# e2label /dev/sdb3 raid2
[root@localhost ~]# blkid /dev/sdb1
/dev/sdb1: UUID="cda0faf6-1ac4-4d5c-86e1-9edb96d3836d" SEC_TYPE="ext2" TYPE="ext3" LABEL="raid"
[root@localhost ~]# blkid /dev/sdb3
/dev/sdb3: UUID="c90f3cb6-1526-4d64-9a5e-4ae4fa3b020a" SEC_TYPE="ext2" TYPE="ext3" LABEL="raid2"


 # 開機自動掛載。

[root@localhost ~]# vi /etc/fstab

LABEL=raid /raid ext3 defaults 0 0
LABEL=raid2 /raid2 ext3 defaults 0 0

[root@localhost ~]# mount -a

[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 145G 2.9G 134G 3% /
tmpfs 3.0G 0 3.0G 0% /dev/shm
/dev/sdb1 94G 188M 89G 1% /raid
/dev/sdb3 3.5T 197M 3.4T 1% /raid2


 # 掛載 swap。

[root@localhost ~]# mkswap -L SWAP-sdb /dev/sdb2

[root@localhost ~]# swapon /dev/sdb2

[root@localhost ~]# blkid /dev/sdb2
/dev/sdb2: TYPE="swap" LABEL="SWAP-sdb"

[root@localhost ~]# cat /proc/swaps
Filename Type Size Used Priority
/dev/sda2 partition 4192956 192 -1
/dev/sdb2 partition 4000968 0 -2

[root@localhost ~]# free
total used free shared buffers cached
Mem: 6102796 470148 5632648 0 66744 286544
-/+ buffers/cache: 116860 5985936
Swap: 8193924 0 8193924


 # 建議 swapon 寫在 /etc/rc.local,不建議寫在 /etc/fstab 裡,
  怕有錯誤會無法開機!

[root@localhost ~]# vi /etc/rc.local

swapon /dev/sdb2


 # 若機器先完成開機動作,Disk RAID 才開機時,
  記得先將 Fiber Card 的模組移除,接著重新載入。

[root@localhost ~]# rmmod qla2xxx
[root@localhost ~]# modprobe qla2xxx



補充說明:

之前在 RedHat 4.2 這個版本,有碰過一個比較詭異的狀況,
當完成 gpt磁區分割後,使用 mke2fs 格式化時,會發現格式
化完成後,只能分割出 2T 的磁碟空間。之前找了很久財發現
原來,問題出在 mke2fs 不知道為什麼並沒有套用預設值4096
的 block 分割大小,此時只需加上 -b 的參數,即可:

[root@localhost ~]# mke2fs -j -b 4096 /dev/sda1


另個補充要點是,筆者實做使用的版本是 parted v1.81 這個
版本。假若用 parted v1.6的版本,使用 mkpartfs 指令格式
化 ext3 的話,是無法使用的!建議先切割磁區,之後再透過
mke2fs 進行格式化。



【延伸閱讀】

      GNU Parted
      Parted 詳細功能與支援的檔案系統
      GNU parted 的指令說明
      GNU Parted 不完全攻略
      管理磁碟儲存空間



OK!拉哩拉雜寫了一堆工作上的瑣事,方便日後查詢,希望下
次碰到問題點的時候,能更加細心才是。

目前,感覺自己的能力還是一點都不強啊! >"<~~ 加油!



                         Paul

paul 發表在 痞客邦 PIXNET 留言(0) 人氣()