• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Linux系统/根分区扩容

武飞扬头像
php00py
帮助1

背景

项目中遇到/分区不足需要扩容,需要对/分区进行扩容

查看主机挂载信息

查看当前挂载使用的磁盘信息

df -Th

学新通
使用fdisk –l 查看当前主机磁盘信息,给主机挂上多余的磁盘
学新通
通过 fdisk /dev/sdb 操作来分出一块分区/dev/sdb1,将磁盘修改成lvm

[root@localhost ~]# 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 0x680e669a.

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): 1
First sector (2048-209715199, default 2048): 
Using default value 2048
Last sector,  sectors or  size{K,M,G} (2048-209715199, default 209715199): 
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): p

Disk /dev/sdb: 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: 0x680e669a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   209715199   104856576   83  Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

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

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

再次查看磁盘列表,发现磁盘/dev/sdb已经有了sdb1的分区

学新通

使用pvcreate /dev/sdb1对新分区出来的磁盘创建物理卷
学新通
使用vgdisplay命令查看当前主机的卷组
学新通
使用vgextend rhel /dev/sdb1命令将新分区的sdb1加入到卷组rhel
学新通

扩容

当前主机/目录磁盘容量大小
学新通

使用lvextend -L 99G /dev/mapper/rhel-root对/目录进行扩容
学新通

最后对文件系统进行扩容,不对文件系统进行扩容不会生效,使用resize2fs /dev/mapper/rhel-root 进行扩容

特别注意:文件格式是ext4使用resize2fs进行系统扩容,文件格式是xfs使用xfs_growfs /dev/mapper/rhel-root

验证

使用df –Th 进行查看当前主机的/目录发现以及扩容到108G
学新通

使用其他目录下的逻辑卷对/目录扩容

df –Th查看当前主机挂载情况,如图,使用/app下的逻辑卷对/目录进行扩容,在此请先确认所使用的卷组是否和/目录所使用的的卷组是否是同一个,如果不是同一个卷组,使用lvremove命令删除逻辑卷,然后在对/根目录对应的卷组扩容后。在参考下面操作。
学新通
卸载前请先对/app目录下的文件进行备份。
学新通
删除原/app逻辑卷

lvremove /dev/mapper/rhel-captcahlv

学新通
2) 扩容/逻辑卷

lvextend -L  98G /dev/mapper/rhel-root

学新通
最后扩大/根分区容量,操作命令参考扩容部分步骤。

验证

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgebjfj
系列文章
更多 icon
同类精品
更多 icon
继续加载