Linux LVM root分区 磁盘扩容

2023-05-16

LVM 的基本概念

  • 物理卷 Physical Volume (PV): 可以在上面建立卷组的媒介,可以是硬盘分区,也可以是硬盘本身或者- - 回环文件(loopback file)。物理卷包括一个特殊的 header,其余部分被切割为一块块物理区域(physical extents)
  • 卷组 Volume group (VG): 将一组物理卷收集为一个管理单元
  • 逻辑卷 Logical volume (LV): 虚拟分区,由物理区域(physical extents)组成
  • 物理区域 Physical extent (PE): 硬盘可供指派给逻辑卷的最小单位(通常为 4MB)

lvm原理,具体流程是PV -> VG -> LV,弄懂什么是PV VG LV基本就可以了。
在这里插入图片描述
物理卷: 也就是图中第二层,是通过物理分区创建而来,与物理分区一一对应。创建为物理卷后,则可以将物理卷合并为一个大的卷组。通过命令pvdisplay 查看物理卷

卷组: 也就是图中第三层,卷组是不同的物理卷合并而成,可以将所有物理卷的大小整合成一个大的卷组,相当于一个大的整合的逻辑磁盘,然后在卷组中就可以根据需求划分逻辑卷。通过命令vgdisplay 查看卷组。

逻辑卷: 也就是图中最顶层,逻辑卷是从卷组中划分出来的,相当于逻辑分区,此逻辑卷就可以直接格式化挂载到目录,就可以直接使用了。通过命令lvdisplay 查看逻辑卷。

磁盘操作相关命令

  • 查看挂载点
df -h

# 输出如下
Filesystem                         Size  Used Avail Use% Mounted on
udev                               955M     0  955M   0% /dev
tmpfs                              198M  1.8M  196M   1% /run
## 此处为我们磁盘的挂载点
/dev/mapper/ubuntu--vg-ubuntu--lv   19G  6.0G   12G  35% /
tmpfs                              986M     0  986M   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              986M     0  986M   0% /sys/fs/cgroup
/dev/loop1                          91M   91M     0 100% /snap/core/6350
/dev/loop0                          89M   89M     0 100% /snap/core/6964
/dev/sda2                          976M  143M  767M  16% /boot
  • 显示当前的 logical volume:lvdisplay
lvdisplay

# 输出如下
--- Logical volume ---
LV Path                /dev/ubuntu-vg/ubuntu-lv
LV Name                ubuntu-lv
VG Name                ubuntu-vg
LV UUID                e2fKkR-oZeH-WV2A-ltCi-P76v-N9yv-aUtIg1
LV Write Access        read/write
LV Creation host, time ubuntu-server, 2019-05-14 03:13:57 +0800
LV Status              available
# open                 1
LV Size                <19.00 GiB
Current LE             4863
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:0
  • 显示当前的 volume group
vgdisplay

# 输出如下
--- Volume group ---
VG Name               ubuntu-vg
System ID             
Format                lvm2
Metadata Areas        1
Metadata Sequence No  2
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                1
Open LV               1
Max PV                0
Cur PV                1
Act PV                1
## 这里应该是你当前的可用空间大小,待扩容完毕,这里显示的应该是最终的大小
VG Size               <19.00 GiB
PE Size               4.00 MiB
Total PE              4863
Alloc PE / Size       4863 / <19.00 GiB
Free  PE / Size       0 / 0   
VG UUID               dhI9ns-7lOI-pXf8-IOWL-F96N-JIYG-ZF6u82
  • 显示当前的 physical volume
pvdisplay

# 输出如下
--- Physical volume ---
PV Name               /dev/sda3
VG Name               ubuntu-vg
PV Size               <19.00 GiB / not usable 0   
Allocatable           yes (but full)
PE Size               4.00 MiB
Total PE              4863
Free PE               0
Allocated PE          4863
PV UUID               TDFe2b-xsce-R8So-ldxR-ohcp-fx5J-n2JNOa

开始LVM扩容

查看fdisk

fdisk -l

# 输出如下
Disk /dev/loop0: 88.4 MiB, 92733440 bytes, 181120 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/loop1: 91 MiB, 95408128 bytes, 186344 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/sda: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: gpt
Disk identifier: F96F20D7-1F28-4B03-87CF-4FA3E81FDE29

