LVM(Logical Volume Manager)

一. LVM概述

1. 什么是 LVM

LVM(Logical Volume Manager,逻辑卷管理器)是 Linux 系统下的一种 存储管理 机制,能够灵活地管理磁盘分区。它提供了一种比传统分区管理(如fdiskparted)更高级的存储管理方式,允许动态调整存储空间,方便扩展和缩减分区,而不会影响已有数据。

2. LVM 主要概念

LVM 的核心概念类似于 RAID 或虚拟存储池,其主要组成部分如下:

  1. PV(Physical Volume,物理卷)

    • LVM 的最底层单位,可以是整个硬盘,也可以是一个分区。

    • 通过 pvcreate 将物理磁盘或分区初始化为 LVM 可用的 PV。

  2. VG(Volume Group,卷组)

    • 由多个 PV 组成的存储池,所有的存储空间都可以在 VG 内部动态分配。
    • 通过 vgcreate 创建 VG。
  3. LV(Logical Volume,逻辑卷)

    • 相当于传统的“分区”,可以格式化文件系统(如ext4xfs),然后挂载使用。
    • 通过 lvcreate 创建 LV,大小可以随时扩展或缩小(前提是文件系统支持)。
  4. PE(Physical Extents,物理分块)

    • LVM 内部的最小存储单元,默认大小 4MB(可调整)。
    • VG 内的空间被划分成若干个 PE,LV 的大小由 PE 数量决定。
    ┌───────────────────────────────┐
    │        物理磁盘(sdb, sdc)     │
    │  (未初始化)                     │
    └───────────────────────────────┘
             ↓ pvcreate
    ┌───────────────────────────────┐
    │        物理卷(PV)             │
    │  /dev/sdb   /dev/sdc          │
    └───────────────────────────────┘
             ↓ vgcreate
    ┌───────────────────────────────┐
    │        卷组(VG)               │
    │  my_vg = PV1 + PV2             │
    │  (存储池)                       │
    └───────────────────────────────┘
             ↓ lvcreate
    ┌───────────────────────────────┐
    │        逻辑卷(LV)             │
    │  /dev/my_vg/my_lv (50G)       │
    │  (类似于分区,可格式化挂载)        │
    └───────────────────────────────┘
    

3. LVM 的优势

  • 动态扩展与缩减存储:可在不停机的情况下扩展 LV 或 VG,而无需重新分区。
  • 跨多块磁盘管理:可以将多块磁盘合并为一个存储池(VG),提高存储利用率。
  • 快照(Snapshot):支持创建数据快照,方便数据备份与恢复。
  • 条带化存储(Striping):类似 RAID 0,提高磁盘 I/O 性能。

4. LVM 基本操作

# 1. 创建物理卷
pvcreate /dev/sdb /dev/sdc

# 2. 创建卷组
vgcreate my_vg /dev/sdb /dev/sdc

# 3. 创建逻辑卷(比如创建 10GB 的逻辑卷)
lvcreate -L 10G -n my_lv my_vg

# 4. 格式化并挂载
mkfs.ext4 /dev/my_vg/my_lv
mkdir /mnt/lvm_mount
mount /dev/my_vg/my_lv /mnt/lvm_mount

# 5. 扩展逻辑卷
lvextend -L +5G /dev/my_vg/my_lv   # 增加 5GB
resize2fs /dev/my_vg/my_lv         # 扩展文件系统(ext4)

二. LVM 实战操作

1. 环境准备

2. 对磁盘分区

2.1 使用 fdisk 对 /dev/sdc 进行分区

# 1.进入 fdisk 交互模式
[root@lvm:~]# fdisk /dev/sdc

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x0313bb2e.

# 2.查看磁盘信息
Command (m for help): p
Disk /dev/sdc: 300 GiB, 322122547200 bytes, 629145600 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0313bb2e
# 发现磁盘 /dev/sdc 没有有效的分区表,默认是 dos 分区表。

# 3.创建 GPT 分区表
Command (m for help): g
Created a new GPT disklabel (GUID: F96B7C68-81FB-D14C-A17D-C686B732B937).

# 4.创建第一个 100G 分区
Command (m for help): n
Partition number (1-128, default 1):	# 分区编号(默认 1) 
First sector (2048-629145566, default 2048):	# 起始扇区(默认 2048)
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-629145566, default 629145566): +100G

