LVM(LogiC++al Volume Manager,逻辑卷管理器)是 Linux 系统下的一种 存储管理 机制,能够灵活地管理磁盘分区。它提供了一种比传统分区管理(如fdisk
、parted
)更高级的存储管理方式,允许动态调整存储空间,方便扩展和缩减分区,而不会影响已有数据。
LVM 的核心概念类似于 RAID 或虚拟存储池,其主要组成部分如下:
PV(Physical Volume,物理卷)
LVM 的最底层单位,可以是整个硬盘,也可以是一个分区。
通过 pvcreate
将物理磁盘或分区初始化为 LVM 可用的 PV。
VG(Volume Group,卷组)
vgcreate
创建 VG。LV(Logical Volume,逻辑卷)
ext4
、xfs
),然后挂载使用。lvcreate
创建 LV,大小可以随时扩展或缩小(前提是文件系统支持)。PE(Physical Extents,物理分块)
┌───────────────────────────────┐
│ 物理磁盘(sdb, sdc) │
│ (未初始化) │
└───────────────────────────────┘
↓ pvcreate
┌───────────────────────────────┐
│ 物理卷(PV) │
│ /dev/sdb /dev/sdc │
└───────────────────────────────┘
↓ vgcreate
┌───────────────────────────────┐
│ 卷组(VG) │
│ my_vg = PV1 + PV2 │
│ (存储池) │
└───────────────────────────────┘
↓ lvcreate
┌───────────────────────────────┐
│ 逻辑卷(LV) │
│ /dev/my_vg/my_lv (50G) │
│ (类似于分区,可格式化挂载) │
└───────────────────────────────┘
# 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.进入 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
[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
[root@lvm:~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 ubuntu-vg lvm2 a-- <48.00g 0
[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.
[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
[root@lvm:~]# vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 1 0 wz--n- <48.00g 0
[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
[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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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. 创建物理卷
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
# 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
# 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
# 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
# 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