引用自:

 https://blog.csdn.net/u012439646/article/details/73380197 
 xfs_growfs /dev/centos/root 
一、首先安装系统时系统分区选择lvm卷组分区,详见本人博客链接https://www.cnblogs.com/Presley-lpc/p/9242871.html
  1、查看盘结构 lsblk
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 : 4K disk
sda : 20G disk
├─sda1 : 2M part
├─sda2 : 2M part
├─sda3 : 1G part /boot
├─sda4 : 1K part
└─sda5 : 19G part
├─centos-root : 5G lvm /
├─centos-swap : 1G lvm [SWAP]
├─centos-swap00 : 1G lvm [SWAP]
├─centos-home : 2G lvm /home
├─centos-var : 1G lvm /var
└─centos-application : 9G lvm /application
sdb : 20G disk
sr0 : 1024M rom

  2、查看卷组名称及卷组使用情况  vgdisplay

  3、查看当前逻辑卷的空间状态 lvdisplay

[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/home
LV Name home
VG Name centos
LV UUID vJAKGc-Nd7w-IbPZ-FSI5-CTSS-XoXt-WcFu2z
LV Write Access read/write
LV Creation host, time localhost, -- :: +
LV Status available
# open
LV Size 2.00 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID Sgyddc-qr0l-Xry3-xR5f-rYUe-lNkq-3Ia928
LV Write Access read/write
LV Creation host, time localhost, -- :: +
LV Status available
# open
LV Size 1.00 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/centos/var
LV Name var
VG Name centos
LV UUID A0RDo9-Xuz1-7ElO-mwWQ-IHkS-fwDt-YPP1t2
LV Write Access read/write
LV Creation host, time localhost, -- :: +
LV Status available
# open
LV Size 1.00 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/centos/swap00
LV Name swap00
VG Name centos
LV UUID 9HyfSy-etlb-74M9-NKiz-AtaC-YPij-i9Tb78
LV Write Access read/write
LV Creation host, time localhost, -- :: +
LV Status available
# open
LV Size 1.00 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID fez5HR-4F4j-PRBy-cdfE-syBU-4NIU-DHnNIK
LV Write Access read/write
LV Creation host, time localhost, -- :: +
LV Status available
# open
LV Size 5.00 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/centos/application
LV Name application
VG Name centos
LV UUID UT39NC-88Ru-hcX2-iceA-P84w-yHac-xKf3o0
LV Write Access read/write
LV Creation host, time localhost, -- :: +
LV Status available
# open
LV Size 8.99 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device :

二、扩容

  1、在一中我们通过lvdisplay可以看到最后这个卷组 /dev/centos/application 的大小为8.99G,现在要动态扩容到28.99G。

    a、首先添加一块硬盘,然后查看 fdisk -l,可以看到/dev/sdb即为所添加的硬盘.

[root@localhost application]# fdisk -l

Disk /dev/sdb: 21.5 GB,  bytes,  sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/sda: 21.5 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0x0003a9f3 Device Boot Start End Blocks Id System
/dev/sda1 Linux
/dev/sda2 Linux
/dev/sda3 * Linux
/dev/sda4 Extended
/dev/sda5 8e Linux LVM Disk /dev/mapper/centos-root: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/mapper/centos-swap: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/mapper/centos-swap00: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/mapper/centos-home: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/mapper/centos-var: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/mapper/centos-application: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes

    b、给磁盘分区,此处全部都分出来

[root@localhost application]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.). 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 0x6f1c09c9. Command (m for help): n
Partition type:
p primary ( primary, extended, free)
e extended
Select (default p): p
Partition number (-, default ):
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ):
Using default value
Partition of type Linux and of size GiB is set Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.

    c、将分区类型改为lvm