Created a new partition 1 of type 'Linux filesystem' and of size 100 GiB.
# 成功创建 /dev/sdc1 分区,大小 100G

# 5.创建第二个 200G 分区
Command (m for help): n
Partition number (2-128, default 2):	# 分区编号(默认 2) 
First sector (209717248-629145566, default 209717248):	# 起始扇区(默认 209717248) 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (209717248-629145566, default 629145566): 

Created a new partition 2 of type 'Linux filesystem' and of size 200 GiB.
# 成功创建 /dev/sdc2 分区,大小 200G

# 6.查看分区情况
Command (m for help): p
Disk /dev/sdc: 300 GiB, 322122547200 bytes, 629145600 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: F96B7C68-81FB-D14C-A17D-C686B732B937

Device         Start       End   Sectors  Size Type
/dev/sdc1       2048 209717247 209715200  100G Linux filesystem
/dev/sdc2  209717248 629145566 419428319  200G Linux filesystem

# 7.保存分区表并退出
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

# 8.验证分区是否生效
[root@lvm:~]# fdisk -l /dev/sdc
Disk /dev/sdc: 300 GiB, 322122547200 bytes, 629145600 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: F96B7C68-81FB-D14C-A17D-C686B732B937

Device         Start       End   Sectors  Size Type
/dev/sdc1       2048 209717247 209715200  100G Linux filesystem
/dev/sdc2  209717248 629145566 419428319  200G Linux filesystem

2.2 对/dev/sde进行分区

[root@lvm:~]# fdisk -l /dev/sde
Disk /dev/sde: 1 TiB, 1099511627776 bytes, 2147483648 sectors
Disk model: VMware Virtual S
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@lvm:~]# fdisk /dev/sde

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xf8cc9c96.

Command (m for help): p
Disk /dev/sde: 1 TiB, 1099511627776 bytes, 2147483648 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xf8cc9c96

Command (m for help): g
Created a new GPT disklabel (GUID: 7B0A9C2B-F3B1-3A42-9665-8640DFC613DC).

Command (m for help): n
Partition number (1-128, default 1): 
First sector (2048-2147483614, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-2147483614, default 2147483614): +500G

Created a new partition 1 of type 'Linux filesystem' and of size 500 GiB.

Command (m for help): n
Partition number (2-128, default 2): 
First sector (1048578048-2147483614, default 1048578048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1048578048-2147483614, default 2147483614): 

Created a new partition 2 of type 'Linux filesystem' and of size 524 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@lvm:~]# fdisk -l /dev/sde
Disk /dev/sde: 1 TiB, 1099511627776 bytes, 2147483648 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 7B0A9C2B-F3B1-3A42-9665-8640DFC613DC

Device          Start        End    Sectors  Size Type
/dev/sde1        2048 1048578047 1048576000  500G Linux filesystem
/dev/sde2  1048578048 2147483614 1098905567  524G Linux filesystem

2.3 检查磁盘分区情况

3. 创建pv

3.1 查看现有的pv列表

[root@lvm:~]# pvs
  PV         VG        Fmt  Attr PSize   PFree
  /dev/sda3  ubuntu-vg lvm2 a--  <48.00g    0 

3.2 创建pv

[root@lvm:~]# pvcreate /dev/sdb /dev/sdc{1,2} /dev/sdd /dev/sde{1,2}
  Physical volume "/dev/sdb" successfully created.
  Physical volume "/dev/sdc1" successfully created.
  Physical volume "/dev/sdc2" successfully created.
  Physical volume "/dev/sdd" successfully created.
  Physical volume "/dev/sde1" successfully created.
  Physical volume "/dev/sde2" successfully created.

3.3 再次查看现有的pv列表

[root@lvm:~]# pvs
  PV         VG        Fmt  Attr PSize    PFree   
  /dev/sda3  ubuntu-vg lvm2 a--   <48.00g       0 
  /dev/sdb             lvm2 ---   100.00g  100.00g
  /dev/sdc1            lvm2 ---   100.00g  100.00g
  /dev/sdc2            lvm2 ---  <200.00g <200.00g
  /dev/sdd             lvm2 ---   500.00g  500.00g
  /dev/sde1            lvm2 ---   500.00g  500.00g
  /dev/sde2            lvm2 ---  <524.00g <524.00g

