[Linux]LVM扩展卷
LVM
LVM是逻辑盘卷管理(Logical Volume Manager)的简称,它是Linux环境下对磁盘分区进行管理的一种机制,LVM是建立在硬盘和分区之上的一个逻辑层,来提高磁盘分区管理的灵活性。LVM是在磁盘分区和文件系统之间添加的一个逻辑层,来为文件系统屏蔽下层磁盘分区布局,提供一个抽象的盘卷,在盘卷上建立文件系统。物理卷(physical volume)物理卷就是指硬盘分区或从逻辑上与磁盘分区具有同样功能的设备(如RAID),是LVM的基本存储逻辑块,但和基本的物理存储介质(如分区、磁盘等)比较,却包含有与LVM相关的管理参数。
优势:能够在线扩容当前的分区容量。
结构:在整个LVM结构当中以此分为:“物理卷、物理卷分区、卷组、逻辑卷”,下面我详细解释一下这四种结构:
物理卷:Physical Volume,简称PV,一个物理卷只不过是一个有LVM管理数据添加在里面的物理存储介质。要使用LVM系统,首先对要用于LVM的磁盘进行初始化,初始化的目的就是将磁盘或分区标识为LVM 的物理卷。使用pvcreate 命令可以将一个磁盘标记为 LVM 物理卷。
物理分区:Physical Extents,简称PE,LVM将每个物理卷分别叫做物理分区的可寻址存储单元,存储单元的大小通常为几MB。磁盘的开头部分为LVM元数据,之后从索引为零开始,每个物理分区的索引依次递增一,按顺序进行分配。
卷组:Volume Group,简称VG,物理卷可以组织为卷组。卷组可以由一个或多个物理卷组成,同时系统中可以有多个卷组。创建了卷组之后,该卷组(而不是磁盘)便是表示数据存储的实体。因此,尽管以前是将磁盘从一个系统移动到另一个系统,使用了 LVM 之后,会将卷组从一个系统移动到另一个系统。出于这种原因,通常在一个系统上创建多个卷组会比较方便。
逻辑分区:Logical Extents,简称LE,逻辑卷的基本分配单元称为逻辑分区。逻辑分区映射到物理分区,因此,如果物理分区的尺寸小为4MB,那么逻辑分区的尺寸也将为4MB。逻辑卷的大小取决于所分配的逻辑分区数量。
生产环境
[root@Nexus3 ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@Nexus3 ~]# lvm version
LVM version: 2.02.185(2)-RHEL7 (2019-05-13)
Library version: 1.02.158-RHEL7 (2019-05-13)
Driver version: 4.37.1
硬盘扩容20G->100G
[root@Nexus3 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 8.8M 3.9G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
-----/dev/mapper/centos-root是我们需要扩的卷-------------------------
/dev/mapper/centos-root xfs 17G 1.2G 16G 7% /
/dev/sda1 xfs 1014M 136M 879M 14% /boot
tmpfs tmpfs 799M 0 799M 0% /run/user/0
查看本地物理硬盘
[root@Nexus3 ~]# fdisk -l
-----磁盘容量100G-------------------------
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000c35ff
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
-----正在使用18.2G,我们需要将此硬盘扩容-------------------------
Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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@Nexus3 ~]# fdisk /dev/sda
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.
-----列出当前分区-------------------------
Command (m for help): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000c35ff
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
-----注意后面Id System 后面用到-------------------------
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
-----创建分区n,一路回车就会创建sda3全部容量-------------------------
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (41943040-209715199, default 41943040):
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-209715199, default 209715199):
Using default value 209715199
Partition 3 of type Linux and of size 80 GiB is set
-----验证分区-------------------------
Command (m for help): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000c35ff
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
-----看看后面Id System需要修改-------------------------
/dev/sda3 41943040 209715199 83886080 83 Linux
-----修改Id-------------------------
Command (m for help): t
Partition number (1-3, default 3):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000c35ff
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
/dev/sda3 41943040 209715199 83886080 8e Linux LVM
-----保存!!!!!-------------------------
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
-----同步磁盘状态-------------------------
[root@Nexus3 ~]# partprobe
创建物理卷
- pvcreate <物理分区>
-----查询当前PV-------------------------
[root@Nexus3 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <19.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4863
Free PE 0
Allocated PE 4863
PV UUID 2MrxDf-dTQK-I7iK-5VUs-bcrv-Af2t-fVaAiL
-----创建新的PV-------------------------
[root@Nexus3 ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
[root@Nexus3 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <19.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4863
Free PE 0
Allocated PE 4863
PV UUID 2MrxDf-dTQK-I7iK-5VUs-bcrv-Af2t-fVaAiL
-----这个是我们创建的-------------------------
"/dev/sda3" is a new physical volume of "80.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 80.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID kfO9Yc-ToQb-2vnf-8muc-MNsZ-oxJV-vi1vVe
扩展卷组
- vgextend <卷组VG Name> <物理卷PV Name>
-----查看当前VG-------------------------
[root@Nexus3 ~]# vgdisplay
--- Volume group ---
-----VG Name需要用到-------------------------
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
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 Wx79ds-a3LO-VhXo-HJdk-fr0X-C9UX-KOqfSK
-----扩展卷组-------------------------
[root@Nexus3 ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
逻辑卷扩展
- lvextend -l +100%free </dev/mapper/centos-root> #前面df -hT看到的信息
-----查看逻辑卷-------------------------
[root@Nexus3 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID bgsynr-YUZE-LX2j-NIgG-sqqU-wVxb-GIZDg7
LV Write Access read/write
LV Creation host, time localhost, 2019-11-22 14:16:37 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
-----我们需要扩展该卷-------------------------
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID lkRm4c-8g6X-ZWm2-Y86h-aKXs-i2lN-ZKdGaD
LV Write Access read/write
LV Creation host, time localhost, 2019-11-22 14:16:37 +0800
LV Status available
# open 1
LV Size <17.00 GiB
Current LE 4351
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
-----扩充-------------------------
[root@Nexus3 ~]# lvextend -l +100%free /dev/mapper/centos-root
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to 96.99 GiB (24830 extents).
Logical volume centos/root successfully resized.
动态格式化扩容磁盘
[root@Nexus3 ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 4455424 to 25425920
验证
[root@Nexus3 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 8.9M 3.9G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
-----100G-------------------------
/dev/mapper/centos-root xfs 97G 1.2G 96G 2% /
/dev/sda1 xfs 1014M 136M 879M 14% /boot
tmpfs tmpfs 799M 0 799M 0% /run/user/0
END
[Linux]LVM扩展卷的更多相关文章
- Linux LVM学习总结——扩展卷组VG
Linux服务器由于应用变更或需求的缘故,有可能出现分区空间不足的情况,此时往往需要进行扩容(要增加分区的空间),而采用LVM的好处就是可以在不需停机的情况下可以方便地调整各个分区大小.如下所示,分区 ...
- Linux LVM简明教程
逻辑卷管理LVM是一个多才多艺的硬盘系统工具.无论在Linux或者其他类似的系统,都是非常的好用.传统分区使用固定大小分区,重新调整大小十分麻烦.但是,LVM可以创建和管理“逻辑”卷,而不是直接使用物 ...
- linux lvm管理基础教程
linux lvm管理基础教程 本人是在redhat7.x系统上亲测lvm管理功能,至于文中所受的CentOS 6 没有亲自试过. 本文来自:https://geekpeek.net/lvm-phys ...
- Linux lvm在线扩容
1.查看磁盘空间 [root@bgd-mysql3 ~]# fdisk -l Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sector ...
- Linux LVM硬盘管理之二:创建逻辑卷步骤
创建逻辑卷(LV)的顺序:Linux分区---物理卷(PV)---卷组(VG)---逻辑卷(LV)---挂载到文件系统 删除逻辑卷(LV)的顺序:卸载文件系统----逻辑卷(LV)---卷组(VG)- ...
- linux lvm管理扩展 RAID磁盘阵列管理
LVM逻辑卷将多个物理分区/磁盘从逻辑上组合成一个更大的整体,从其中划分出不同的逻辑分区,逻辑分区的大小可以根据需要扩大,缩减!!!!/boot用来存放引导文件,不要基于LVM创建 PV(物理卷)物理 ...
- Linux LVM在线扩容
环境: 虚拟化环境,SUSE Linux Enterprise Server 11sp3,直接把虚拟磁盘从100G改成150G. 现有的LVM是100G,/home 的LV需要再加50G. 步骤: f ...
- Linux LVM 逻辑卷管理
使用Linux好久了,一定会意识到一个问题,某个分区容量不够用了,想要扩容怎么办?这里就涉及到LVM逻辑卷的管理了,可以动态调整Linux分区容量. LVM 概述 全称Logical Volume M ...
- Linux LVM学习总结——创建卷组VG
在Linux平台如何创建一个卷组(VG)呢?下面简单介绍一下卷组(VG)的创建步骤.本文实验平台为Red Hat Enterprise Linux Server release 6.6 (Santia ...
随机推荐
- FWT 入门
#include <bits/stdc++.h> using namespace std; #define ll long long const ll maxn = 3e5+5; cons ...
- python爬虫——selenium+firefox使用代理
本文中的知识点: python selenium库安装 firefox geckodriver的下载与安装 selenium+firefox使用代理 进阶学习 搭建开发环境: selenium库 fi ...
- 如何优雅的用策略模式,取代臃肿的 if-else 嵌套,看这篇就够了
经常听同事抱怨,订单来源又加了一种,代码又要加一层if-else判断,光判断订单来源的if-else就好几百行代码,代码我都不想看了,相信很多同行都有过这样的感受! Java的二十几种设计模式背的滚瓜 ...
- [洛谷 P5053] [COCI2017-2018#7] Clickbait
Description 下图是一个由容器和管道组成的排水系统.对于这个系统,\(Slavko\) 想知道如果一直向容器1灌水,那么所有容器从空到充满水的顺序. 系统共有 \(K\) 个容器标号为1到 ...
- C++ lambda 分析
lambda 表达式分析 构造闭包:能够捕获作用域中变量的匿名函数的对象,Lambda 表达式是纯右值表达式,其类型是独有的无名非联合非聚合类类型,被称为闭包类型(closure type),所以在声 ...
- 使用C++进行声明式编程
声明式编程(英语:Declarative programming)是一种编程范型,与命令式编程相对立.它描述目目标性质,让计算机明白目标,而非流程.声明式编程不用告诉电脑问题领域,从而 ...
- 平滑重启更新(GR机制)
平滑重启更新(GR机制) 什么是平滑启动机制 是一种在协议重启时保证转发业务不中断的机制. 什么时候用到平滑重启 平滑重启一般应用于业务更新或者版本发布过程中,能够避免因为代码发布重启服务导致的暂时性 ...
- Spring注解开发系列Ⅲ --- 生命周期
Bean的生命周期 Spring Bean 的生命周期在整个 Spring 中占有很重要的位置,掌握这些可以加深对 Spring 的理解. 首先看下生命周期图: 再谈生命周期之前有一点需要先明确: S ...
- Java:多线程概述与创建方式
目录 Java:多线程概述与创建方式 进程和线程 并发与并行 多线程的优势 线程的创建和启动 继承Thread类 start()和run() 实现Runnable接口 实现Callable接口 创建方 ...
- 六、Django学习之基于下划线的跨表查询
六.Django学习之基于下划线的跨表查询 一对一 正向查询的例子为 已知用户名,查询用户的电话号码.反向查询例子反之. 正向查询 其中下划线前的表示表名,无下划线的表示的是Author表 resul ...