[root@localhost application]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.). Changes will remain in memory only, until you decide to write them.
Be careful before using the write command. Command (m for help): t
Selected partition
Hex code (type L to list all codes): L Empty NEC DOS Minix / old Lin bf Solaris
FAT12 Hidden NTFS Win Linux swap / So c1 DRDOS/sec (FAT-
XENIX root Plan Linux c4 DRDOS/sec (FAT-
XENIX usr 3c PartitionMagic OS/ hidden C: c6 DRDOS/sec (FAT-
FAT16 <32M Venix Linux extended c7 Syrinx
Extended PPC PReP Boot NTFS volume set da Non-FS data
FAT16 SFS NTFS volume set db CP/M / CTOS / .
HPFS/NTFS/exFAT 4d QNX4.x Linux plaintext de Dell Utility
AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
AIX bootable 4f QNX4.x 3rd part Amoeba e1 DOS access
a OS/ Boot Manag OnTrack DM Amoeba BBT e3 DOS R/O
b W95 FAT32 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
OPUS EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
Hidden FAT12 Golden Bow a8 Darwin UFS f1 SpeedStor
Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
Hidden FAT16 < SpeedStor ab Darwin boot f2 DOS secondary
Hidden FAT16 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
Hidden HPFS/NTF Novell Netware b7 BSDI fs fc VMware VMKCORE
AST SmartSleep Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 Old Minix
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): p Disk /dev/sdb: 21.5 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0x6f1c09c9 Device Boot Start End Blocks Id System
/dev/sdb1 8e Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

  2、开始扩容

    a、将新加的分区 /dev/sdb1 创建为物理卷

[root@localhost application]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created

    b、给卷组‘centos’扩容(此处的centos即为一中vgdisplay 中的centos),将物理卷 /dev/sdb1 扩展至‘centos’卷组

[root@localhost application]# vgextend centos /dev/sdb1
Volume group "centos" successfully extended

    c、此时卷组‘centos’有20G空余空间,将其全部扩展至 /application

[root@localhost application]# lvextend -l +%FREE /dev/mapper/centos-application
Size of logical volume centos/application changed from 8.99 GiB ( extents) to 28.99 GiB ( extents).
Logical volume application successfully resized.

    d、虽然此时磁盘已经扩展至/application,但是还没有写入文件系统,我们先通过df -hT 查看/application文件格式为xfs,因此,使用xfs_growfs /dev/mapper/centos-application 命令写入。若文件格式为ext4则使用命令resize2fs /dev/mapper/centos-application写入

[root@localhost application]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs .0G 1020M .0G % /
devtmpfs devtmpfs 483M 483M % /dev
tmpfs tmpfs 493M 493M % /dev/shm
tmpfs tmpfs 493M 6.8M 487M % /run
tmpfs tmpfs 493M 493M % /sys/fs/cgroup
/dev/mapper/centos-home xfs .0G 33M .0G % /home
/dev/mapper/centos-application xfs .0G 33M .0G % /application
/dev/mapper/centos-var xfs 1014M 79M 936M % /var
/dev/sda3 xfs 1014M 133M 881M % /boot
tmpfs tmpfs 99M 99M % /run/user/
[root@localhost application]# xfs_growfs /dev/mapper/centos-application
meta-data=/dev/mapper/centos-application isize= agcount=, agsize= blks
= sectsz= attr=, projid32bit=
= crc= finobt=
data = bsize= blocks=, imaxpct=
= sunit= swidth= blks
naming =version bsize= ascii-ci= ftype=
log =internal bsize= blocks=, version=
= sectsz= sunit= blks, lazy-count=
realtime =none extsz= blocks=, rtextents=
data blocks changed from to
[root@localhost application]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs .0G 1020M .0G % /
devtmpfs devtmpfs 483M 483M % /dev
tmpfs tmpfs 493M 493M % /dev/shm
tmpfs tmpfs 493M 6.8M 487M % /run
tmpfs tmpfs 493M 493M % /sys/fs/cgroup
/dev/mapper/centos-home xfs .0G 33M .0G % /home
/dev/mapper/centos-application xfs 29G 33M 29G % /application
/dev/mapper/centos-var xfs 1014M 79M 936M % /var
/dev/sda3 xfs 1014M 133M 881M % /boot
tmpfs tmpfs 99M 99M % /run/user/

    e、可以看到/application大小已经从9G动态扩容到了29G。

三、lvm创建和使用

  1、创建和使用流程
    建立分区-PV--VG--LV--格式化--挂载

  2、fdisk建立分区

    #fdisk /dev/sdb //同样分区sdc

    n 1 回车 回车

    t 8e 回车

    p 查看 w退出

    # fdisk -l /dev/sdb /dev/sdc | grep "LVM"

  3、 转换为物理卷PV

    # pvcreate /dev/sdb1 /dev/sdc1

  4、创建卷组VG

    # vgcreate juanzu /dev/sdb1 /dev/sdc1

  5、在卷组中 创建逻辑卷LV

    # lvcreate -L 120G -n luoji juanzu
  6、mkfs 格式化

    #mkfs -t ext4 /dev/juanzu/luoji

  7、mount 挂载

    #mount /dev/juanzu/luoji /yinpan

    df -hT 查看

    #df -hT

  8、注意:设置文件系统自动挂载

    #vi /etc/fstab

    设备名称 挂载点目录 文件类型 defaults默认参数(读写) 0(dump备份) 0(启动检查)
    /dev/juanzu/luoji /yinpan ext4 defaults 0 0

四、lvm动态扩容总结

  1、创建分区

#fdisk /dev/sdb

  2、创建物理卷

#pvcreat /dev/sdb1

  3、查看卷组名称及使用情况

#vgdisplay

  4、将物理卷扩展到卷组

 #vgextend centos /dev/sdb1   (此处‘centos’是卷组名称)

  5、将卷组中空闲空间扩展到 /home

#lvextend -l +%FREE /dev/mapper/centos-application

  6、刷新文件系统使扩容生效

#resize2fs /dev/mapper/centos-application

  7、使用reiserfs 文件系统代替ext2/ext3 ,若为xfs则用xfs_growfs

#resize_reiserfs /dev/mapper/cl-home
#xfs_growfs /dev/mapper/cl-home

Linux LVM动态扩容的更多相关文章

  1. Linux LVM在线扩容

    环境: 虚拟化环境,SUSE Linux Enterprise Server 11sp3,直接把虚拟磁盘从100G改成150G. 现有的LVM是100G,/home 的LV需要再加50G. 步骤: f ...

  2. Linux lvm在线扩容

    1.查看磁盘空间 [root@bgd-mysql3 ~]# fdisk -l Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sector ...

  3. 微服务架构 ------ 插曲 linux LVM磁盘扩容

    1.LVM的基本概念 物理卷(PV):可以在上面建立卷组的媒介,可以是硬盘分区,也可以是硬盘本身或者回环文件,物理卷包括一个特殊的header,其余部分被切割成一块块物理区域. 卷组(VG):将一组物 ...

  4. linux LVM 系统盘扩容

    1.fdisk /dev/sda2.输入n,开始创建新分区3.输入p4.输入w5.mkfs.ext4 /dev/sda36.pvcreate /dev/sda37.vgdisplay 查看VG nam ...

  5. Linux lvm 分区知识笔记

    盘面上可以细分出扇区(Sector)与柱面(Cylinder)两种单位,其中扇区每个为512bytes那么大. 通常所说的"硬盘分区"就是指修改磁盘分区表,它定义了"第n ...

  6. <实训|第十二天>用LVM对linux分区进行动态扩容

    [root@localhost~]#序言在linux中,我们安装软件的途径一般有那些,你们知道吗?在linux中,如果你的磁盘空间不够用了,你知道如何来扩展磁盘吗?动态扩容不仅在工作中还是在其他方面都 ...

  7. Linux - 通过LVM对磁盘进行动态扩容

    目录 1 LVM是什么 1.1 概念解释 1.2 为什么用LVM 1.2.1 不使用LVM时的扩容思路 1.2.2 使用LVM时的扩容思路 1.3 名词解释 2 普通的挂载磁盘方法 2.1 创建分区的 ...

  8. Linux:lvm磁盘分区,动态扩容

    一.lvm磁盘分区: 1,查看新增的磁盘,需要使用root权限 fdisk -l 看到有一个新增的100G磁盘 2,对磁盘进行分区 fdisk /dev/xvdb 1,输入:n 表示创建一个新的分区( ...

  9. [转载]Linux LVM硬盘管理及LVM扩容

    最近项目中一直在用Linux,其中涉及到了Linux的LVM,本来想自己写一篇关于LVM的文章,搜了一下,发现了一篇更好的,转载过来,也感谢作者gaojun 原文Linux LVM硬盘管理及LVM扩容 ...

随机推荐

  1. 配置国内 Docker Registry Mirror

    由于国内特殊的网络环境,往往我们从Docker Hub中拉取镜像并不能成功,而且速度特别慢. 那么我们可以给Docker配置一个国内的registry mirror,当我们需要的镜像在mirror中则 ...

  2. pyhon 前面补充和set

    一, 主要内容. 补充一个字符串的基本操作 li = ["李嘉诚", "麻花藤", "黄海峰", "刘嘉玲"] s = ...

  3. 连接mysql(建表和删表)

    from sqlalchemy.ext.declarative import declarative_base##拿到父类from sqlalchemy import Column##拿到字段from ...

  4. 安装python的pip模块

    安装python的pip模块 网址https://pypi.python.org/pypi/pip 选择,点击下载 将文件解压到C:\Users\Administrator\AppData\Local ...

  5. oracle数据库内存调整之增加内存

    注:本文来源:小颜Kevin   <oracle数据库内存调整之增加内存> 模拟操作系统内存从2G增加为8G后,调整数据库内存参数,示例中参数不作为实际生产环境参考,因为因需所取,调整参数 ...

  6. Confluence 6 任务的类型

    下面是有关你可以调整的计划任务列表. Confluence 备份(Back Up Confluence) 对 Confluence 站点执行备份操作. 每集群(Per cluster) At 2am ...

  7. Confluence 6 你模板中可用的对象

    包含宏正文和参数,下面的 Confluence 对象在宏中可用: $body 宏的正文(如果宏有正文的话) String $paramfoo, $parambar, ...$param<name ...

  8. iOS ibeacon 使用详解

    前段时间写项目,设计到了通过蓝牙ibeacon 的方式接收数据,最开始自己都之前都没听过什么叫ibeacon,然后就开始查资料,慢慢的也了解并知道了ibeacon怎么使用了.先大概解释下ibeacon ...

  9. Linux 编程笔记(四)

    一.用户和用户组管理 添加新的用户账户使用useradd 格式useradd   选项  用户名 1.创建一个用户tian 其中 -d -m参数用来为登陆,登录名产生一个主目录 /usr/tian(其 ...

  10. cf1140E 回文串+染色方案dp

    有点硬核的dp..要用到一个结论.. /* 把原串拆成奇偶串,再拆成极大连续的-1串:该串两端都是非-1数,中间都是-1,并且下标要么都是偶数,要么都是技术 然后对所有这些串进行dp,dp[i][0] ...