4. 创建vg

4.1 查看现有的vg列表

[root@lvm:~]# vgs
  VG        #PV #LV #SN Attr   VSize   VFree
  ubuntu-vg   1   1   0 wz--n- <48.00g    0 

4.2 创建vg

[root@lvm:~]# vgcreate vg01 /dev/sdb /dev/sdc1 /dev/sdc2
  Volume group "vg01" successfully created
[root@lvm:~]# vgcreate vg02 /dev/sdd /dev/sde1 /dev/sde2
  Volume group "vg02" successfully created

4.3 再次查看现有的vg列表

[root@lvm:~]# vgs
  VG        #PV #LV #SN Attr   VSize    VFree   
  ubuntu-vg   1   1   0 wz--n-  <48.00g       0 
  vg01        3   0   0 wz--n- <399.99g <399.99g
  vg02        3   0   0 wz--n-   <1.49t   <1.49t

5. 创建lv

5.1 查看现有的lv列表

[root@lvm:~]# lvs
  LV        VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  ubuntu-lv ubuntu-vg -wi-ao---- <48.00g 

5.2 创建lv

[root@lvm:~]# lvcreate vg01 --name lv01 --size 50G
  Logical volume "lv01" created.
[root@lvm:~]# lvcreate vg01 --name lv02 --size 100G
  Logical volume "lv02" created.
[root@lvm:~]# lvcreate vg02 --name lv03 --size 20G
  Logical volume "lv03" created.
[root@lvm:~]# lvcreate vg02 --name lv04 --size 50G
  Logical volume "lv04" created.

5.3 再次查看现有的lv列表

[root@lvm:~]# pvs
  PV         VG        Fmt  Attr PSize    PFree   
  /dev/sda3  ubuntu-vg lvm2 a--   <48.00g       0 
  /dev/sdb   vg01      lvm2 a--  <100.00g  <50.00g
  /dev/sdc1  vg01      lvm2 a--  <100.00g <100.00g
  /dev/sdc2  vg01      lvm2 a--  <200.00g <100.00g
  /dev/sdd   vg02      lvm2 a--  <500.00g <430.00g
  /dev/sde1  vg02      lvm2 a--  <500.00g <500.00g
  /dev/sde2  vg02      lvm2 a--  <524.00g <524.00g
[root@lvm:~]# 
[root@lvm:~]# vgs
  VG        #PV #LV #SN Attr   VSize    VFree   
  ubuntu-vg   1   1   0 wz--n-  <48.00g       0 
  vg01        3   2   0 wz--n- <399.99g <249.99g
  vg02        3   2   0 wz--n-   <1.49t   <1.42t
[root@lvm:~]# 
[root@lvm:~]# lvs
  LV        VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  ubuntu-lv ubuntu-vg -wi-ao---- <48.00g                                                    
  lv01      vg01      -wi-a-----  50.00g                                                    
  lv02      vg01      -wi-a----- 100.00g                                                    
  lv03      vg02      -wi-a-----  20.00g                                                    
  lv04      vg02      -wi-a-----  50.00g 

6. 格式化lv设备

6.1 查看lv的设备存储路径

[root@lvm:~]# ll /dev/vg01
total 0
drwxr-xr-x  2 root root   80 Feb 25 16:25 ./
drwxr-xr-x 22 root root 4460 Feb 25 16:26 ../
lrwxrwxrwx  1 root root    7 Feb 25 16:25 lv01 -> ../dm-1
lrwxrwxrwx  1 root root    7 Feb 25 16:25 lv02 -> ../dm-2

[root@lvm:~]# ll /dev/vg02
total 0
drwxr-xr-x  2 root root   80 Feb 25 16:26 ./
drwxr-xr-x 22 root root 4460 Feb 25 16:26 ../
lrwxrwxrwx  1 root root    7 Feb 25 16:25 lv03 -> ../dm-3
lrwxrwxrwx  1 root root    7 Feb 25 16:26 lv04 -> ../dm-4

