LVM逻辑卷在线动态扩容

环境:centos6

将需要扩容硬盘插入指定服务器
[root@huidu_hx_127_88 ~]# /opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL

Adapter #0

Enclosure Device ID: 32
Slot Number: 2
Enclosure position: 1
Device Id: 2
WWN: 5000C50084869FF8
Sequence Number: 1
Media Error Count: 0
Other Error Count: 0
Predictive Failure Count: 0
Last Predictive Failure Event Seq Number: 0
PD Type: SAS
Raw Size: 931.512 GB [0x74706db0 Sectors]
Non Coerced Size: 931.012 GB [0x74606db0 Sectors]
Coerced Size: 931.0 GB [0x74600000 Sectors]
Sector Size: 0
Firmware state: Unconfigured(good), Spun Up
Device Firmware Level: AS0B
Shield Counter: 0
Successful diagnostics completion on : N/A
SAS Address(0): 0x5000c50084869ff9
SAS Address(1): 0x0
Connected Port Number: 2(path0)
Inquiry Data: SEAGATE ST91000640SS AS0B9XG9K9R0
FDE Capable: Not Capable
FDE Enable: Disable
Secured: Unsecured
Locked: Unlocked
Needs EKM Attention: No
Foreign State: None
Device Speed: 6.0Gb/s
Link Speed: 6.0Gb/s
Media Type: Hard Disk Device
Drive Temperature :17C (62.60 F)
PI Eligibility: No
Drive is formatted for PI information: No
PI: No PI
Port-0 :
Port status: Active
Port's Linkspeed: 6.0Gb/s
Port-1 :
Port status: Active
Port's Linkspeed: Unknown
Drive has flagged a S.M.A.R.T alert : No

Enclosure Device ID: 32
Slot Number: 3
Enclosure position: 1
Device Id: 3
WWN: 5000C50084857234
Sequence Number: 1
Media Error Count: 0
Other Error Count: 0
Predictive Failure Count: 0
Last Predictive Failure Event Seq Number: 0
PD Type: SAS
Raw Size: 931.512 GB [0x74706db0 Sectors]
Non Coerced Size: 931.012 GB [0x74606db0 Sectors]
Coerced Size: 931.0 GB [0x74600000 Sectors]
Sector Size: 0
Firmware state: Unconfigured(good), Spun Up
Device Firmware Level: AS0B
Shield Counter: 0
Successful diagnostics completion on : N/A
SAS Address(0): 0x5000c50084857235
SAS Address(1): 0x0
Connected Port Number: 3(path0)
Inquiry Data: SEAGATE ST91000640SS AS0B9XG9KD2Q
FDE Capable: Not Capable
FDE Enable: Disable
Secured: Unsecured
Locked: Unlocked
Needs EKM Attention: No
Foreign State: None
Device Speed: 6.0Gb/s
Link Speed: 6.0Gb/s
Media Type: Hard Disk Device
Drive Temperature :18C (64.40 F)
PI Eligibility: No
Drive is formatted for PI information: No
PI: No PI
Port-0 :
Port status: Active
Port's Linkspeed: 6.0Gb/s
Port-1 :
Port status: Active
Port's Linkspeed: Unknown
Drive has flagged a S.M.A.R.T alert : No
确认JBOD模式为禁用状态
[root@huidu_hx_127_88 ~]# /opt/MegaRAID/MegaCli/MegaCli64 -AdpGetProp -enablejbod -aALL

Adapter 0: JBOD: Disabled
Exit Code: 0x00
创建raid1
[root@huidu_hx_127_88 ~]# /opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r1 [32:2,32:3] WB Direct -a0

Adapter 0: Created VD 1
Adapter 0: Configured the Adapter!!
Exit Code: 0x00

[root@huidu_hx_127_88 ~]# ll /dev/sd
sda sda1 sda2 sdb
查看raid状态
[root@huidu_hx_127_88 ~]# /opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -LALL -aAll