Device       Start      End  Sectors Size Type
/dev/sda1     2048     4095     2048   1M BIOS boot
/dev/sda2     4096  2101247  2097152   1G Linux filesystem
/dev/sda3  2101248 41940991 39839744  19G Linux filesystem

Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 19 GiB, 20396900352 bytes, 39837696 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

查看所有储存设备

fdisk -l |grep '/dev'

# 输出如下
Disk /dev/loop0: 88.4 MiB, 92733440 bytes, 181120 sectors
Disk /dev/loop1: 91 MiB, 95408128 bytes, 186344 sectors
## 目前只有一块磁盘 sda
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
/dev/sda1     2048     4095     2048   1M BIOS boot
/dev/sda2     4096  2101247  2097152   1G Linux filesystem
/dev/sda3  2101248 41940991 39839744  19G Linux filesystem
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 19 GiB, 20396900352 bytes, 39837696 sectors
# 在虚拟机中挂载多一块磁盘,再操作
fdisk -l |grep '/dev'

# 输出如下
Disk /dev/loop0: 88.4 MiB, 92733440 bytes, 181120 sectors
Disk /dev/loop1: 91 MiB, 95408128 bytes, 186344 sectors
## 挂载的第一块磁盘 sda
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
/dev/sda1     2048     4095     2048   1M BIOS boot
/dev/sda2     4096  2101247  2097152   1G Linux filesystem
/dev/sda3  2101248 41940991 39839744  19G Linux filesystem
## 挂载的第二块磁盘 sdb
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 19 GiB, 20396900352 bytes, 39837696 sectors

创建sdb分区

fdisk /dev/sdb

# 输出如下
Welcome to fdisk (util-linux 2.31.1).
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 0x0de15f1d.

## 在此处输入命令
## n:新建分区
## l: 选择逻辑分区,如果没有,则首先创建主分区(p),然后再添加逻辑分区(硬盘最多四个分区 P-P-P-P 或 P-P-P-E)
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p):

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): 

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

## 在此处输入命令
## w:写入磁盘
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

格式化磁盘

  • 查看分区
fdisk -l |grep '/dev'

# 输出如下
Disk /dev/loop0: 88.4 MiB, 92733440 bytes, 181120 sectors
Disk /dev/loop1: 91 MiB, 95408128 bytes, 186344 sectors
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
/dev/sda1     2048     4095     2048   1M BIOS boot
/dev/sda2     4096  2101247  2097152   1G Linux filesystem
/dev/sda3  2101248 41940991 39839744  19G Linux filesystem
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
## 此时可以看见新创建的分区 /dev/sdb1
/dev/sdb1        2048 41943039 41940992  20G 83 Linux
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 19 GiB, 20396900352 bytes, 39837696 sectors
  • 格式化
    请查好自己系统的文件系统类型,选择对应命令格式化:
    在这里插入图片描述
mkfs -t ext4 /dev/sdb1

# 输出如下
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 5242624 4k blocks and 1310720 inodes
Filesystem UUID: 6f11063f-c118-4099-90fc-2b083c181b23
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
mkfs.xfs -f /dev/sdc2

创建PV

pvcreate /dev/sdb1

# 输出如下
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdb1.
  Physical volume "/dev/sdb1" successfully created.

查看卷组

pvscan

# 输出如下
PV /dev/sda3   VG ubuntu-vg       lvm2 [<19.00 GiB / 0    free]
PV /dev/sdb1                      lvm2 [<20.00 GiB]
Total: 2 [<39.00 GiB] / in use: 1 [<19.00 GiB] / in no VG: 1 [<20.00 GiB]

扩容 VG

  • 查看VG
vgdisplay

# 输出如下
--- Volume group ---
## 我们需要用到 VG Name
VG Name               ubuntu-vg
System ID             
Format                lvm2
Metadata Areas        1
Metadata Sequence No  2
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                1
Open LV               1
Max PV                0
Cur PV                1
Act PV                1
VG Size               <19.00 GiB
PE Size               4.00 MiB
Total PE              4863
Alloc PE / Size       4863 / <19.00 GiB
Free  PE / Size       0 / 0   
VG UUID               dhI9ns-7lOI-pXf8-IOWL-F96N-JIYG-ZF6u82
  • 扩容VG
vgextend ubuntu-vg /dev/sdb1

# 输出如下
Volume group "ubuntu-vg" successfully extended

扩容LV

  • 查看VG
vgdisplay

