背景

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

    查看主机挂载信息

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

    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
    在这里插入图片描述
    最后扩大/根分区容量,操作命令参考扩容部分步骤。

    验证
    在这里插入图片描述

    标签: none

    添加新评论