• CentOS环境下下调整home和根分区大小


    项目建设方给提供了3台CentOS的服务器,连接进去之后发现磁盘空间很大,但是都放在了home目录下,所以需要调整一下。

    1、查看磁盘使用情况

    [root@CentOS ~]# df -h
    Filesystem                     Size  Used Avail Use% Mounted on
    /dev/mapper/vg_centos-lv_root   50G  9.9G   37G  22% /
    tmpfs                          3.9G   72K  3.9G   1% /dev/shm
    /dev/sda1                      485M   40M  421M   9% /boot
    /dev/mapper/vg_centos-lv_home  439G  200M  417G   1% /home

    2、卸载/home

    [root@CentOS ~]# umount /home
    [root@CentOS ~]# 
    [root@CentOS ~]# df -h
    Filesystem                     Size  Used Avail Use% Mounted on
    /dev/mapper/vg_centos-lv_root   50G   11G   37G  22% /
    tmpfs                          3.9G   72K  3.9G   1% /dev/shm
    /dev/sda1                      485M   40M  421M   9% /boot

    3、调整分区大小

    [root@CentOS ~]# resize2fs -p /dev/mapper/vg_centos-lv_home 40G
    resize2fs 1.41.12 (17-May-2010)
    请先运行 'e2fsck -f /dev/mapper/vg_centos-lv_home'.
    [root@CentOS ~]# e2fsck -f /dev/mapper/vg_centos-lv_home
    e2fsck 1.41.12 (17-May-2010)
    第一步: 检查inode,块,和大小
    第二步: 检查目录结构
    第3步: 检查目录连接性
    Pass 4: Checking reference counts
    第5步: 检查簇概要信息
    /dev/mapper/vg_centos-lv_home: 163/29212672 files (0.0% non-contiguous), 1884450/116819968 blocks

    再次执行

    [root@CentOS ~]# resize2fs -p /dev/mapper/vg_centos-lv_home 40G
    resize2fs 1.41.12 (17-May-2010)
    Resizing the filesystem on /dev/mapper/vg_centos-lv_home to 10485760 (4k) blocks.
    Begin pass 2 (max = 32975)
    正在重定位块            XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    Begin pass 3 (max = 3566)
    正在扫描inode表          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    Begin pass 4 (max = 84)
    正在更新inode引用       XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    The filesystem on /dev/mapper/vg_centos-lv_home is now 10485760 blocks long.

    4、挂载/home

    [root@CentOS ~]# mount /home

    查看磁盘使用情况:

    [root@CentOS ~]# df -h
    Filesystem                     Size  Used Avail Use% Mounted on
    /dev/mapper/vg_centos-lv_root   50G   11G   37G  22% /
    tmpfs                          3.9G   72K  3.9G   1% /dev/shm
    /dev/sda1                      485M   40M  421M   9% /boot
    /dev/mapper/vg_centos-lv_home   40G  178M   38G   1% /home

    5、设置空闲空间

    [root@CentOS ~]# lvreduce -L 40G /dev/mapper/vg_centos-lv_home
      WARNING: Reducing active and open logical volume to 40.00 GiB
      THIS MAY DESTROY YOUR DATA (filesystem etc.)
    Do you really want to reduce lv_home? [y/n]: y
      Reducing logical volume lv_home to 40.00 GiB
      Logical volume lv_home successfully resized

    使用lvreduce指令用于减少LVM逻辑卷占用的空间大小。可能会删除逻辑卷上已有的数据,所以在操作前必须进行确认。记得输入 “y”
    [root@localhost ~]# lvreduce -L 20G /dev/mapper/VolGroup-lv_home
    注:lvreduce -L 20G的意思为设置当前文件系统为20G,如果lvreduce -l 20G是指从当前文件系统上减少20G
    使用lvreduce减小逻辑卷的大小。注意:减小后的大小不能小于文件的大小,否则会丢失数据。
     
    可以使用vgdisplay命令等查看一下可以操作的大小。也可以是用fdisk -l命令查看详细信息。
    [root@localhost ~]# vgdisplay
    注:vgdisplay为显示LVM卷组的元数据信息。

    6、将空闲空间挂载到根目录下

    [root@CentOS ~]# vgdisplay
      --- Volume group ---
      VG Name               vg_centos
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  5
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                3
      Open LV               3
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               499.51 GiB
      PE Size               4.00 MiB
      Total PE              127874
      Alloc PE / Size       24032 / 93.88 GiB
      Free  PE / Size       103842 / 405.63 GiB
      VG UUID               ASX7Lb-Y0p6-YCGH-hNYp-ewdK-iFse-fq7uWw
       
    [root@CentOS ~]# 
    [root@CentOS ~]# 
    [root@CentOS ~]# lvextend -L +400G /dev/mapper/vg_centos-lv_root
      Extending logical volume lv_root to 450.00 GiB
      Logical volume lv_root successfully resized
    [root@CentOS ~]# 
    [root@CentOS ~]# 
    [root@CentOS ~]# vgdisplay
      --- Volume group ---
      VG Name               vg_centos
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  6
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                3
      Open LV               3
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               499.51 GiB
      PE Size               4.00 MiB
      Total PE              127874
      Alloc PE / Size       126432 / 493.88 GiB
      Free  PE / Size       1442 / 5.63 GiB
      VG UUID               ASX7Lb-Y0p6-YCGH-hNYp-ewdK-iFse-fq7uWw
       
    [root@CentOS ~]# df -h
    Filesystem                     Size  Used Avail Use% Mounted on
    /dev/mapper/vg_centos-lv_root   50G   11G   37G  22% /
    tmpfs                          3.9G   72K  3.9G   1% /dev/shm
    /dev/sda1                      485M   40M  421M   9% /boot
    /dev/mapper/vg_centos-lv_home   40G  178M   38G   1% /home
    [root@CentOS ~]# 
    [root@CentOS ~]# 
    [root@CentOS ~]# resize2fs -p /dev/mapper/vg_centos-lv_root
    resize2fs 1.41.12 (17-May-2010)
    Filesystem at /dev/mapper/vg_centos-lv_root is mounted on /; on-line resizing required
    old desc_blocks = 4, new_desc_blocks = 29
    Performing an on-line resize of /dev/mapper/vg_centos-lv_root to 117964800 (4k) blocks.
    The filesystem on /dev/mapper/vg_centos-lv_root is now 117964800 blocks long.
    
    [root@CentOS ~]# df -h
    Filesystem                     Size  Used Avail Use% Mounted on
    /dev/mapper/vg_centos-lv_root  443G   11G  411G   3% /
    tmpfs                          3.9G   72K  3.9G   1% /dev/shm
    /dev/sda1                      485M   40M  421M   9% /boot
    /dev/mapper/vg_centos-lv_home   40G  178M   38G   1% /home
  • 相关阅读:
    数据库语句中(+)是什么意思
    MySQL的存储引擎(二)解决Warning Code : 3719 'utf8' is currently an alias for the character set UTF8MB3,...
    MSQL存储引擎(一)
    fastjson的使用,在redis里面存list
    js的发展历史,笔记
    spring的断言工具类Assert的基本使用
    httpclient的使用
    nginx的反向代理
    使用 Redis 连接池的原因
    springboot的yml自定义值的笔记
  • 原文地址:https://www.cnblogs.com/xusweeter/p/5964561.html
Copyright © 2020-2023  润新知