LINUX系统中的PV LV VG的关系及管理

一.pv lv vg 介绍

  • PV(physical volume)即物理卷,就是物理磁盘,可以通过 fdisk -l 查看操作系统有几块硬盘

  • VG(volume group)即卷组,就是一组物理磁盘的组合,里面可以有一块硬盘也可以有多块硬盘

  • LV(logical volume)及逻辑卷,就是在VG(指定的物理磁盘组)里面划分出来的

可以说成是PV就是硬盘,而VG就是管理硬盘的操作系统,而LV就是操作系统分出来的各个分区.

PV->VG->LV-> 文件系统使用(挂载到某个目录)

硬盘或分区做成pv,然后将pv或多个pv建立vg,vg上建立lv在这里插入图片描述

二.命令集合

1.PV

pvcreate :根据物理盘,创建pv
pvscan :查询目前系统里的pv
pvdisplay:显示pv的状态
pvremove:将pv属性移除

2.VG

vgcreate:创建vg
vgscan:查找当前系统里面的vg
vgdisplay:显示当前系统vg的状态
vgextend:给vg添加额外的pv
vgreduce:在vg内删除pv
vgchange:设置vg是否是启动状态(active)

vgremove:删除一个vg

3.LV

lvcreate:创建lv
lvscan:查询当前系统的lv
lvdisplay:显示lv的属性
lvextend:给lv添加容量
lvredurce:给lv减少容量
lvremove:删除一个lv
lvresize:对lv大小的容量进行调整

三.实际操作

下面实际操作下,来看看

1.案例描述

从下看到只是把sda这块硬盘用了,做了vg(vg_dsgdata),并且在vg(vg_dsgdata)下建了/dev/vg_dsgdata/lv_root, /dev/vg_dsgdata/lv_swap, /dev/vg_dsgdata/lv_home三个lv, 通过df -h看到/dev/mapper/vg_dsgdata-lv_root挂载在根目录/下,/dev/mapper/vg_dsgdata-lv_home挂载在/home目录下.从上述看,还剩余sdb,sdc,sdd三块硬盘没有使用

