在Linux学习过程中,可能会遇到根目录存储空间不足的问题,这时候如果只是新增一块硬盘并挂载到某个目录上,还需要将数据转移至新的硬盘中才能缓解存储压力。这种操作未免有些繁琐,那可不可以直接对跟目录进行扩容呢?当然是可以的,接下来就给大家介绍操作步骤:

  实验环境:RHEL7系统(默认已部署LVM)、VMware Workstation 12虚拟软件

  第1步:给虚拟机新增一块20GB的硬盘

  第2步:查看系统盘的分区类型,最后记得输入q不保存退出

  1. [root@linuxprobe ~]# fdisk /dev/sda
  2. Welcome to fdisk (util-linux 2.23.).
  3.  
  4. Changes will remain in memory only, until you decide to write them.
  5. Be careful before using the write command.
  6.  
  7. Command (m for help): p //输入p查看分区信息
  8.  
  9. Disk /dev/sda: 21.5 GB, bytes, sectors
  10. Units = sectors of * = bytes
  11. Sector size (logical/physical): bytes / bytes
  12. I/O size (minimum/optimal): bytes / bytes
  13. Disk label type: dos
  14. Disk identifier: 0x00091636
  15.  
  16. Device Boot Start End Blocks Id System
  17. /dev/sda1 * Linux
  18. /dev/sda2 8e Linux LVM //分区类型为Linux LVM

 Command (m for help): q     //输入q不保存退出

  第3步:对新硬盘进行分区,并设置分区类型

  1. [root@linuxprobe ~]# fdisk /dev/sdb
  2. Welcome to fdisk (util-linux 2.23.).
  3.  
  4. Changes will remain in memory only, until you decide to write them.
  5. Be careful before using the write command.
  6.  
  7. Command (m for help): n //添加一个新分区
  8. Partition type:
  9. p primary ( primary, extended, free)
  10. e extended
  11. Select (default p): p //主分区
  12. Partition number (-, default ): 1 //分区编号为1
  13. First sector (-, default ): <此处按下回车键>
  14. Using default value
  15. Last sector, +sectors or +size{K,M,G} (-, default ): +10G //分区大小为10GB
  16. Partition of type Linux and of size GiB is set
  17.  
  18. Command (m for help): p //再次查看分区信息
  19.  
  20. Disk /dev/sdb: 21.5 GB, bytes, sectors
  21. Units = sectors of * = bytes
  22. Sector size (logical/physical): bytes / bytes
  23. I/O size (minimum/optimal): bytes / bytes
  24. Disk label type: dos
  25. Disk identifier: 0x1894a517
  26.  
  27. Device Boot Start End Blocks Id System
  28. /dev/sdb1 Linux //新的分区添加成功,不过分区类型不对
  29.  
  30. Command (m for help): t //变更分区的类型
  31. Selected partition
  32. Hex code (type L to list all codes): 8e //输入8e即"Linux LVM"
  33. Changed type of partition 'Linux' to 'Linux LVM'
  34.  
  35. Command (m for help): p //再次查看分区信息
  36.  
  37. Disk /dev/sdb: 21.5 GB, bytes, sectors
  38. Units = sectors of * = bytes
  39. Sector size (logical/physical): bytes / bytes
  40. I/O size (minimum/optimal): bytes / bytes
  41. Disk label type: dos
  42. Disk identifier: 0x1894a517
  43.  
  44. Device Boot Start End Blocks Id System
  45. /dev/sdb1 8e Linux LVM //分区类型变更成功,与系统分区一致
  46.  
  47. Command (m for help): w //最后记得要保存退出
  48. The partition table has been altered!
  49.  
  50. Calling ioctl() to re-read partition table.
  51. Syncing disks.

  第4步:让新添加的硬盘分区支持LVM技术

  1. [root@linuxprobe ~]# pvcreate /dev/sdb1
  2. Physical volume "/dev/sdb1" successfully created

  第5步:查看当前系统的卷组,并将/dev/sdb1硬盘分区加入到卷组中

  1. [root@linuxprobe ~]# vgdisplay
  2. --- Volume group ---
  3. VG Name rhel //卷组名为"rhel"
  4. System ID
  5. Format lvm2
  6. Metadata Areas
  7. Metadata Sequence No
  8. VG Access read/write
  9. VG Status resizable
  10. MAX LV
  11. Cur LV
  12. Open LV
  13. Max PV
  14. Cur PV
  15. Act PV
  16. VG Size 19.51 GiB //卷组的总容量大小
  17. PE Size 4.00 MiB
  18. Total PE
  19. Alloc PE / Size / 19.51 GiB
  20. Free PE / Size /
  21. VG UUID mGomiV-U0sF-wKii-YxOh-V7Gw-VEQ4-yIkcRD
  22. [root@linuxprobe ~]# vgextend rhel /dev/sdb1 //把/dev/sdb1硬盘分区加入到rhel卷组中
  23. Volume group "rhel" successfully extended
  24. [root@linuxprobe ~]# vgdisplay
  25. --- Volume group ---
  26. VG Name rhel
  27. System ID
  28. Format lvm2
  29. Metadata Areas
  30. Metadata Sequence No
  31. VG Access read/write
  32. VG Status resizable
  33. MAX LV
  34. Cur LV
  35. Open LV
  36. Max PV
  37. Cur PV
  38. Act PV
  39. VG Size 29.50 GiB //卷组的容量增大了10GB
  40. PE Size 4.00 MiB
  41. Total PE
  42. Alloc PE / Size / 19.51 GiB
  43. Free PE / Size / 10.00 GiB
  44. VG UUID mGomiV-U0sF-wKii-YxOh-V7Gw-VEQ4-yIkcRD

  第6步:查看当前逻辑卷信息

  1. [root@linuxprobe ~]# lvdisplay
  2. --- Logical volume ---
  3. LV Path /dev/rhel/swap //用来充当SWAP分区,我们这里不管它
  4. LV Name swap
  5. VG Name rhel
  6. LV UUID d2gNWI-6Oin-9Q3r-OGLp-0nf5-0Dun-Z8EvgS
  7. LV Write Access read/write
  8. LV Creation host, time localhost, -- :: +
  9. LV Status available
  10. # open
  11. LV Size 2.00 GiB
  12. Current LE
  13. Segments
  14. Allocation inherit
  15. Read ahead sectors auto
  16. - currently set to
  17. Block device :
  18.  
  19. --- Logical volume ---
  20. LV Path /dev/rhel/root //该逻辑卷实际就是Linux系统盘,我们将对它进行扩容
  21. LV Name root //逻辑卷名为root
  22. VG Name rhel
  23. LV UUID rI6Xvu-eCJx-0WFO-TuUj-LQWM-WuUc-3uE6zc
  24. LV Write Access read/write
  25. LV Creation host, time localhost, -- :: +
  26. LV Status available
  27. # open
  28. LV Size 17.51 GiB //逻辑卷的大小,即系统盘大小
  29. Current LE
  30. Segments
  31. Allocation inherit
  32. Read ahead sectors auto
  33. - currently set to
  34. Block device :

  第7步:对root逻辑卷进行扩容操作

  1. [root@linuxprobe ~]# lvextend -L +10G /dev/rhel/root
  2. Extending logical volume root to 27.51 GiB
  3. Insufficient free space: extents needed, but only available //显示实际空闲容量不足10GB,比10GB稍微小一点点
  4. [root@linuxprobe ~]# lvextend -L +5G /dev/rhel/root //这里我们先扩容5GB
  5. Extending logical volume root to 22.51 GiB
  6. Logical volume root successfully resized
  7. [root@linuxprobe ~]# lvdisplay
  8.  
  9. ----------------省略部分输出内容------------------------
  10.  
  11. --- Logical volume ---
  12. LV Path /dev/rhel/root
  13. LV Name root
  14. VG Name rhel
  15. LV UUID rI6Xvu-eCJx-0WFO-TuUj-LQWM-WuUc-3uE6zc
  16. LV Write Access read/write
  17. LV Creation host, time localhost, -- :: +
  18. LV Status available
  19. # open
  20. LV Size 22.51 GiB //容量已从17.51GB提升至22.51GB
  21. Current LE
  22. Segments
  23. Allocation inherit
  24. Read ahead sectors auto
  25. - currently set to
  26. Block device :

  第8步:重置root逻辑卷的大小。xfs系统不需要先umount操作

  1. [root@linuxprobe ~]# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/mapper/rhel-root 18G .1G 15G % / //重置之前,先查看当前系统盘的大小,此时显示为18GB
  4. devtmpfs 985M 985M % /dev
  5. tmpfs 994M 80K 994M % /dev/shm
  6. tmpfs 994M 8.9M 986M % /run
  7. tmpfs 994M 994M % /sys/fs/cgroup
  8. /dev/sr0 .5G .5G % /media/cdrom
  9. /dev/sda1 497M 119M 379M % /boot
  10. [root@linuxprobe ~]# xfs_growfs /dev/rhel/root //重置root逻辑卷大小
  11. meta-data=/dev/mapper/rhel-root isize= agcount=, agsize= blks
  12. = sectsz= attr=, projid32bit=
  13. = crc=
  14. data = bsize= blocks=, imaxpct=
  15. = sunit= swidth= blks
  16. naming =version bsize= ascii-ci= ftype=
  17. log =internal bsize= blocks=, version=
  18. = sectsz= sunit= blks, lazy-count=
  19. realtime =none extsz= blocks=, rtextents=
  20. data blocks changed from to
  21. [root@linuxprobe ~]# df -h
  22. Filesystem Size Used Avail Use% Mounted on
  23. /dev/mapper/rhel-root 23G .1G 20G % / //系统盘成功扩容至23G,增加了5GB容量,且重启依然生效
  24. devtmpfs 985M 985M % /dev
  25. tmpfs 994M 80K 994M % /dev/shm
  26. tmpfs 994M 8.9M 986M % /run
  27. tmpfs 994M 994M % /sys/fs/cgroup
  28. /dev/sr0 .5G .5G % /media/cdrom
  29. /dev/sda1 497M 119M 379M % /boot

 至此,Linux系统盘扩容操作完毕。

 知识补充:

  1、重置逻辑卷命令 "xfs_growfs /dev/rhel/root" 和 "xfs_growfs /dev/mapper/rhel-root" 效果一样;

  2、如果是ext4文件系统,重置命令为"resize2fs /dev/rhel/root";

  3、xfs文件系统只能扩容,不允许缩容。

  1. [root@linuxprobe ~]# pvs
  2. PV VG Fmt Attr PSize PFree
  3. /dev/sda2 rhel lvm2 a-- .51g
  4. /dev/sdb1 rhel lvm2 a-- .00g .00g //还省5GB空闲容量