[root@lvm:~]# ll /dev/mapper/
total 0
drwxr-xr-x  2 root root     160 Feb 25 16:26 ./
drwxr-xr-x 22 root root    4460 Feb 25 16:26 ../
crw-------  1 root root 10, 236 Feb 25 16:02 control
lrwxrwxrwx  1 root root       7 Feb 25 16:02 ubuntu--vg-ubuntu--lv -> ../dm-0
lrwxrwxrwx  1 root root       7 Feb 25 16:25 vg01-lv01 -> ../dm-1
lrwxrwxrwx  1 root root       7 Feb 25 16:25 vg01-lv02 -> ../dm-2
lrwxrwxrwx  1 root root       7 Feb 25 16:25 vg02-lv03 -> ../dm-3
lrwxrwxrwx  1 root root       7 Feb 25 16:26 vg02-lv04 -> ../dm-4

6.2 格式化lv设备

# 1.格式化为ext4文件系统
[root@lvm:~]# mkfs.ext4 /dev/vg01/lv01
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 13107200 4k blocks and 3276800 inodes
Filesystem UUID: e8267825-be6f-4b78-ac78-3a1ddcef678d
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (65536 blocks): done
Writing superblocks and filesystem accounting information: done   

# 2.格式化为ntfs文件系统(速度较慢) 
[root@lvm:~]# mkfs.ntfs /dev/vg01/lv02
Cluster size has been automatically set to 4096 bytes.
Initializing device with zeroes: 100% - Done.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.

# 3.格式化为fat件系统
[root@lvm:~]# mkfs.fat /dev/vg02/lv03
mkfs.fat 4.2 (2021-01-31)

# 4.格式化为xfs文件系统
[root@lvm:~]# mkfs.xfs /dev/vg02/lv04
meta-data=/dev/vg02/lv04         isize=512    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

7. 挂载lv设备

7.1 创建挂载点

[root@lvm:~]# mkdir -p /caixiangjia/{ext4,ntfs,fat,xfs}
[root@lvm:~]# ll /caixiangjia/
total 16
drwxr-xr-x 2 root root 4096 Feb 25 16:44 ext4/
drwxr-xr-x 2 root root 4096 Feb 25 16:44 fat/
drwxr-xr-x 2 root root 4096 Feb 25 16:44 ntfs/
drwxr-xr-x 2 root root 4096 Feb 25 16:44 xfs/

7.2 挂载lv设备

[root@lvm:~]# mount /dev/vg01/lv01 /caixiangjia/ext4/
[root@lvm:~]# mount /dev/vg01/lv02 /caixiangjia/ntfs/
[root@lvm:~]# mount /dev/vg02/lv03 /caixiangjia/fat/
[root@lvm:~]# mount /dev/vg02/lv04 /caixiangjia/xfs/

7.3 查看lv设备挂载信息

[root@lvm:~]# mount | grep caixiangjia
/dev/mapper/vg01-lv01 on /caixiangjia/ext4 type ext4 (rw,relatime)
/dev/mapper/vg01-lv02 on /caixiangjia/ntfs type fuseblk (rw,relatime,user_id=0,group_id=0,allow_other,blksize=4096)
/dev/mapper/vg02-lv03 on /caixiangjia/fat type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
/dev/mapper/vg02-lv04 on /caixiangjia/xfs type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)

[root@lvm:~]# df -h | grep caixiangjia
/dev/mapper/vg01-lv01               49G   24K   47G   1% /caixiangjia/ext4
/dev/mapper/vg01-lv02              100G   68M  100G   1% /caixiangjia/ntfs
/dev/mapper/vg02-lv03               20G   16K   20G   1% /caixiangjia/fat
/dev/mapper/vg02-lv04               50G  390M   50G   1% /caixiangjia/xfs

三. LVM扩展案例

1. 扩展lv案例

1.1 扩容到指定大小ext4案例

# 1.扩容前查看
[root@lvm:~]# df -h | grep caixiangjia
/dev/mapper/vg01-lv01               49G   24K   47G   1% /caixiangjia/ext4
/dev/mapper/vg01-lv02              100G   68M  100G   1% /caixiangjia/ntfs
/dev/mapper/vg02-lv03               20G   16K   20G   1% /caixiangjia/fat
/dev/mapper/vg02-lv04               50G  390M   50G   1% /caixiangjia/xfs