[root@dsgdata ~]# fdisk -lDisk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 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: 0x00000000Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 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: 0x00000000Disk /dev/sdd: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 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: 0x00000000Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 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: 0x000a2d9eDevice Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64      121602   976248832   8e  Linux LVMDisk /dev/mapper/vg_dsgdata-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x00000000Disk /dev/mapper/vg_dsgdata-lv_swap: 8355 MB, 8355053568 bytes
255 heads, 63 sectors/track, 1015 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: 0x00000000Disk /dev/mapper/vg_dsgdata-lv_home: 937.6 GB, 937632464896 bytes
255 heads, 63 sectors/track, 113993 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[root@dsgdata ~]# [root@dsgdata ~]# pvdisplay--- Physical volume ---PV Name               /dev/sda2VG Name               vg_dsgdataPV Size               931.02 GiB / not usable 4.00 MiBAllocatable           yes (but full)PE Size               4.00 MiBTotal PE              238341Free PE               0Allocated PE          238341PV UUID               lPOKfO-HZ6y-4ubK-5TPk-FuB0-ypCU-y0mK1R[root@dsgdata ~]# 
[root@dsgdata ~]# vgdisplay--- Volume group ---VG Name               vg_dsgdataSystem ID             Format                lvm2Metadata Areas        1Metadata Sequence No  4VG Access             read/writeVG Status             resizableMAX LV                0Cur LV                3Open LV               3Max PV                0Cur PV                1Act PV                1VG Size               931.02 GiBPE Size               4.00 MiBTotal PE              238341Alloc PE / Size       238341 / 931.02 GiBFree  PE / Size       0 / 0   VG UUID               zQcZh0-2t6e-9LuM-zHnv-R0tG-sQDi-Ba3wLK[root@dsgdata ~]# lvdisplay--- Logical volume ---LV Path                /dev/vg_dsgdata/lv_rootLV Name                lv_rootVG Name                vg_dsgdataLV UUID                D7Z7jC-v0aK-fYJ5-AbcN-LmjX-nMEJ-dwpcm0LV Write Access        read/writeLV Creation host, time dsgdata, 2014-03-05 17:59:43 +0800LV Status              available# open                 1LV Size                50.00 GiBCurrent LE             12800Segments               1Allocation             inheritRead ahead sectors     auto- currently set to     256Block device           253:0--- Logical volume ---LV Path                /dev/vg_dsgdata/lv_swapLV Name                lv_swapVG Name                vg_dsgdataLV UUID                0HrVlq-IS9g-hNH0-R1Sr-hvcd-BUI2-hkjfLhLV Write Access        read/writeLV Creation host, time dsgdata, 2014-03-05 18:00:00 +0800LV Status              available# open                 1LV Size                7.78 GiBCurrent LE             1992Segments               1Allocation             inheritRead ahead sectors     auto- currently set to     256Block device           253:1--- Logical volume ---LV Path                /dev/vg_dsgdata/lv_homeLV Name                lv_homeVG Name                vg_dsgdataLV UUID                PC4IMN-Nvm3-UpaB-Em5I-NCvq-fzPF-MKcqOsLV Write Access        read/writeLV Creation host, time dsgdata, 2014-03-05 18:00:01 +0800LV Status              available# open                 1LV Size                873.24 GiBCurrent LE             223549Segments               1Allocation             inheritRead ahead sectors     auto- currently set to     256Block device           253:2[root@dsgdata ~]#
[root@dsgdata ~]# df -h
Filesystem                      Size  Used Avail Use% Mounted on
/dev/mapper/vg_dsgdata-lv_root   50G  4.4G   43G  10% /
tmpfs                           3.9G  228K  3.9G   1% /dev/shm
/dev/sda1                       485M   40M  420M   9% /boot
/dev/mapper/vg_dsgdata-lv_home  860G  200M  816G   1% /home
[root@dsgdata ~]# 
2.下面手工操作,创建增加减少删除关于pv,vg,lv的操作

创建pv

[root@dsgdata /]# pvcreate /dev/sdbPhysical volume "/dev/sdb" successfully created
[root@dsgdata /]# pvdisplay--- Physical volume ---PV Name               /dev/sda2VG Name               vg_dsgdataPV Size               931.02 GiB / not usable 4.00 MiBAllocatable           yes (but full)PE Size               4.00 MiBTotal PE              238341Free PE               0Allocated PE          238341PV UUID               lPOKfO-HZ6y-4ubK-5TPk-FuB0-ypCU-y0mK1R"/dev/sdb" is a new physical volume of "931.51 GiB"--- NEW Physical volume ---PV Name               /dev/sdbVG Name               PV Size               931.51 GiBAllocatable           NOPE Size               0   Total PE              0Free PE               0Allocated PE          0PV UUID               MO29Sj-3lEd-Licp-BNxD-9qPH-v5y4-zLUNHI[root@dsgdata /]# pvscanPV /dev/sda2   VG vg_dsgdata      lvm2 [931.02 GiB / 0    free]PV /dev/sdb                       lvm2 [931.51 GiB]Total: 2 [1.82 TiB] / in use: 1 [931.02 GiB] / in no VG: 1 [931.51 GiB]
[root@dsgdata /]# 
[root@dsgdata /]# pvremove /dev/sdbLabels on physical volume "/dev/sdb" successfully wiped
[root@dsgdata /]# pvscanPV /dev/sda2   VG vg_dsgdata   lvm2 [931.02 GiB / 0    free]Total: 1 [931.02 GiB] / in use: 1 [931.02 GiB] / in no VG: 0 [0   ]<pre code_snippet_id="220533" snippet_file_name="blog_20140306_6_5401133" class="html" name="code">[root@dsgdata /]# pvcreate /dev/sdb 
Physical volume "/dev/sdb" successfully created
3.创建VG
[root@dsgdata /]# vgcreate DATA /dev/sdb  Volume group "DATA" successfully created[root@dsgdata /]#[root@dsgdata /]# vgdisplay DATA  --- Volume group ---  VG Name               DATA  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 Size               931.51 GiB  PE Size               4.00 MiB  Total PE              238467  Alloc PE / Size       0 / 0     Free  PE / Size       238467 / 931.51 GiB  VG UUID               HhP6O7-sjLT-xzA7-YqLl-QsOJ-lQSM-3sN5VS   [root@dsgdata /]#

