Linux LVM添加物理盤學習筆記1

背景:linux

linux操做系統使用lvm管理後,當出現磁盤空間不足的時候,就須要添加硬盤,而後把硬盤添加到vg裏面去,在線擴容磁盤空間,業務不受影響。bash

具體添加流程:app

disk--->pv--->vg--->lvide

  • 添加完硬盤後,進入操做系統,檢查是否已經識別到硬盤了,若是沒有識別,須要重啓操做系統。

[root@cw001 ~]# fdisk -lui

Disk /dev/sda: 21.5 GB, 21474836480 bytes操作系統

255 heads, 63 sectors/track, 2610 cylindersrest

Units = cylinders of 16065 * 512 = 8225280 bytesorm

Sector size (logical/physical): 512 bytes / 512 bytesit

I/O size (minimum/optimal): 512 bytes / 512 bytesio

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

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

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

255 heads, 63 sectors/track, 509 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

Disk /dev/sdb: 64.4 GB, 64424509440 bytes

255 heads, 63 sectors/track, 7832 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

  • 檢查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

[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

"/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

Free PE 0

Allocated PE 0

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

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

[root@cw001 ~]# vgdisplay

--- Volume group ---

VG Name vg_cw001

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

PE Size 4.00 MiB

Total PE 4994

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

  • 添加完後,查看顯示大小

[root@cw001 ~]# vgdisplay

--- Volume group ---

VG Name vg_cw001

System ID

Format lvm2

Metadata Areas 2

Metadata Sequence No 4

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 2

Open LV 2

Max PV 0

Cur PV 2

Act PV 2

VG Size 79.50 GiB

PE Size 4.00 MiB

Total PE 20353

Alloc PE / Size 4994 / 19.51 GiB

Free PE / Size 15359 / 60.00 GiB

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

[root@cw001 ~]#

  • 添加完vg後,如今開始正式擴容lv

#查看lv大小

[root@cw001 ~]# lvdisplay

--- Logical volume ---

LV Path /dev/vg_cw001/lv_root

LV Name lv_root

VG Name vg_cw001

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

--- Logical volume ---

LV Path /dev/vg_cw001/lv_swap

LV Name lv_swap

VG Name vg_cw001

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

LV Write Access read/write

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

LV Status available

# open 1

LV Size 3.91 GiB

Current LE 1000

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

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

[root@cw001 ~]# lvdisplay

--- Logical volume ---

LV Path /dev/vg_cw001/lv_root

LV Name lv_root

VG Name vg_cw001

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 74.60 GiB

Current LE 19098

Segments 2

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:0

--- Logical volume ---

LV Path /dev/vg_cw001/lv_swap

LV Name lv_swap

VG Name vg_cw001

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

LV Write Access read/write

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

LV Status available

# open 1

LV Size 3.91 GiB

Current LE 1000

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:1

[root@cw001 ~]#

  • 檢查硬盤擴容是否已經成功

[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

[root@cw001 ~]#

  • 發現沒有成功,這個時候,須要使用resize2fs從新刷新一次便可。

[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

[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.

[root@cw001 ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_cw001-lv_root

74G 14G 56G 20% /

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

[root@cw001 ~]#

結束: 執行完上面命令後,表示lv已經擴容成功,若是下次磁盤空間不夠,能夠繼續添加物理盤,而後從新擴容,不影響用戶使用。

相關文章
相關標籤/搜索