其他分享
首页 > 其他分享> > LVM逻辑卷管理器

LVM逻辑卷管理器

作者:互联网

概述

从最底层向上,分别为:物理存储介质 > 物理卷(Physical Volume,PV) > 卷组(Volume Group,VG) > 逻辑卷(Logical Volume,LV)。

查看物理磁盘信息

[root@localhost ~]# fdisk -l

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00035770

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   198549503    98761728   8e  Linux LVM

Disk /dev/mapper/centos-root: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-data: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-mongo1: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-mongo2: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

查看物理卷信息

[root@localhost ~]# pvs
  PV         VG     Fmt  Attr PSize  PFree
  /dev/sda2  centos lvm2 a--  94.18g 2.18g

[root@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               94.19 GiB / not usable 3.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              24111
  Free PE               559
  Allocated PE          23552
  PV UUID               VZJK2P-I2xp-uBU7-GRT1-1lmv-AR7f-lvidpL

查看卷组信息

[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  centos   1   6   0 wz--n- 94.18g 2.18g
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  19
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                6
  Open LV               5
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               94.18 GiB
  PE Size               4.00 MiB
  Total PE              24111
  Alloc PE / Size       23552 / 92.00 GiB
  Free  PE / Size       559 / 2.18 GiB
  VG UUID               EnXv5G-61bc-tBOR-Zi6e-7Y8L-ygas-19p6jC

查看逻辑卷信息

[root@localhost ~]# lvs
  LV     VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  data   centos -wi-ao---- 50.00g
  home   centos -wi-ao---- 10.00g
  mongo1 centos -wi-ao---- 10.00g
  mongo2 centos -wi-a----- 10.00g
  root   centos -wi-ao---- 10.00g
  swap   centos -wi-ao----  2.00g
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                MOEifJ-qBRF-5gjB-qXB7-jNJa-LW3H-IzClIq
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-06-26 06:56:26 +0000
  LV Status              available
  # open                 1
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/centos/home
  LV Name                home
  VG Name                centos
  LV UUID                7NvaN8-X2k1-woTr-dvxF-ZvjL-OYsD-eX2lEn
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-06-26 06:56:27 +0000
  LV Status              available
  # open                 1
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                eEgY5U-bhWg-74Cl-AKWM-o3k4-9UBd-9NLg4K
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-06-26 06:56:27 +0000
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos/data
  LV Name                data
  VG Name                centos
  LV UUID                FgxSlv-ISnS-0SKH-gTMk-gHCg-5xHh-n4F0yS
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-06-26 06:56:28 +0000
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3

  --- Logical volume ---
  LV Path                /dev/centos/mongo1
  LV Name                mongo1
  VG Name                centos
  LV UUID                6wqmyQ-kII5-hXTa-E3Co-9iRU-626g-TAsUko
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-06-26 06:17:16 +0000
  LV Status              available
  # open                 1
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:4

  --- Logical volume ---
  LV Path                /dev/centos/mongo2
  LV Name                mongo2
  VG Name                centos
  LV UUID                7hl3pj-ye17-1uNd-opVT-25SK-IZWa-iWd2EG
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-06-26 06:33:27 +0000
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:5

查看文件系统及挂载信息

[root@localhost ~]# df -hT
Filesystem                Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   xfs        10G  1.3G  8.7G  14% /
devtmpfs                  devtmpfs  487M     0  487M   0% /dev
tmpfs                     tmpfs     497M     0  497M   0% /dev/shm
tmpfs                     tmpfs     497M  6.7M  490M   2% /run
tmpfs                     tmpfs     497M     0  497M   0% /sys/fs/cgroup
/dev/mapper/centos-home   ext4      9.8G   37M  9.2G   1% /home
/dev/sda1                 xfs       497M  125M  373M  25% /boot
tmpfs                     tmpfs     100M     0  100M   0% /run/user/0
/dev/mapper/centos-data   ext4       50G   63M   47G   1% /data
/dev/mapper/centos-mongo1 ext4      9.8G  337M  8.9G   4% /mongo1

缩减逻辑卷

如果想新建逻辑卷,但卷组中已经没有空余空间,可以缩减已有的逻辑卷,切出一部分空间。

注意:centos默认的xfs格式磁盘,是不支持缩减的,会导致逻辑卷无法挂载,甚至系统无法启动。

  1. /data逻辑卷取消挂载。缩减前,要先将待缩减的卷取消挂载。
umount /data
  1. 检查卷
e2fsck -f /dev/centos/data
  1. 重置/dev/mapper/centos-data卷为10G
resize2fs  /dev/centos/data 10G
lvresize -L 10G /dev/centos/data
  1. 重新挂载/etc/fstab中的所有卷
mount -a

新增卷

通过缩减逻辑卷,卷组中已经空余出37G的空间,可以通地vgs查看。

  1. 新增卷,指定大小为30G,名称为vnew,卷组为centos
lvcreate -L 30G -n vnew centos
  1. 查看新增的卷
lvdisplay
  1. 格式化新增的卷为ext4格式。
mkfs.ext4 /dev/centos/vnew
  1. 创建挂载点文件夹
mkdir /vnew/
  1. 编辑/etc/fstab,添加新增的卷。最后一行,添加如下内容:
/dev/centos/vnew /vnew ext4 defaults 0 0
  1. 重新挂载/etc/fstab中的所有卷。
mount -a
  1. 查看挂载情况
df -Th

删除卷

  1. 取消挂载
umount /vnew
  1. 删除卷
lvremove /dev/centos/vnew

标签:逻辑,管理器,sectors,centos,bytes,dev,LV,LVM,512
来源: https://www.cnblogs.com/shangyingbin/p/14934723.html