腾进电子 发表于 2023-2-1 21:46:37

认识和使用LVM,过一遍!

疑惑

最近在反复搭建ceph集群过程中,总是遇到osd创建不成功的问题,疑似硬盘残留信息,排查中引出了很多陌生的命令,比如vgremove等,于是打算重新了解这部分。
LVM是什么?

逻辑卷管理器(LVM,Logical Volume Manager)是一种把硬盘空间分配成逻辑卷的方法。
看到定义可能还比较懵,不妨结合场景:
有一块系统盘空间随着时间推移容量需要扩容该怎么做?
这时候使用LVM就比较方便了,它可以弹性的调整文件系统的容量,可以整合多个物理分区在一起,让这些分区看起来像是一个磁盘一样。通俗理解就是它可以将很多硬盘/分区全部拿过来作为一个资源池,然后自己再随意划分成逻辑层面的分区,那么这个分区后期进行扩容缩容删除就比较方便了!LVM相关概念

1、Physical Volume,PV,物理卷

# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.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
Building a new DOS disklabel with disk identifier 0x172f2548.

Command (m for help): p                                        ###输入 p 查看分区情况

Disk /dev/sdb: 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 label type: dos
Disk identifier: 0x172f2548

   Device Boot      Start         End      Blocks   IdSystem

Command (m for help): n                                    ###输入 n 创建新分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p                                        ### 默认是 p ,创建主分区,视情况而定
Partition number (1-4, default 1): 1                         ###这里做第一块主分区
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): p                                    ###再次输入 p 查看分区情况

Disk /dev/sdb: 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 label type: dos
Disk identifier: 0x172f2548

   Device Boot      Start         End      Blocks   IdSystem
/dev/sdb1            2048    20971519    10484736   83Linux

Command (m for help): w                                 ###最后输入 w 保存从sdb分出来的sdb1   
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.fdisk -l查看是否分区成功
# fdisk -l

Disk /dev/sdb: 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 label type: dos
Disk identifier: 0x172f2548

   Device Boot      Start         End      Blocks   IdSystem
/dev/sdb1            2048    20971519    10484736   83Linux可以看到实际分区Id字段为83,使用时需要通过 fdisk 命令将Id字段调整为8e(LVM 的标识符),再经过 pvcreate 命令将它转为 LVM 最底层的物理卷(PV),之后这些PV才能够被利用
# fdisk /dev/sdbWelcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Command (m for help): t                                  ###输入 t 修改分区类型Selected partition 1Hex code (type L to list all codes): L                   ###输入 L 列出所有分区类型 0Empty         24NEC DOS         81Minix / old Lin bfSolaris 1FAT12         27Hidden NTFS Win 82Linux swap / So c1DRDOS/sec (FAT- 2XENIX root      39Plan 9          83Linux         c4DRDOS/sec (FAT- 3XENIX usr       3cPartitionMagic84OS/2 hidden C:c6DRDOS/sec (FAT- 4FAT16
页: [1]
查看完整版本: 认识和使用LVM,过一遍!