LVM(Logical Volume Manager)
2025-08-22 16:02:25,

一. LVM概述

1. 什么是 LVM

LVM(LogiC++al 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列表

# 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)

0

5.2 创建lv

# 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)

1

5.3 再次查看现有的lv列表

# 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)

2

6. 格式化lv设备

6.1 查看lv的设备存储路径

# 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)

3

6.2 格式化lv设备

# 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)

4

7. 挂载lv设备

7.1 创建挂载点

# 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)

5

7.2 挂载lv设备

# 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)

6

7.3 查看lv设备挂载信息

# 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)

7

三. LVM扩展案例

1. 扩展lv案例

1.1 扩容到指定大小ext4案例

# 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)

8

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

# 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)

9

2. 扩展vg案例

2.1 环境准备

2.2 扩容vg案例

# 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
0

3. 移除现有的vg

3.1 卸载设备

# 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
1

3.2 移除vg列表等待所有lv

# 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

3.3 移除所有的vg

# 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
3