2007年2月19日 星期一

[LVM2] 新增硬碟加大 Volume Group

之前有介紹如何在 LVM2 中動態調整 LV 的大小,這次是因為新買了硬碟,要將其加入到原本的 VG 中,以便於繼續增加原有 LV 的容量~

首先,將硬碟裝到電腦後,其裝置名稱為「/dev/sdb」(此硬碟接於第二個SATA裝置),並建立磁碟分割:
# 執行格式化指令,並指定欲格式化的裝置
[root@nat ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 38913.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

# 新增分割區
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-38913, default 1): (使用預設值)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-38913, default 38913): (使用預設值)
Using default value 38913

# 顯示目前的磁碟分割資訊
Command (m for help): p

Disk /dev/sdb: 320.0 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 38913 312568641 83 Linux

# 修改分隔區的系統ID => 原本為83(Linux)
Command (m for help): t
Selected partition 1 # 只有一個分割區,所以就沒得選了
Hex code (type L to list codes): 8e # 修改為8e(Linux LVM)
Changed system type of partition 1 to 8e (Linux LVM)

# 將分割結果寫入磁碟
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

接著要建立 PV:
# 讓上一個步驟分割好的 Partition Table 生效
[root@nat ~]# partprobe

# 顯示分割區的內容
[root@nat ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 320.0 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 38913 312568641 8e Linux LVM

# 建立 PV(Physical Volume)
[root@nat ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created

# 顯示 PV 內容 (320GB的硬碟其實只有300GB左右.....Orz)
[root@nat ~]# pvdisplay /dev/sdb1
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 298.09 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID JYted7-WjWQ-QylJ-sEjq-XCmw-0ZrO-L50I0n

最後,再將 PV 加入 VG 即可大功告成啦!!
# 將 剛建立好的 PV 加入原本存在的 VG
[root@nat ~]# vgextend VG_root /dev/sdb1
Volume group "VG_root" successfully extended

# 重新檢視 PV 資訊
[root@nat ~]# pvscan
PV /dev/sda2 VG VG_root lvm2 [186.03 GB / 3.34 GB free]
PV /dev/sdb1 VG VG_root lvm2 [298.06 GB / 298.06 GB free]
Total: 2 [484.09 GB] / in use: 2 [484.09 GB] / in no VG: 0 [0 ]

VG容量變大以後,接著就是參照前一篇的方式將 LV 加大囉!

沒有留言:

張貼留言