邏輯卷LVM

dotaddjj發表於2012-08-29

邏輯卷LVM是建立在物理儲存裝置之上的一個抽象層,LVM使儲存虛擬化,不會受限於物理磁碟的大小,可以組合多個物理磁碟,也可以線上對其邏輯卷的大小進行追加。

[root@orcl11g test]# pvcreate /dev/sda{5,6,7,8,9}

Physical volume "/dev/sda3" successfully created

Physical volume "/dev/sda5" successfully created

Physical volume "/dev/sda6" successfully created

Physical volume "/dev/sda7" successfully created

Physical volume "/dev/sda8" successfully created

Physical volume "/dev/sda9" successfully created

[root@orcl11g test]# pvscan

PV /dev/sda3 lvm2 [980.53 MB]

PV /dev/sda5 lvm2 [1.92 GB]

PV /dev/sda6 lvm2 [1.92 GB]

PV /dev/sda7 lvm2 [1.92 GB]

PV /dev/sda8 lvm2 [1.92 GB]

PV /dev/sda9 lvm2 [2.37 GB]

Total: 6 [10.99 GB] / in use: 0 [0 ] / in no VG: 6 [10.99 GB]

[root@orcl11g test]# pvdisplay

"/dev/sda3" is a new physical volume of "980.53 MB"

--- NEW Physical volume ---

PV Name /dev/sda3

VG Name

PV Size 980.53 MB

Allocatable NO

PE Size (KByte) 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID dJ3j0L-wDWq-1Bfa-zkpG-yTbG-eoNa-4FrjGP

"/dev/sda5" is a new physical volume of "1.92 GB"

--- NEW Physical volume ---

PV Name /dev/sda5

VG Name

PV Size 1.92 GB

Allocatable NO

PE Size (KByte) 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID nZnZfR-K5aH-v0MK-Vgfm-ZFY3-O1pK-fa5m1V

後續的省略

移除其中的一個物理卷

[root@orcl11g test]# pvremove /dev/sda3

Labels on physical volume "/dev/sda3" successfully wiped

[root@orcl11g test]# vgcreate -s 8M vg0 /dev/sda{5,6,7,8}

Volume group "vg0" successfully created

[root@orcl11g test]# vgscan

Reading all physical volumes. This may take a while...

Found volume group "vg0" using metadata type lvm2

[root@orcl11g test]# vgdisplay

--- Volume group ---

VG Name vg0

System ID

Format lvm2

Metadata Areas 4

Metadata Sequence No 1

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 0

Open LV 0

Max PV 0

Cur PV 4

Act PV 4

VG Size 7.66 GB

PE Size 8.00 MB

Total PE 980

Alloc PE / Size 0 / 0

Free PE / Size 980 / 7.66 GB

VG UUID RUxe0R-XVBe-IJe5-rz4D-IX00-30k5-YWG1gb

新增某個物理捲到卷組:

[root@orcl11g test]# vgextend vg0 /dev/sda9

Volume group "vg0" successfully extended

移除卷組

[root@orcl11g test]# vgremove vg0

Volume group "vg0" successfully removed

建立邏輯卷,一個卷組可以分開建立兩個邏輯卷。

[root@orcl11g test]# lvcreate -L 8G -n lv0 vg0

Logical volume "lv0" created

[root@orcl11g test]# lvcreate -L 2G -n lv1 vg0

Logical volume "lv1" created

移除某個邏輯卷

[root@orcl11g test]# lvremove /dev/vg0/lv1

Do you really want to remove active logical volume "lv1"? [y/n]: y

Logical volume "lv1" successfully removed

格式化邏輯卷

[root@orcl11g test]# mkfs -t ext3 /dev/vg0/lv0

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

1048576 inodes, 2097152 blocks

104857 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=2147483648

64 block groups

增加邏輯卷的大小

[root@orcl11g test]# lvextend -L +2G /dev/vg0/lv0

Extending logical volume lv0 to 10.00 GB

Logical volume lv0 successfully resized

當在mount階段對其邏輯卷容量儘量修改時,需要使用Resize2fs使其修改馬上生效,不然df看見的還是原來的size

[root@orcl11g test]# resize2fs /dev/vg0/lv0

resize2fs 1.39 (29-May-2006)

Resizing the filesystem on /dev/vg0/lv0 to 2621440 (4k) blocks.

The filesystem on /dev/vg0/lv0 is now 2621440 blocks long.

減少邏輯卷的大小。(不過個人在虛擬機器環境下測試後無法正常resizesuperblock被損壞)

[root@orcl11g test]# lvreduce -L -2G /dev/vg0/lv0

WARNING: Reducing active logical volume to 8.00 GB

減少完後還是把這2Glvextend追加進去

掛載邏輯卷

[root@orcl11g test]# mount /dev/vg0/lv0 /db

[root@orcl11g test]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda2 3.8G 3.0G 657M 83% /

/dev/sda1 99M 13M 82M 14% /boot

tmpfs 440M 0 440M 0% /dev/shm

none 440M 104K 440M 1% /var/lib/xenstored

/dev/mapper/vg0-lv0 9.9G 147M 9.4G 2% /db

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25362835/viewspace-1059284/,如需轉載,請註明出處,否則將追究法律責任。

相關文章