Linux运维学习-磁盘管理之LVM

LVM:逻辑卷管理器(logical Volume Managerment)

 

物理卷(PV):可以是整个硬盘sdb、或者某个分区sdb1、或者RAID

卷组(VG): 物理卷的集合

逻辑卷(LV):基于卷组之上创建,文件系统建立在逻辑卷之上

这里就只有物理卷是不可以更改的,卷组和逻辑卷都可以动态改变,如果逻辑卷不够用了,就找卷组,如果卷组不够用了,在向卷子里面添加物理卷,物理卷的最小单位为PE(物理单元),默认一个是4M

功能/命令

物理卷管理

卷组管理

逻辑卷管理

扫描

pvscan

vgscan

lvscan

建立

pvcreate

vgcreate

lvcreate

显示

pvdisplay

vgdisplay

lvdisplay

删除

pvremove

vgremove

lvremove

扩展

 

vgextend

lvextend

缩小

 

vgreduce

lvreduce

 创建物理卷(PV):

Linux运维学习-磁盘管理之LVM_第1张图片

[root@localhost ~]# ls -l /dev/sd*
brw-rw----. 1 root disk 8,  0 Mar 21 03:34 /dev/sda
brw-rw----. 1 root disk 8,  1 Mar 21 03:34 /dev/sda1
brw-rw----. 1 root disk 8,  2 Mar 21 03:34 /dev/sda2
brw-rw----. 1 root disk 8, 16 Mar 21 03:34 /dev/sdb
brw-rw----. 1 root disk 8, 32 Mar 21 03:34 /dev/sdc
brw-rw----. 1 root disk 8, 48 Mar 21 03:34 /dev/sdd
brw-rw----. 1 root disk 8, 64 Mar 21 03:34 /dev/sde
brw-rw----. 1 root disk 8, 80 Mar 21 03:34 /dev/sdf
[root@localhost ~]# 
创建物理卷(PV):

[root@localhost ~]# pvcreate /dev/sd[e-f]
  Physical volume "/dev/sde" successfully created.
  Physical volume "/dev/sdf" successfully created.
[root@localhost ~]# 
查看:

[root@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               rhel
  PV Size               19.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4863
  Free PE               0
  Allocated PE          4863
  PV UUID               3qUrn1-1Epa-VUpA-XYcY-G8L4-kqIs-z016AL
   
  "/dev/sdf" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdf
  VG Name               
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               uw0ylA-uSTv-3vVV-kefT-gF86-Q5kN-cddbJm
   
  "/dev/sde" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sde
  VG Name               
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               XOIGMl-wjfz-uS3q-mVCt-Cf96-nQ6q-Rug6rz
   
[root@localhost ~]# 

创建卷组(VG):物理卷组成卷组

创建卷组,卷组名称为"myvg",将物理卷"/dev/sde"与"/dev/sdf"加入卷组:

[root@localhost ~]# vgcreate myvg /dev/sdf /dev/sde
  Volume group "myvg" successfully created
[root@localhost ~]#
[root@localhost ~]# 
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               rhel
  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.00 GiB
  PE Size               4.00 MiB
  Total PE              4863
  Alloc PE / Size       4863 / 19.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               qCWZIy-1Jaq-hDrp-ucrm-7CbF-dQey-n62uXB
   
  --- Volume group ---
  VG Name               myvg
  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 Size               39.99 GiB
  PE Size               4.00 MiB
  Total PE              10238
  Alloc PE / Size       0 / 0   
  Free  PE / Size       10238 / 39.99 GiB
  VG UUID               OVgeEV-DnX7-Hg6U-umf4-K2fb-Ly6g-ZOWovb
   
[root@localhost ~]# 
[root@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               rhel
  PV Size               19.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4863
  Free PE               0
  Allocated PE          4863
  PV UUID               3qUrn1-1Epa-VUpA-XYcY-G8L4-kqIs-z016AL
   
  --- Physical volume ---
  PV Name               /dev/sdf
  VG Name               myvg
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               5119
  Allocated PE          0
  PV UUID               uw0ylA-uSTv-3vVV-kefT-gF86-Q5kN-cddbJm
   
  --- Physical volume ---
  PV Name               /dev/sde
  VG Name               myvg
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               5119
  Allocated PE          0
  PV UUID               XOIGMl-wjfz-uS3q-mVCt-Cf96-nQ6q-Rug6rz
   
[root@localhost ~]#

创建逻辑卷(LV):

lvcreate -n mylv myvg -l 20

-n:指定逻辑卷的名称为”mylv”

指定分区大小有2种方式:

-l:指定PE的个数,整数(PE个数)

-L:指定大小(整数+单位),当大小不是PE的整数倍时,自动向上扩展

使用卷组"myvg",创建逻辑分区"mylv01",分配20个PE:

[root@localhost ~]# lvcreate -n mylv01 myvg -l 20
  Logical volume "mylv01" created.
[root@localhost ~]# 
[root@localhost ~]# lsblk /dev/myvg/mylv01 
NAME        MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
myvg-mylv01 253:2    0  80M  0 lvm  
[root@localhost ~]#
创建文件系统,挂载使用:

[root@localhost ~]# mkfs.xfs /dev/myvg/mylv01 
meta-data=/dev/myvg/mylv01       isize=512    agcount=4, agsize=5120 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=20480, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# 
[root@localhost ~]# mkdir /backup1
[root@localhost ~]# 
[root@localhost ~]# mount /dev/myvg/mylv01 /backup1/
[root@localhost ~]# 
[root@localhost ~]# df -hT /dev/myvg/mylv01 
Filesystem              Type  Size  Used Avail Use% Mounted on
/dev/mapper/myvg-mylv01 xfs    77M  4.2M   73M   6% /backup1
[root@localhost ~]# 

扩展逻辑卷(LV):

[root@localhost ~]# lsblk /dev/myvg/mylv01 
NAME        MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
myvg-mylv01 253:2    0  80M  0 lvm  /backup1
[root@localhost ~]# 
扩容到200M:

[root@localhost ~]# lvextend /dev/myvg/mylv01 -L 200M
  Size of logical volume myvg/mylv01 changed from 80.00 MiB (20 extents) to 200.00 MiB (50 extents).
  Logical volume myvg/mylv01 successfully resized.
[root@localhost ~]# 
重置大小:

[root@localhost ~]# xfs_growfs /dev/myvg/mylv01 
meta-data=/dev/mapper/myvg-mylv01 isize=512    agcount=4, agsize=5120 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=20480, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 20480 to 51200
[root@localhost ~]# 
[root@localhost ~]# df -hT /dev/myvg/mylv01 
Filesystem              Type  Size  Used Avail Use% Mounted on
/dev/mapper/myvg-mylv01 xfs   197M  4.4M  193M   3% /backup1
[root@localhost ~]# 

 

你可能感兴趣的:(Linux运维学习-磁盘管理之LVM)