给VG添加或者减少容量:

[root@dsgdata /]# pvcreate /dev/sdc  Physical volume "/dev/sdc" successfully created[root@dsgdata /]# vgextend DATA /dev/sdc  Volume group "DATA" successfully extended[root@dsgdata /]# vgdisplay DATA  --- Volume group ---  VG Name               DATA  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  Cur PV                2  Act PV                2  VG Size               1.82 TiB  PE Size               4.00 MiB  Total PE              476934  Alloc PE / Size       0 / 0     Free  PE / Size       476934 / 1.82 TiB  VG UUID               HhP6O7-sjLT-xzA7-YqLl-QsOJ-lQSM-3sN5VS  [root@dsgdata /]# vgreduce DATA /dev/sdc  Removed "/dev/sdc" from volume group "DATA"[root@dsgdata /]# vgdisplay DATA  --- Volume group ---  VG Name               DATA  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 Size               931.51 GiB  PE Size               4.00 MiB  Total PE              238467  Alloc PE / Size       0 / 0     Free  PE / Size       238467 / 931.51 GiB  VG UUID               HhP6O7-sjLT-xzA7-YqLl-QsOJ-lQSM-3sN5VS   [root@dsgdata /]#
4.创建LV,并挂载
[root@dsgdata /]# lvscan  ACTIVE            '/dev/vg_dsgdata/lv_root' [50.00 GiB] inherit  
ACTIVE            '/dev/vg_dsgdata/lv_swap' [7.78 GiB] inherit  
ACTIVE            '/dev/vg_dsgdata/lv_home' [873.24 GiB] inherit[root@dsgdata /]# lvcreate -n test -L 100G DATA  Logical volume "test" created[root@dsgdata /]# lvscan  ACTIVE            '/dev/DATA/test' [100.00 GiB] inherit  ACTIVE           
'/dev/vg_dsgdata/lv_root' [50.00 GiB] inherit  ACTIVE           
'/dev/vg_dsgdata/lv_swap' [7.78 GiB] inherit  ACTIVE            
'/dev/vg_dsgdata/lv_home' [873.24 GiB] inherit[root@dsgdata /]#

在根目录下创建目录CXF
[root@dsgdata /]# mkdir /cxf
对逻辑卷进行格式化:

[root@dsgdata /]# mkfs -t ext4 /dev/DATA/test
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214400 blocks
1310720 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872</p><p>Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: 
done</p><p>This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@dsgdata /]#

将逻辑卷/dev/DATA/test挂载到/cxf目录下:

[root@dsgdata /]# mount /dev/DATA/test /cxf
[root@dsgdata /]# df -h
Filesystem                      Size  Used Avail Use% Mounted on
/dev/mapper/vg_dsgdata-lv_root   50G  4.4G   43G  10% /
tmpfs                           3.9G  228K  3.9G   1% /dev/shm
/dev/sda1                       485M   40M  420M   9% /boot
/dev/mapper/vg_dsgdata-lv_home  860G  200M  816G   1% /home
/dev/mapper/DATA-test            99G  188M   94G   1% /cxf
[root@dsgdata /]#

转自:https://blog.csdn.net/chengxuefei_bj/article/details/20612661

一文搞懂linux磁盘管理以及各场景扩容需求


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部