[root@lvm:~]# fdisk -l /dev/mapper/vg01-lv01
Disk /dev/mapper/vg01-lv01: 50 GiB, 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

[root@lvm:~]# vgs
  VG        #PV #LV #SN Attr   VSize    VFree   
  ubuntu-vg   1   1   0 wz--n-  <48.00g       0 
  vg01        3   2   0 wz--n- <399.99g <249.99g
  vg02        3   2   0 wz--n-   <1.49t   <1.42t

# 2.开始扩容
[root@lvm:~]# lvextend /dev/mapper/vg01-lv01 --size 150G
  Size of logical volume vg01/lv01 changed from 50.00 GiB (12800 extents) to 150.00 GiB (38400 extents).
  Logical volume vg01/lv01 successfully resized.
  
[root@lvm:~]# vgs
  VG        #PV #LV #SN Attr   VSize    VFree   
  ubuntu-vg   1   1   0 wz--n-  <48.00g       0 
  vg01        3   2   0 wz--n- <399.99g <149.99g
  vg02        3   2   0 wz--n-   <1.49t   <1.42t
  
[root@lvm:~]# df -h | grep caixiangjia
/dev/mapper/vg01-lv01               49G   24K   47G   1% /caixiangjia/ext4
/dev/mapper/vg01-lv02              100G   68M  100G   1% /caixiangjia/ntfs
/dev/mapper/vg02-lv03               20G   16K   20G   1% /caixiangjia/fat
/dev/mapper/vg02-lv04               50G  390M   50G   1% /caixiangjia/xfs

[root@lvm:~]# fdisk -l /dev/mapper/vg01-lv01
Disk /dev/mapper/vg01-lv01: 150 GiB, 161061273600 bytes, 314572800 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

3.使用 resize2fs 工具刷新最新的挂载表
[root@lvm:~]# resize2fs /dev/mapper/vg01-lv01 
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/mapper/vg01-lv01 is mounted on /caixiangjia/ext4; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 19
The filesystem on /dev/mapper/vg01-lv01 is now 39321600 (4k) blocks long.

[root@lvm:~]# df -h | grep caixiangjia
/dev/mapper/vg01-lv01              148G   24K  141G   1% /caixiangjia/ext4
/dev/mapper/vg01-lv02              100G   68M  100G   1% /caixiangjia/ntfs
/dev/mapper/vg02-lv03               20G   16K   20G   1% /caixiangjia/fat
/dev/mapper/vg02-lv04               50G  390M   50G   1% /caixiangjia/xfs

1.2 剩余空间全部扩容xfs案例

# 1.扩容前查看
[root@lvm:~]# vgs
  VG        #PV #LV #SN Attr   VSize    VFree   
  ubuntu-vg   1   1   0 wz--n-  <48.00g       0 
  vg01        3   2   0 wz--n- <399.99g <149.99g
  vg02        3   2   0 wz--n-   <1.49t   <1.42t
  
[root@lvm:~]# lvs
  LV        VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  ubuntu-lv ubuntu-vg -wi-ao---- <48.00g                                                    
  lv01      vg01      -wi-ao---- 150.00g                                                    
  lv02      vg01      -wi-ao---- 100.00g                                                    
  lv03      vg02      -wi-ao----  20.00g                                                    
  lv04      vg02      -wi-ao----  50.00g   


# 2.将vg剩余的所有空间扩容到指定的lv
[root@lvm:~]# lvextend /dev/mapper/vg02-lv04 -l +100%FREE
  Size of logical volume vg02/lv04 changed from 50.00 GiB (12800 extents) to <1.47 TiB (385021 extents).
  Logical volume vg02/lv04 successfully resized.
  
[root@lvm:~]# vgs
  VG        #PV #LV #SN Attr   VSize    VFree   
  ubuntu-vg   1   1   0 wz--n-  <48.00g       0 
  vg01        3   2   0 wz--n- <399.99g <149.99g
  vg02        3   2   0 wz--n-   <1.49t       0     # 此时不难发现,vg的空间已经完全用完了

[root@lvm:~]# fdisk -l /dev/mapper/vg02-lv04
Disk /dev/mapper/vg02-lv04: 1.47 TiB, 1614895120384 bytes, 3154092032 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  