Linux系统系统盘扩容的更多相关文章

  1. Linux系统硬盘扩容

    参考教程:https://www.jb51.net/article/144291.htm 1.查看硬盘已经用了99% $ df -h #查看硬盘已经使用了99% 文件系统 容量 已用 可用 已用% 挂 ...

  2. Oracle VM VirtualBox虚拟机内Linux系统硬盘扩容步骤(CentOS6.5)

    1.首先获取要扩容的虚拟机的 UUID VBoxManage 改命令在C:\Program Files\Oracle\VirtualBox目录内,可先添加该目录到环境变量.C:\Users\yzkj- ...

  3. linux LVM 系统盘扩容

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

  4. Linux系统盘扩容-物理机非虚拟机

    # Linux系统盘扩容 ## 了解磁盘分区情况 - `blkid` 查看分区情况- `fdisk -l` 分区表 ## 系统挂载分区 - `/etc/fstab` 启动挂载分区情况 ## 双系统下分 ...

  5. Linux系统LVM分区减容扩容

    Linux系统LVM分区减容扩容 目标:将VolGroup-lv_home缩小到20G,并将剩余的空间添加给VolGroup-lv_root 1.首先查看磁盘使用情况 [root@localhost ...

  6. linux 系统扩容 VMware Centos---VMware ESXi

    用到的命令 df  fdisk  pvcreate   pvdisplay    vgdisplay    vgextend    lvdisplay    lvextend  resize2fs 0 ...

  7. 虚拟机linux系统 硬盘/root路径扩容

    调整完后,重新打开虚拟机,使用fdisk -l查看,可以看到我们刚刚扩容的空间已经可以看到,但没有分区,还不能使用./dev/sda已经拥有了扩大的空间. 使用Linux的fdisk分区工具给磁盘/d ...

  8. centos7下使用LVM给系统硬盘扩容超详细

    简单介绍: LVM是逻辑盘卷管理(Logical Volume Manager)的简称,它是Linux环境下对磁盘分区进行管理的一种机制,LVM是建立在硬盘和分区之上的一个逻辑层,来提高磁盘分区管理的 ...

  9. 【转载】CentOS7下使用LVM给系统硬盘扩容

    原文地址:https://www.cnblogs.com/ding2016/p/9680690.html 简单介绍: LVM是逻辑盘卷管理(Logical Volume Manager)的简称,它是L ...

随机推荐

  1. 82)PHP,基本框架类步骤

    framework.class.php 基本代码展示: <?php /** * 框架初始化功能类 */ class Framework { /** * 入口 * 里面的static和self是一 ...

  2. django框架基础-视图系统-长期维护

    ##################   什么是视图?     ####################### 视图: 1,一个视图函数(类),简称视图,是一个简单的Python 函数(类),它接受W ...

  3. python学习笔记(1)python数据类型

    一.数据类型计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网页等各种各样的数据,不同的数据,需要 ...

  4. leetcode第36题:有效的数独

    解题思路:按行,列,3*3方格读取元素,存入字典中.若字典中该元素的值大于1,则返回false,否则返回true. class Solution: def isValidSudoku(self, bo ...

  5. 林轩田机器学习基石笔记4—Feasibility of Learning

    上节课介绍了机器学习可以分为不同的类型.其中,监督式学习中的二元分类和回归分析是最常见的也是最重要的机器学习问题.本节课,我们将介绍机器学习的可行性,讨论问题是否可以使用机器学习来解决. 一.Lear ...

  6. [LC] 252. Meeting Rooms

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  7. DB2数据库多行一列转换成 一行一列

    在db2中遇到多行一列转为一行一列的需求时,用db2函数 LISTAGG可以实现该功能.语法如下: SELECT   [分组的字段 ] , LISTAGG([需要聚合的字段名], ',')   FRO ...

  8. Android开发之《安全防护》

    逆向 java混淆 so加固 网络传输安全

  9. labview学习——生产者/消费者(数据)(事件)

    其主要的模型: 主要从以下几个方面理解: 1.可重入性 正常的labview是多线程设计语言,而我们在执行VI时的规则是通过VI的命名来分别调用实现的. 打开VI的Highlight调试工具,可以看出 ...

  10. 吴裕雄--天生自然HTML学习笔记:HTML 段落

    HTML 可以将文档分割为若干段落. HTML 段落 段落是通过 <p> 标签定义的. 实例 <p>这是一个段落 </p> <p>这是另一个段落< ...