引用自:

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                      2:0    1    4K  0 disk
sda                      8:0    0   20G  0 disk
├─sda1                   8:1    0    2M  0 part
├─sda2                   8:2    0    2M  0 part
├─sda3                   8:3    0    1G  0 part /boot
├─sda4                   8:4    0    1K  0 part
└─sda5                   8:5    0   19G  0 part ├─centos-root        253:0    0    5G  0 lvm  /├─centos-swap        253:1    0    1G  0 lvm  [SWAP]├─centos-swap00      253:2    0    1G  0 lvm  [SWAP]├─centos-home        253:3    0    2G  0 lvm  /home├─centos-var         253:4    0    1G  0 lvm  /var└─centos-application 253:5    0    9G  0 lvm  /application
sdb                      8:16   0   20G  0 disk
sr0                     11:0    1 1024M  0 rom  

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

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

[root@localhost ~]# lvdisplay --- Logical volume ---LV Path                /dev/centos/homeLV Name                homeVG Name                centosLV UUID                vJAKGc-Nd7w-IbPZ-FSI5-CTSS-XoXt-WcFu2zLV Write Access        read/writeLV Creation host, time localhost, 2019-01-17 19:41:24 +0800LV Status              available# open                 1LV Size                2.00 GiBCurrent LE             512Segments               1Allocation             inheritRead ahead sectors     auto- currently set to     8192Block device           253:3--- Logical volume ---LV Path                /dev/centos/swapLV Name                swapVG Name                centosLV UUID                Sgyddc-qr0l-Xry3-xR5f-rYUe-lNkq-3Ia928LV Write Access        read/writeLV Creation host, time localhost, 2019-01-17 19:41:25 +0800LV Status              available# open                 2LV Size                1.00 GiBCurrent LE             256Segments               1Allocation             inheritRead ahead sectors     auto- currently set to     8192Block device           253:1--- Logical volume ---LV Path                /dev/centos/varLV Name                varVG Name                centosLV UUID                A0RDo9-Xuz1-7ElO-mwWQ-IHkS-fwDt-YPP1t2LV Write Access        read/writeLV Creation host, time localhost, 2019-01-17 19:41:25 +0800LV Status              available# open                 1LV Size                1.00 GiBCurrent LE             256Segments               1Allocation             inheritRead ahead sectors     auto- currently set to     8192Block device           253:4--- Logical volume ---LV Path                /dev/centos/swap00LV Name                swap00VG Name                centosLV UUID                9HyfSy-etlb-74M9-NKiz-AtaC-YPij-i9Tb78LV Write Access        read/writeLV Creation host, time localhost, 2019-01-17 19:41:26 +0800LV Status              available# open                 2LV Size                1.00 GiBCurrent LE             256Segments               1Allocation             inheritRead ahead sectors     auto- currently set to     8192Block device           253:2--- Logical volume ---LV Path                /dev/centos/rootLV Name                rootVG Name                centosLV UUID                fez5HR-4F4j-PRBy-cdfE-syBU-4NIU-DHnNIKLV Write Access        read/writeLV Creation host, time localhost, 2019-01-17 19:41:26 +0800LV Status              available# open                 1LV Size                5.00 GiBCurrent LE             1280Segments               1Allocation             inheritRead ahead sectors     auto- currently set to     8192Block device           253:0--- Logical volume ---LV Path                /dev/centos/applicationLV Name                applicationVG Name                centosLV UUID                UT39NC-88Ru-hcX2-iceA-P84w-yHac-xKf3o0LV Write Access        read/writeLV Creation host, time localhost, 2019-01-17 19:41:27 +0800LV Status              available# open                 1LV Size                8.99 GiBCurrent LE             2301Segments               1Allocation             inheritRead ahead sectors     auto- currently set to     8192Block device           253:5

二、扩容

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

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

