[root@li2 ~]# pvdisplay --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size36.00 GB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID QDmnUd-tuvH-U4Hn-n5Ry-zGRT-O1yK-67Dxbb --- NEW Physical volume --- PV Name /dev/sdc1 VG Name PV Size36.00 GB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID NDBf68-6qrD-9hE6-Rotv-RdxL-Azvv-7NlC0S
[root@li2 ~]# vgdisplay --- Volume group --- VG Name lvmdisk System ID Format lvm2 Metadata Areas 2 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 2 Act PV 2 VG Size71.98 GB PE Size4.00 MB Total PE 18428 Alloc PE / Size0 / 0 Free PE / Size18428 / 71.98 GB VG UUID SARfuj-wAUI-od81-VWAc-A1nt-aaFN-JWaPVf
当多个物理卷组合成一个卷组后时,LVM会在所有的物理卷上做类似格式化的工作,将每个物理卷切成一块一块的空间,这一块一块的空间就称为PE(Physical Extent ),它的默认大小是4MB。 由于受内核限制的原因,一个逻辑卷(Logic Volume)最多只能包含65536个PE(Physical Extent),所以一个PE的大小就决定了逻辑卷的最大容量,4 MB 的PE决定了单个逻辑卷最大容量为 256 GB,若希望使用大于256G的逻辑卷,则创建卷组时需要指定更大的PE。在Red Hat Enterprise Linux AS 4中PE大小范围为8 KB 到 16GB,并且必须总是 2 的倍数。 例如,如果希望使用 64 MB 的PE创建卷组,这样逻辑卷最大容量就可以为4 TB,命令如下:
[root@li2 ~]# vgdisplay --- Volume group --- VG Name lvmdisk System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size71.98 GB PE Size4.00 MB Total PE 18428 Alloc PE / Size3840 / 15.00 GB Free PE / Size14588 / 56.98 GB VG UUID SARfuj-wAUI-od81-VWAc-A1nt-aaFN-JWaPVf
[root@li2 ~]# vgdisplay --- Volume group --- VG Name lvmdisk System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size107.97 GB PE Size4.00 MB Total PE 27640 Alloc PE / Size3840 / 15.00 GB Free PE / Size23800 / 92.97 GB VG UUID l8YPvz-uD7h-oj1A-0qS5-TFcT-mbC7-QbjzCu
--- Physical volume --- PV Name /dev/sda2 VG Name VolGroup00 PV Size19.89 GB / not usable 19.49 MB Allocatable yes (but full) PE Size (KByte) 32768 Total PE 636 Free PE 0 Allocated PE 636 PV UUID 9UuRWq-3nFG-pQvY-nkCN-WZgj-uzNW-cUI1ei
"/dev/sdb" is a newphysical volume of "500.00 GB" ----这里是我们刚才创建的PV,已经成功
--- NEW Physical volume --- PV Name /dev/sdb VG Name PV Size500.00 GB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 3Xhu20-4Y4L-ITf5-MyXi-VLVN-kJ3M-LsoouK
4、 创建data卷组:
1 2 3 4 5 6
[root@jetsen~]# vgcreate data /dev/sdb /dev/cdrom: open failed: 只读文件系统 /dev/cdrom: open failed: 只读文件系统 Attempt to close device '/dev/cdrom' which isnot open. Volume group "data" successfullycreated
--- Volume group --- ------我们可以看到,这就是我们刚才创建的vg,已经成功了,大小为500G,由一个PV组成
VG Namedata System ID Format lvm2 Metadata Areas 1 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 1 Act PV 1 VG Size500.00 GB PE Size4.00 MB Total PE 127999 Alloc PE / Size0 / 0 Free PE / Size127999 / 500.00 GB VG UUID wqyQM5-Rigb-5art-0H20-X9QW-OL6N-PDkI4o
--- Volume group --- -----这是系统之前的卷组
VG Name VolGroup00 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 Size19.88 GB PE Size32.00 MB Total PE 636 Alloc PE / Size636 / 19.88 GB Free PE / Size0 / 0 VG UUID 9BbNZr-0ILr-CP3K-debx-OyJM-hDru-C0gVuR
6、 激活卷组
1 2 3
[root@jetsen~]# vgchange -a y data
0 logical volume(s) in volume group"data" now active
7、 创建新的物理卷
1 2 3
[root@jetsen~]# pvcreate /dev/sdc
Physical volume "/dev/sdc"successfully created
8、 将新的物理卷添加到现有卷组:
1 2 3 4 5 6 7
[root@jetsen~]# vgextend data /dev/sdc
/dev/cdrom: open failed: 只读文件系统
Attempt toclose device '/dev/cdrom' which isnot open.
--- Volume group --- VG Namedata System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 CurPV 2 ActPV 2 VG Size999.99 GB PE Size4.00 MB Total PE 255998 Alloc PE / Size0 / 0 Free PE / Size255998 / 999.99 GB VG UUID wqyQM5-Rigb-5art-0H20-X9QW-OL6N-PDkI4o
--- Volume group --- VG Namedata System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size500.00 GB PE Size4.00 MB Total PE 127999 Alloc PE / Size0 / 0 Free PE / Size127999 / 500.00 GB VG UUID wqyQM5-Rigb-5art-0H20-X9QW-OL6N-PDkI4o
--- Logical volume --- LV Name /dev/data/data001 **---LV的名称为data001** VG Name data **----卷组的名称为data** LV UUID o75uV4-VvTA-aaMe-4T74-mVQe-gSQO-clot5L LV WriteAccessread/write LV Status available # open0 LV Size 200.00 MB **---大小为200M** Current LE 50 Segments 1 Allocation inherit Read ahead sectors auto - currently setto256 Block device 253:2
--- Volume group --- VG Name data System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 500.00 GB PE Size 4.00 MB Total PE 127999 -----也就是这个值 Alloc PE / Size 50 / 200.00 MB Free PE / Size 127949 / 499.80 GB VG UUID wqyQM5-Rigb-5art-0H20-X9QW-OL6N-PDkI4o
创建使用卷组的全部逻辑卷语法如下:(由于之前已经创建了一卷组,就无法演示)
1
[root@jetsen~]# lvcreate -l***\*127999\****-n dataall data
--- Volume group --- VG Namedata System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size500.00 GB PE Size4.00 MB Total PE 127999 Alloc PE / Size50 / 200.00 MB Free PE / Size127949 / 499.80 GB ----这里是剩余空间的大小 VG UUID wqyQM5-Rigb-5art-0H20-X9QW-OL6N-PDkI4o
创建分区:
1 2 3
[root@jetsen~]# lvcreate -l127949 -n data003 data /dev/cdrom: open failed: 只读文件系统 Logical volume "data003" created
再次查看Free PE
1 2 3
[root@jetsen~]# vgdisplay data|grep "Free"
Free PE / Size 0/0----空间已经被划分完了,没有空间了
查看刚才创建的LV的信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
[root@jetsen~]# lvdisplay /dev/data/data003
--- Logical volume --- LV Name /dev/data/data003 VG Name data LV UUID 5gk4X3-ltNL-YUR9-AZnx-GHr9-shgc-t1Cuye LV Write Access read/write LV Status available # open 0 LV Size 499.80 GB ----大小为499.80G,正好验证了剩余空间的大小 Current LE 127949 ----LV个数正好验证了刚才所剩余的个数 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:3
mke2fs1.39 (29-May-2006) Filesystemlabel= OS type:Linux Blocksize=4096 (log=2) Fragmentsize=4096 (log=2) 65519616inodes, 131019776 blocks 6550988blocks (5.00%) reserved for the super user Firstdata block=0 Maximumfilesystem blocks=0 3999block groups 32768blocks per group, 32768 fragments per group 16384inodes per group Superblockbackups stored on blocks: 32768, 98304, 163840, 229376, 294912,819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000,23887872, 71663616, 78675968, 102400000
[root@jetsen /]# lvremove /dev/data/data003 /dev/cdrom:open failed: Read-only file system Do you really want to remove active logical volume data003?[y/n]: y Logical volume"data003" successfully removed
--- Volume group --- VG Name soft System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 1.43 GB PE Size 4.00 MB Total PE 366 Alloc PE / Size 0 / 0 Free PE / Size 366 / 1.43 GB VG UUID D3x6JY-BVIL-C4ld-013H-U2Rq-hb1q-1oOVnx
将1.5G共366个PE创建一个LV
1 2
[root@jetsen/]# lvcreate -l366 soft -n soft01 Logical volume "soft01" created
mke4fs1.41.5 (23-Apr-2009) Filesystemlabel= OS type:Linux Blocksize=4096 (log=2) Fragmentsize=4096 (log=2) 93696inodes, 374784 blocks 18739blocks (5.00%) reserved for the super user First datablock=0 Maximumfilesystem blocks=385875968 12 blockgroups 32768blocks per group, 32768 fragments per group 7808inodes per group Superblockbackups stored on blocks: 32768, 98304, 163840, 229376, 294912
VG Name soft System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 1.43 GB PE Size 4.00 MB Total PE 366 Alloc PE / Size 366 / 1.43 GB Free PE / Size 0 / 0 ----可用PE为0,需添加磁盘或分区 VG UUID D3x6JY-BVIL-C4ld-013H-U2Rq-hb1q-1oOVnx
[root@jetsen~]# pvcreate /dev/sdc3 Physical volume "/dev/sdc3"successfully created [root@jetsen~]# vgextend soft /dev/sdc3 /dev/cdrom: open failed: 只读文件系统 /dev/cdrom: open failed:只读文件系统 Attempt to close device '/dev/cdrom'which isnot open. Volume group "soft" successfullyextended [root@jetsen~]# vgdisplay soft --- Volume group --- VG Name soft System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 2.37 GB PE Size 4.00 MB Total PE 607 Alloc PE / Size 366 / 1.43 GB Free PE / Size 241 / 964.00 MB ------我们可以看到,这里已经添加进来了 VG UUID D3x6JY-BVIL-C4ld-013H-U2Rq-hb1q-1oOVnx
[root@jetsensoft]# lvdisplay soft --- Logical volume --- LV Name /dev/soft/soft01 VG Name soft LV UUID AutjnY-C3KP-5bfC-Di5v-Zkdu-4VhD-AahFY8 LV Write Access read/write LV Status available # open 1 LV Size 2.00 GB ----已经扩容到2G了 Current LE 512 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2
扩容文件系统
1 2 3 4 5 6
[root@jetsen~]# resize4fs /dev/soft/soft01 resize4fs1.41.5 (23-Apr-2009) Filesystemat /dev/soft/soft01 is mounted on /soft; on-line resizing required olddesc_blocks = 1, new_desc_blocks = 1 Performingan on-line resize of /dev/soft/soft01 to 652288 (4k) blocks. Thefilesystem on /dev/soft/soft01 is now 652288 blocks long.