# 3.自动扩展XFS文件系统到最大的可用大小
[root@lvm:~]# df -h | grep caixiangjia
/dev/mapper/vg01-lv01              148G   24K  141G   1% /caixiangjia/ext4
/dev/mapper/vg01-lv02              100G   68M  100G   1% /caixiangjia/ntfs
/dev/mapper/vg02-lv03               20G   16K   20G   1% /caixiangjia/fat
/dev/mapper/vg02-lv04               50G  390M   50G   1% /caixiangjia/xfs

[root@lvm:~]# xfs_growfs /caixiangjia/xfs/
meta-data=/dev/mapper/vg02-lv04  isize=512    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13107200 to 394261504

[root@lvm:~]# df -h | grep caixiangjia
/dev/mapper/vg01-lv01              148G   24K  141G   1% /caixiangjia/ext4
/dev/mapper/vg01-lv02              100G   68M  100G   1% /caixiangjia/ntfs
/dev/mapper/vg02-lv03               20G   16K   20G   1% /caixiangjia/fat
/dev/mapper/vg02-lv04              1.5T   11G  1.5T   1% /caixiangjia/xfs

2. 扩展vg案例

2.1 环境准备

2.2 扩容vg案例

# 1.查看现有的vg列表
[root@lvm:~]# vgs
  VG        #PV #LV #SN Attr   VSize    VFree   
  ubuntu-vg   1   1   0 wz--n-  <48.00g       0 
  vg01        3   2   0 wz--n- <399.99g <149.99g
  vg02        3   2   0 wz--n-   <1.49t       0 

# 2.创建pv
[root@lvm:~]# pvcreate /dev/sdf /dev/sdg
  Physical volume "/dev/sdf" successfully created.
  Physical volume "/dev/sdg" successfully created.

# 3.将pv加入到vg02中
[root@lvm:~]# vgextend vg02 /dev/sdf /dev/sdg
  Volume group "vg02" successfully extended

# 4.再次查看现有的vg列表
[root@lvm:~]# vgs
  VG        #PV #LV #SN Attr   VSize    VFree   
  ubuntu-vg   1   1   0 wz--n-  <48.00g       0 
  vg01        3   2   0 wz--n- <399.99g <149.99g
  vg02        5   2   0 wz--n-   <3.49t   <2.00t

3. 移除现有的vg

3.1 卸载设备

[root@lvm:~]# umount /dev/caixiangjia/ext4/
[root@lvm:~]# umount /dev/caixiangjia/ntfs/
[root@lvm:~]# umount /dev/caixiangjia/fat/
[root@lvm:~]# umount /dev/caixiangjia/xfs/
[root@lvm:~]# df -h | grep caixiangjia
[root@lvm:~]# 

3.2 移除vg列表等待所有lv

[root@lvm:~]# lvs
  LV        VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  ubuntu-lv ubuntu-vg -wi-ao---- <48.00g                                                    
  lv01      vg01      -wi-a----- 150.00g                                                    
  lv02      vg01      -wi-a----- 100.00g                                                    
  lv03      vg02      -wi-a-----  20.00g                                                    
  lv04      vg02      -wi-a-----  <1.47t                                                    

[root@lvm:~]# lvremove vg01 --force 
  Logical volume "lv01" successfully removed
  Logical volume "lv02" successfully removed

[root@lvm:~]# lvremove vg02 --force 
  Logical volume "lv03" successfully removed
  Logical volume "lv04" successfully removed

[root@lvm:~]# lvs
  LV        VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  ubuntu-lv ubuntu-vg -wi-ao---- <48.00g 

3.3 移除所有的vg

[root@lvm:~]# vgs
  VG        #PV #LV #SN Attr   VSize    VFree   
  ubuntu-vg   1   1   0 wz--n-  <48.00g       0 
  vg01        3   0   0 wz--n- <399.99g <399.99g
  vg02        5   0   0 wz--n-   <3.49t   <3.49t

[root@lvm:~]# vgremove vg01
  Volume group "vg01" successfully removed
  
[root@lvm:~]# vgremove vg02
  Volume group "vg02" successfully removed
  
[root@lvm:~]# vgs
  VG        #PV #LV #SN Attr   VSize   VFree
  ubuntu-vg   1   1   0 wz--n- <48.00g    0 
posted @   cxjyyds  阅读(10)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示