# 输出如下
--- Volume group ---
VG Name               ubuntu-vg
System ID             
Format                lvm2
Metadata Areas        2
Metadata Sequence No  3
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                1
Open LV               1
Max PV                0
Cur PV                2
Act PV                2
VG Size               38.99 GiB
PE Size               4.00 MiB
Total PE              9982
Alloc PE / Size       4863 / <19.00 GiB
## 这里是可以扩容的大小
Free  PE / Size       5119 / <20.00 GiB
VG UUID               dhI9ns-7lOI-pXf8-IOWL-F96N-JIYG-ZF6u82
  • 查看LV
lvdisplay

# 输出如下
--- Logical volume ---
## 我们需要用到 LV Path
LV Path                /dev/ubuntu-vg/ubuntu-lv
LV Name                ubuntu-lv
VG Name                ubuntu-vg
LV UUID                e2fKkR-oZeH-WV2A-ltCi-P76v-N9yv-aUtIg1
LV Write Access        read/write
LV Creation host, time ubuntu-server, 2019-05-14 03:13:57 +0800
LV Status              available
# open                 1
LV Size                <19.00 GiB
Current LE             4863
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:0
  • 扩容LV
    这个地方截图环境lv vg pv名字和上边不一致,按照自己环境配置扩容即可
[root@node1 ceph-csi-3.7.2]# lvextend -l +100%FREE /dev/cl/root
  Size of logical volume cl/root changed from <161.21 GiB (41269 extents) to 361.20 GiB (92468 extents).
  Logical volume cl/root successfully resized.
[root@node1 ceph-csi-3.7.2]# xfs_growfs /dev/cl/root
meta-data=/dev/mapper/cl-root    isize=512    agcount=11, agsize=4011520 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=42259456, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=7835, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 42259456 to 94687232

  • 刷新分区
    请查好自己系统的文件系统类型,选择对应命令格式化:
resize2fs /dev/ubuntu-vg/ubuntu-lv

# 输出如下
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 5
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 10221568 (4k) blocks long.
xfs_growfs /dev/mapper/centos-root
  • 验证
lvdisplay

--- Logical volume ---
LV Path                /dev/ubuntu-vg/ubuntu-lv
LV Name                ubuntu-lv
VG Name                ubuntu-vg
LV UUID                e2fKkR-oZeH-WV2A-ltCi-P76v-N9yv-aUtIg1
LV Write Access        read/write
LV Creation host, time ubuntu-server, 2019-05-14 03:13:57 +0800
LV Status              available
# open                 1
## 可以看到磁盘扩容成功了
LV Size                38.99 GiB
Current LE             9982
Segments               2
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:0

参考原文地址:

