美文网首页
CentOS_7给root目录扩容实践记录

CentOS_7给root目录扩容实践记录

作者: 辉耀辉耀 | 来源:发表于2017-12-04 18:16 被阅读0次

    前言:在实际工作中常遇到类似问题,所以特做一次实践,记录下来供大家参考。


    环境:centOS 7 虚拟机
    配置:1CPU 2G内存 200G硬盘

    1.查看分区

    [root@test ~]# df -h
    Filesystem           Size  Used Avail Use% Mounted on
    /dev/mapper/cl-root   50G 1020M   49G   2% /
    devtmpfs             901M     0  901M   0% /dev
    tmpfs                912M     0  912M   0% /dev/shm
    tmpfs                912M  8.6M  904M   1% /run
    tmpfs                912M     0  912M   0% /sys/fs/cgroup
    /dev/sda1           1014M  139M  876M  14% /boot
    /dev/mapper/cl-home  147G   33M  147G   1% /home
    tmpfs                183M     0  183M   0% /run/user/0
    
    [root@test ~]# fdisk -l
    
    Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x000b8796
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200   419430399   208665600   8e  Linux LVM
    
    Disk /dev/mapper/cl-root: 53.7 GB, 53687091200 bytes, 104857600 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 /dev/mapper/cl-swap: 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 bytes
    
    
    Disk /dev/mapper/cl-home: 157.8 GB, 157831659520 bytes, 308264960 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
    

    2.终止占用/home进程
    a.安装psmisc

    [root@test ~]# yum -y install psmisc
    

    b.使用fuser命令

    [root@test ~]# fuser -m -v -i -k /home​
    

    3.卸载/home

    [root@test ~]# umount /home
    

    4.删除/home所在的lv

    [root@test ~]# lvremove /dev/mapper/cl-home 
    Do you really want to remove active logical volume cl/home? [y/n]: y
      Logical volume "home" successfully removed
    

    5.扩展/root所在的lv,增加100G

    [root@test ~]# lvextend -L +100G /dev/mapper/cl-root 
      Size of logical volume cl/root changed from 50.00 GiB (12800 extents) to 150.00 GiB (38400 extents).
      Logical volume cl/root successfully resized.
    

    6.扩展/root文件系统

    [root@test ~]# xfs_growfs /dev/mapper/cl-root 
    meta-data=/dev/mapper/cl-root    isize=512    agcount=4, agsize=3276800 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0 spinodes=0
    data     =                       bsize=4096   blocks=13107200, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal               bsize=4096   blocks=6400, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    data blocks changed from 13107200 to 39321600
    

    7.重新创建home的lv

    [root@test ~]# lvcreate -L 40G -n home cl
      Logical volume "home" created.
    

    8.创建文件系统

    [root@test ~]# mkfs.xfs /dev/cl/home 
    meta-data=/dev/cl/home           isize=512    agcount=4, agsize=2621440 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=10485760, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=5120, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    

    9.挂载/home

    [root@test ~]# mount /dev/cl/home /home
    

    10.还原/home相关文件以及对应目录权限

    [root@test ~]# chmod -R 755 /home
    

    11.结果展现,可以看到/dev/mapper/cl-root已经由50G变为了150G

    [root@test ~]# df -h
    Filesystem           Size  Used Avail Use% Mounted on
    /dev/mapper/cl-root  150G  1.1G  149G   1% /
    devtmpfs             901M     0  901M   0% /dev
    tmpfs                912M     0  912M   0% /dev/shm
    tmpfs                912M  8.6M  904M   1% /run
    tmpfs                912M     0  912M   0% /sys/fs/cgroup
    /dev/sda1           1014M  139M  876M  14% /boot
    tmpfs                183M     0  183M   0% /run/user/0
    /dev/mapper/cl-home   40G   33M   40G   1% /home
    

    相关文章

      网友评论

          本文标题:CentOS_7给root目录扩容实践记录

          本文链接:https://www.haomeiwen.com/subject/fioxixtx.html