[root@localhost application]# fdisk -lDisk /dev/sdb: 21.5 GB, 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 bytesDisk /dev/sda: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0x0003a9f3Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048        6143        2048   83  Linux
/dev/sda2            6144       10239        2048   83  Linux
/dev/sda3   *       10240     2107391     1048576   83  Linux
/dev/sda4         2107392    41943039    19917824    5  Extended
/dev/sda5         2109440    41943039    19916800   8e  Linux LVMDisk /dev/mapper/centos-root: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap00: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-home: 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 bytesDisk /dev/mapper/centos-var: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-application: 9651 MB, 9651093504 bytes, 18849792 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

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

[root@localhost application]# 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 0x6f1c09c9.Command (m for help): n
Partition type:p   primary (0 primary, 0 extended, 4 free)e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is setCommand (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.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
Selected partition 1
Hex code (type L to list all codes): L  0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT
1e  Hidden W95 FAT1 80  Old Minix
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'Command (m for help): pDisk /dev/sdb: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0x6f1c09c9Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   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/sdb1Physical volume "/dev/sdb1" successfully created

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

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

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

[root@localhost application]# lvextend -l +100%FREE /dev/mapper/centos-applicationSize of logical volume centos/application changed from 8.99 GiB (2301 extents) to 28.99 GiB (7421 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       5.0G 1020M  4.0G  20% /
devtmpfs                       devtmpfs  483M     0  483M   0% /dev
tmpfs                          tmpfs     493M     0  493M   0% /dev/shm
tmpfs                          tmpfs     493M  6.8M  487M   2% /run
tmpfs                          tmpfs     493M     0  493M   0% /sys/fs/cgroup
/dev/mapper/centos-home        xfs       2.0G   33M  2.0G   2% /home
/dev/mapper/centos-application xfs       9.0G   33M  9.0G   1% /application
/dev/mapper/centos-var         xfs      1014M   79M  936M   8% /var
/dev/sda3                      xfs      1014M  133M  881M  14% /boot
tmpfs                          tmpfs      99M     0   99M   0% /run/user/0
[root@localhost application]# xfs_growfs /dev/mapper/centos-application
meta-data=/dev/mapper/centos-application isize=256    agcount=4, agsize=589056 blks=                       sectsz=512   attr=2, projid32bit=1=                       crc=0        finobt=0
data     =                       bsize=4096   blocks=2356224, imaxpct=25=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
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 2356224 to 7599104
[root@localhost application]# df -hT
Filesystem                     Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root        xfs       5.0G 1020M  4.0G  20% /
devtmpfs                       devtmpfs  483M     0  483M   0% /dev
tmpfs                          tmpfs     493M     0  493M   0% /dev/shm
tmpfs                          tmpfs     493M  6.8M  487M   2% /run
tmpfs                          tmpfs     493M     0  493M   0% /sys/fs/cgroup
/dev/mapper/centos-home        xfs       2.0G   33M  2.0G   2% /home
/dev/mapper/centos-application xfs        29G   33M   29G   1% /application
/dev/mapper/centos-var         xfs      1014M   79M  936M   8% /var
/dev/sda3                      xfs      1014M  133M  881M  14% /boot
tmpfs                          tmpfs      99M     0   99M   0% /run/user/0

    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 +100%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

转载于:https://www.cnblogs.com/Presley-lpc/p/9668083.html

Linux LVM动态扩容相关推荐

  1. Linux 磁盘动态扩容 PVM(转载)

    CentOS7.x系统根目录分区扩容 说明:系统版本为 Linux version 3.10.0-327.el7.x86_64 step1. 查看现有磁盘信息,可以看出根分区有45G [ 复制代码 ] ...

  2. Linux LVM在线扩容xfs文件系统(创建大于2T的磁盘分区)

    1. 使用parted方式格式化磁盘 1.1 查看磁盘情况 [root@superman ~]# fdisk -lDisk /dev/sdd: 2199.0 GB, 2199023255552 byt ...

  3. CentOS7的LVM动态扩容

    问题 CentOS7上面的磁盘空间有点紧张,需要扩容. 解决 查询当前磁盘状态 [root@xxx ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT ...

  4. linux中LVM动态扩容和管理

    相关概念 pv:物理卷 pe:物理拓展卷     lvm的最小存储单元 vg :卷组 lvm :最终使用的可伸缩设备 2.  lvm 建立 1).划分物理分区,修改其标签为lvm 通过L 查出8e编号 ...

  5. Linux中的lvm动态扩容管理

    1.相关概念 pv:物理卷                                                                                ---一杯桔子 ...

  6. Linux lvm分区扩容、给sda2扩容

    初始创建服务器未将所有磁盘空间进行分配,数据目录.swap需要扩容 [root@yhcs /]# lsblk NAME            MAJ:MIN RM  SIZE RO TYPE MOUN ...

  7. lvm android分区合并,Linux LVM 分区扩容与多磁盘分区合并处理

    1.概念描述 LVM主要在磁盘与文件系统之间创建一个层,主要用来管理多磁盘多分区进行与多文件系统的映射. 就是说N块硬盘分区后,能够把不一样硬盘之间的分区进行组卷,有了这个组卷后再从组卷的基础上分配逻 ...

  8. Linux lvm分区扩容/ gparted 扩容

    环境说明 已知 pv 空间剩余大小 13.27t没有分配,把剩余空间分配到根目录的lv分区上 查看分区 df -lh 文件系统 容量 已用 可用 已用% 挂载点 devtmpfs 16G 0 16G ...

  9. Linux LVM在线扩容ext3文件系统

    1. 扩容前信息查看 1.2 查看文件系统情况 [root@superman ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/VG00-lv_root30G 2 ...

  10. linux LVM 系统盘扩容

    1.fdisk /dev/sda 2.输入n,开始创建新分区 3.输入p 4.输入w 5.mkfs.ext4 /dev/sda3 6.pvcreate /dev/sda3 7.vgdisplay 查看 ...

最新文章

  1. 浅谈python+requests实现接口自动化
  2. 如何用JavaScript判断dom是否有存在某class的值?
  3. 前端学习(3154):react-hello-react之脚手架文件介绍
  4. 在家办公上课成强需求 钉钉峰值流量暴增百倍
  5. win10 html css,Win10创造者更新:Edge支持CSS自定义属性
  6. leetcode刷题:搜索旋转排序数组
  7. 了解架构设计远远不够!一文拆解 Tomcat 高并发原理与性能调优
  8. 蓝桥杯2015年第六届C/C++B组省赛第八题-移动距离
  9. 47 Python - 装饰器 回忆函数基础
  10. linux下删除编译安装的软件,Linux 中卸载编译安装的软件
  11. 互联网营销师淘宝主播
  12. 手机CPU性能天梯图及品牌
  13. 台州银行笔试考什么_历年台州银行笔试和面试经验分享
  14. 使用metalink批量下载sentinel数据
  15. 计算机毕业设计论文不会做怎么办?这里送教程送代码送开题送答辩
  16. 黑马程序员学习笔记-------c++提高编程
  17. 悲观锁、乐观锁、间隙锁、死锁、自旋锁等
  18. 开题报告的国内外研究现状怎么写呢?
  19. Storyboard References
  20. UGUI图集的理解与使用

热门文章

  1. strace的简单用法
  2. 通过 Hibernate 调用存储过程
  3. mysql建表时创建索引语句_创建表的时候创建索引
  4. 单片机,嵌入式,PLC三者之间有什么区别,学习方向如何选择
  5. Docker一站式配置Nginx【图文教程】
  6. 外层div自动撑大为什么没有最大_在工业自动化行业,为什么电阻触摸屏更受欢迎...
  7. Spring源码之ApplicationContext(四)功能补充
  8. Struts2标签库(三)之表单标签
  9. Baxter实战 (四)ubuntu14.04安装kinect V2
  10. 一个简单的倒计时js插件