天天看點

Linux LVM添加實體盤學習筆記1

背景:

linux作業系統使用lvm管理後,當出現磁盤空間不足的時候,就需要添加硬碟,然後把硬碟添加到vg裡面去,線上擴容磁盤空間,業務不受影響。

具體添加流程:

disk--->pv--->vg--->lv

添加完硬碟後,進入作業系統,檢查是否已經識别到硬碟了,如果沒有識别,需要重新開機作業系統。

[root@cw001 ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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: 0x00019bb5

Device Boot Start End Blocks Id System

/dev/sda1 * 1 64 512000 83 Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2 64 2611 20458496 8e Linux LVM

Disk /dev/mapper/vg_cw001-lv_root: 16.8 GB, 16752050176 bytes

255 heads, 63 sectors/track, 2036 cylinders

Disk identifier: 0x00000000

Disk /dev/mapper/vg_cw001-lv_swap: 4194 MB, 4194304000 bytes

255 heads, 63 sectors/track, 509 cylinders

Disk /dev/sdb: 64.4 GB, 64424509440 bytes

255 heads, 63 sectors/track, 7832 cylinders

檢查pv,然後添加新的硬碟到lvm中的pv組中

[root@cw001 ~]# pvdisplay

--- Physical volume ---

PV Name /dev/sda2

VG Name vg_cw001

PV Size 19.51 GiB / not usable 3.00 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 4994

Free PE 0

Allocated PE 4994

PV UUID ybQPnm-seCs-Np31-Hr64-P5eS-3saW-HQ57u0

[root@cw001 ~]# pvcreate /dev/sdb

Physical volume "/dev/sdb" successfully created

[root@cw001 ~]# pvdiaplay

-bash: pvdiaplay: command not found

"/dev/sdb" is a new physical volume of "60.00 GiB"

--- NEW Physical volume ---

PV Name /dev/sdb

VG Name

PV Size 60.00 GiB

Allocatable NO

PE Size 0

Total PE 0

Allocated PE 0

PV UUID B0fjek-wMhA-bIQP-wuA1-PRiN-eD3g-rrhyjh

檢查vg的大小,然後使用vgextend擴容vg空間

[root@cw001 ~]# vgdisplay

--- Volume group ---

System ID

Format lvm2

Metadata Areas 1

Metadata Sequence No 3

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 2

Open LV 2

Max PV 0

Cur PV 1

Act PV 1

VG Size 19.51 GiB

Alloc PE / Size 4994 / 19.51 GiB

Free PE / Size 0 / 0

VG UUID U3tLKK-6I7f-mYJn-qurr-tX45-ubz5-3czoMJ

把sdb硬碟添加到vg_cw001這個vg組中

[root@cw001 ~]# vgextend vg_cw001 /dev/sdb

Volume group "vg_cw001" successfully extended

添加完後,檢視顯示大小

Metadata Areas 2

Metadata Sequence No 4

Cur PV 2

Act PV 2

VG Size 79.50 GiB

Total PE 20353

Free PE / Size 15359 / 60.00 GiB

[root@cw001 ~]#

添加完vg後,現在開始正式擴容lv

#檢視lv大小

[root@cw001 ~]# lvdisplay

--- Logical volume ---

LV Path /dev/vg_cw001/lv_root

LV Name lv_root

LV UUID h1F8Vv-xCBt-kRDF-Kkut-0S7F-e9F0-srEdWm

LV Write Access read/write

LV Creation host, time cw001, 2015-07-29 18:45:20 -0400

LV Status available

# open 1

LV Size 15.60 GiB

Current LE 3994

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:0

LV Path /dev/vg_cw001/lv_swap

LV Name lv_swap

LV UUID QXzVwA-ERYR-f3iw-ZgIn-cxNV-u849-5lQwiM

LV Creation host, time cw001, 2015-07-29 18:45:22 -0400

LV Size 3.91 GiB

Current LE 1000

Block device 253:1

執行lv擴容指令lvextend

[root@cw001 ~]# lvextend -L +59G /dev/vg_cw001/lv_root

Extending logical volume lv_root to 74.60 GiB

Logical volume lv_root successfully resized

LV Size 74.60 GiB

Current LE 19098

Segments 2

檢查硬碟擴容是否已經成功

[root@cw001 ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_cw001-lv_root

16G 14G 677M 96% /

tmpfs 932M 443M 489M 48% /dev/shm

/dev/sda1 485M 32M 428M 7% /boot

/dev/sr0 4.1G 4.1G 0 100% /media/CentOS_6.4_Final

發現沒有成功,這個時候,需要使用resize2fs重新重新整理一次即可。

[root@cw001 ~]# res

reset resize2fs resizecons restart restorecon restorecond

[root@cw001 ~]# resize2fs /dev/vg_cw001/lv_root

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/vg_cw001/lv_root is mounted on /; on-line resizing required

old desc_blocks = 1, new_desc_blocks = 5

Performing an on-line resize of /dev/vg_cw001/lv_root to 19556352 (4k) blocks.

The filesystem on /dev/vg_cw001/lv_root is now 19556352 blocks long.

74G 14G 56G 20% /

結束: 執行完上面指令後,表示lv已經擴容成功,如果下次磁盤空間不夠,可以繼續添加實體盤,然後重新擴容,不影響使用者使用。\\

本文轉自 woshiwei201 51CTO部落格,原文連結:http://blog.51cto.com/chenwei/1959603

繼續閱讀