https://blog.csdn.net/u010674101/article/details/118020008
https://www.cnblogs.com/khtt/p/16902118.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Linux LVM root分区 磁盘扩容 的相关文章

  • C++算法库网站 https://zh.cppreference.com/w/cpp/algorithm

    貌似要出国才能访问的C 43 43 标准库api网站 https zh cppreference com w cpp algorithm 有详细的函数介绍 如下图
  • 关于cv.cvtColor转换的问题及解决方法

    问题描述篇 xff1a 今天在调试困扰了我很久的一个问题 xff0c 在训练网络生成batch数据的时候读入原始图像 xff0c 输出的时候却老是出问题 我们都知道YUV和RGB之间的转换关系 xff1a R 61 Y 43 1 4075
  • Nuttx 驱动开发手册

    目录 Nuttx 代码获取编译 Nuttx 启动流程 Nuttx BootLoader 开发之源码分析 gpio 驱动分析 I2c驱动分析 PX4 框架分析 UORB 进程间通讯分析 PX4应用层驱动分析并实现例程 串口驱动GPS 驱动分析
  • 解析小觅中通过双目相机生成深度图的代码

    最近在使用双目摄像机生成深度图 xff0c 研读一下自带的代码 xff0c 做一个记录 第一部分 xff1a 第一部分是定义了一个命名空间 xff0c 其中包含许多个类 第一个类 xff1a 1 代码 GrabCallbacks类主要用于抓
  • altium designer PCB各层介绍+添加多层+设置正/负片+设置层的网络标号

    top layer 顶层 xff0c 用来走线 bottom layer 底层 xff0c 用来走线 mechanical 机械层 xff0c 用来定义PCB形状和尺寸 keepout layer 禁止布线层 xff0c 用来绘制禁布区 t
  • java死锁产生的条件

    以下四个条件同时满足时机会产生死锁 产生死锁的条件互斥 xff0c 共享资源 X 和 Y 只能被一个线程占用 xff1b 占有且等待 xff0c 线程 T1 已经取得共享资源 X xff0c 在等待共享资源 Y 的时候 xff0c 不释放共
  • PID--位置型PID和增量式PID比较

    一 位置型PID 位置型 PID 算法适用于不带积分元件的执行器 执行器的动作位置与其输入信号呈一一对应的关系 控制器根据第 n 次计算机采样结果与给定值之间的偏差 e 来计算出第 n 次采用后所输出的控制变量的值 以调节阀来简单说明 xf
  • 你可能不知道的室内无人机秘密都在这里(二 )

    接上篇 xff1a 你可能不知道的室内无人机秘密都在这里 xff08 一 xff09 如果说上一篇是无人机现状的一些科普知识篇 xff0c 那这篇就直接上干货了 xff0c 希望能真正帮助到喜欢无人机行业 想深入研究无人机的小伙伴们 具体我
  • 漫话程序员们的家庭装修——书房篇

    身为一名程序员 xff0c 辛辛苦苦码代码N年 xff0c 终于攒下钱买了自己的小窝 xff0c 不好好犒劳一下自己都对不起自己的近视眼和鼠标手 这就来分享一下我装修的心得 xff0c 从书房开始 xff01 书房作为程序员在公司战斗一天回
  • Windows下使用vscode 调试linux kernel

    安装WSL2 在microsoft store上安装Ubuntu xff0c 当不能安装时可能需要梯子window中访问Ubuntu的目录使用 xff1a wsl Ubuntu中需要修改软件源 xff1a 参考 https mirrors
  • 计算器算法----C语言实现(堆栈法)

    1 字符串去空格处理 实现一 xff1a span class hljs keyword void span spacess span class hljs keyword char span span class hljs keyword
  • 链接脚本

    本文转自 xff1a http www cnblogs com li hao p 4107964 html 一 概论 每一个链接过程都由 链接脚本 linker script 一般以lds作为文件的后缀名 控制 链接脚本 主要用于规定如何把
  • 记录2017/9/7趋势科技笔试题

    1 下面程序一共会在屏幕上输出多少个 xff1f include lt iostream gt include lt stdio h gt include lt sys types h gt include lt unistd h gt u
  • 字节对齐算法

    ps xff1a 遇见这种算法纯属一个巧合 xff0c 刚入职的我 xff0c 在忙着调用各种SDK中的API xff0c 无暇顾及代码的具体实现 xff0c 有些代码还被屏蔽了 xff0c 在写flash的过程中 xff0c 参考了前辈们
  • UCOSIII学习笔记

    目录 1 学习环境 2 滴答定时器 3 任务 3 1 UCOSIII系统任务 3 2 UCOSIII任务状态 3 3 UCOSIII任务调度 3 4 任务相关的API函数 3 5 钩子函数 4 UCOSIII的中断 5 UCOSIII的临界
  • QCC5125----GAIA

    1 描述 GAIA全称 xff1a Generic Application Interface Architecture xff0c 实现了端到端 xff0c 主机无关的生态系统 xff0c 支持主机应用程序访问设备功能 底层的数据包由8个
  • 【SQLserver】使用openrowset方法导入EXCEL表格数据

    一 前言 在之前的一篇博文中记录了用OPENDATASOURCE函数将EXCEL数据写入SQLserver表中的方法 这一方法需要表名sheet1为固定名称不可更改 实际业务中可能会遇到表名随着日期而改动的情况 xff0c 如果excel表
  • PDM

    PDM Pulse Density Modulation 1 Protocols Introduction1 1 PDM Introduction1 2 PCM Introduction1 3 PDM To PCM 2 PDM Struct
  • FreeRTOS --(1)链表

    Based On FreeRTOS Kernel V10 3 1 1 相关文件 链表结构是 OS 内部经常使用到的 xff0c FreeRTOS 自然也不例外 xff0c 在深入分析各个模块的工作原理之前 xff0c 首先来分析 FreeR
  • FreeRTOS --(3)任务管理之创建任务

    目录 1 描述任务的结构 2 任务创建 2 1 xTaskCreate 2 2 prvInitialiseNewTask 2 3 pxPortInitialiseStack 2 4 prvAddNewTaskToReadyList 在 Fr

随机推荐