Adapter 0 -- Virtual Drive Information:
Virtual Drive: 0 (Target Id: 0)
Name :
RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
Size : 185.75 GB
Sector Size : 512
Mirror Data : 185.75 GB
State : Optimal
Strip Size : 64 KB
Number Of Drives : 2
Span Depth : 1
Default Cache Policy: WriteBack, ReadAdaptive, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAdaptive, Direct, No Write Cache if Bad BBU
Default Access Policy: Read/Write
Current Access Policy: Read/Write
Disk Cache Policy : Disk's Default
Encryption Type : None
Default Power Savings Policy: Controller Defined
Current Power Savings Policy: None
Can spin up in 1 minute: No
LD has drives that support T10 power conditions: No
LD's IO profile supports MAX power savings with cached writes: No
Bad Blocks Exist: No
Is VD Cached: No

Virtual Drive: 1 (Target Id: 1)
Name :
RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
Size : 931.0 GB
Sector Size : 512
Mirror Data : 931.0 GB
State : Optimal
Strip Size : 64 KB
Number Of Drives : 2
Span Depth : 1
Default Cache Policy: WriteBack, ReadAdaptive, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAdaptive, Direct, No Write Cache if Bad BBU
Default Access Policy: Read/Write
Current Access Policy: Read/Write
Disk Cache Policy : Disk's Default
Encryption Type : None
Default Power Savings Policy: Controller Defined
Current Power Savings Policy: None
Can spin up in 1 minute: Yes
LD has drives that support T10 power conditions: Yes
LD's IO profile supports MAX power savings with cached writes: No
Bad Blocks Exist: No
Is VD Cached: Yes
Cache Cade Type : Read Only
Exit Code: 0x00

[root@huidu_hx_127_88 ~]# ll /dev/sd
sda sda1 sda2 sdb

[root@huidu_hx_127_88 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 999.7 GB, 999653638144 bytes
255 heads, 63 sectors/track, 121534 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
LVM分区
[root@huidu_hx_127_88 ~]# fdisk  /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7b065bfc.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-121534, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-121534, default 121534):
Using default value 121534

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p
Disk /dev/sdb: 999.7 GB, 999653638144 bytes
255 heads, 63 sectors/track, 121534 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7b065bfc
Device Boot Start End Blocks Id System
/dev/sdb1 1 121534 976221823+ 8e Linux LVM

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
创建物理卷(PV)
[root@huidu_hx_127_88 ~]# pvcreate /dev/sdb1 
dev_is_mpath: failed to get device for 8:17
Physical volume "/dev/sdb1" successfully created

[root@huidu_hx_127_88 ~]# pvscan
PV /dev/sda2 VG vg_root lvm2 [185.62 GiB / 0 free]
PV /dev/sdb1 lvm2 [931.00 GiB]
Total: 2 [1.09 TiB] / in use: 1 [185.62 GiB] / in no VG: 1 [931.00 GiB]
扩展卷组(VG)
[root@huidu_hx_127_88 ~]# vgextend vg_root /dev/sdb1
Volume group "vg_root" successfully extended

[root@huidu_hx_127_88 ~]# pvscan
PV /dev/sda2 VG vg_root lvm2 [185.62 GiB / 0 free]
PV /dev/sdb1 VG vg_root lvm2 [930.97 GiB / 930.97 GiB free]
Total: 2 [1.09 TiB] / in use: 2 [1.09 TiB] / in no VG: 0 [0 ]
扩展LV(将新的VG空间划入LV,扩容lv_opt)
[root@huidu_hx_127_88 ~]# lvextend -l +100%FREE /dev/vg_root/lv_opt 
Extending logical volume lv_opt to 1.03 TiB
Logical volume lv_opt successfully resized
更新磁盘blocks
[root@huidu_hx_127_88 ~]# resize2fs /dev/vg_root/lv_opt 
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_root/lv_opt is mounted on /opt; on-line resizing required
old desc_blocks = 8, new_desc_blocks = 67
Performing an on-line resize of /dev/vg_root/lv_opt to 277504000 (4k) blocks.
The filesystem on /dev/vg_root/lv_opt is now 277504000 blocks long.
查看分区状态
[root@huidu_hx_127_88 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_root-lv_root
ext4 50G 9.3G 38G 20% /
tmpfs tmpfs 24G 0 24G 0% /dev/shm
/dev/sda1 ext3 97M 30M 63M 32% /boot
/dev/mapper/vg_root-lv_opt
ext4 1.1T 105G 885G 11% /opt
0%