• centos 扩展root根分区的大小


    目标:将VolGroup-lv_home缩小到125G,并将剩余的空间添加给VolGroup-lv_root
     
    1.首先查看磁盘使用情况
    [root@localhost ~]# df -h
    文件系统    容量  已用 可用  已用% 挂载点    
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/vg_hostname-lv_root
                           20G  8.7G  9.6G  48% /
    tmpfs                 6.9G   72K  6.9G   1% /dev/shm
    /dev/sda1             485M   38M  422M   9% /boot
    /dev/mapper/vg_hostname-lv_home
                          171G  110G   53G  68% /home
    /dev/sdb5             2.0T  805G  1.1T  43% /xxxx_sdb5
    /dev/sdc5             1.7T  197M  1.6T   1% /xxxx_sdc5

     
    2、卸载/home
    [root@localhost ~]# umount /home
    umount: /home: device is busy.
            (In some cases useful info about processes that use
             the device is found by lsof(8) or fuser(1))

    umount /home 如果提示无法卸载,则是有进程占用/home,使用如下命令来终止占用进程:
    [root@localhost ~]# fuser -m /home  
    /home:               31112m
    top
    kill -9 31112
     
    3、调整分区大小
    [root@localhost ~]# resize2fs -p /dev/mapper/vg_hostname-lv_home 125G
    resize2fs 1.41.12 (17-May-2010)
    Please run 'e2fsck -f /dev/mapper/vg_hostname-lv_home' first.

    如果提示运行“e2fsck -f /dev/mapper/VolGroup-lv_home”,则执行相关命令:
    [root@localhost ~]# e2fsck -f /dev/mapper/vg_hostname-lv_home 然后重新执行命令:
    [root@localhost ~]# resize2fs -p /dev/mapper/vg_hostname-lv_home 125G
    resize2fs 1.41.12 (17-May-2010)
    Resizing the filesystem on /dev/mapper/vg_hostname-lv_home to 32768000 (4k) blocks.
    Begin pass 2 (max = 7110485)
    Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    Begin pass 3 (max = 1385)
    Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    Begin pass 4 (max = 3237)
    Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    The filesystem on /dev/mapper/vg_hostname-lv_home is now 32768000 blocks long.

    注:resize2fs 为重新设定磁盘大小,只是重新指定一下大小,并不对结果有影响,需要下面lvreduce的配合
     
    4、挂载上/home,查看磁盘使用情况
    [root@localhost ~]# mount /home
    [root@localhost ~]# df -h
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/vg_hostname-lv_root
                           20G  8.7G  9.6G  48% /
    tmpfs                 6.9G   72K  6.9G   1% /dev/shm
    /dev/sda1             485M   38M  422M   9% /boot
    /dev/sdb5             2.0T  805G  1.1T  43% /xxxx_sdb5
    /dev/sdc5             1.7T  197M  1.6T   1% /xxxx_sdc5
    /dev/mapper/vg_hostname-lv_home
                          124G  110G  7.4G  94% /home

     
    5、设置空闲空间
    使用lvreduce指令用于减少LVM逻辑卷占用的空间大小。可能会删除逻辑卷上已有的数据,所以在操作前必须进行确认。记得输入 “y”
    [root@localhost ~]# lvreduce -L 125G /dev/mapper/vg_hostname-lv_home
      WARNING: Reducing active and open logical volume to 125.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 125.00 GiB
      Logical volume lv_home successfully resized

    注:lvreduce -L 125G的意思为设置当前文件系统为125G,如果lvreduce -l 125G是指从当前文件系统上减少125G
    使用lvreduce减小逻辑卷的大小。注意:减小后的大小不能小于文件的大小,否则会丢失数据。
     
    可以使用vgdisplay命令等查看一下可以操作的大小。也可以是用fdisk -l命令查看详细信息。
    [root@localhost ~]# vgdisplay
      --- Volume group ---
      VG Name               vg_hostname
      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               199.51 GiB
      PE Size               4.00 MiB
      Total PE              51074
      Alloc PE / Size       38758 / 151.40 GiB
      Free  PE / Size       12316 / 48.11 GiB
      VG UUID               zk1eHH-QXe8-sdm8-cKfF-StSl-yffz-Dfe9sF
    注:vgdisplay为显示LVM卷组的元数据信息
     
    6.把闲置空间挂在到根目录下
    [root@localhost ~]# lvextend -L +48G /dev/mapper/vg_hostname-lv_root
      Extending logical volume lv_root to 67.53 GiB
      Logical volume lv_root successfully resized
    注:lvextend -L +48G为在文件系统上增加48G
    [root@localhost ~]# resize2fs -p /dev/mapper/vg_hostname-lv_root
    resize2fs 1.41.12 (17-May-2010)
    Filesystem at /dev/mapper/vg_hostname-lv_root is mounted on /; on-line resizing required
    old desc_blocks = 2, new_desc_blocks = 5
    Performing an on-line resize of /dev/mapper/vg_hostname-lv_root to 17702912 (4k) blocks.
    The filesystem on /dev/mapper/vg_hostname-lv_root is now 17702912 blocks long.

    7、检查调整结果
    [root@localhost ~]# df -h
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/vg_hostname-lv_root
                           67G  8.7G   55G  14% /
    tmpfs                 6.9G   72K  6.9G   1% /dev/shm
    /dev/sda1             485M   38M  422M   9% /boot
    /dev/sdb5             2.0T  805G  1.1T  43% /xxxx_sdb5
    /dev/sdc5             1.7T  197M  1.6T   1% /xxxx_sdc5
    /dev/mapper/vg_hostname-lv_home
                          124G  110G  7.4G  94% /home

  • 相关阅读:
    Jzoj3555 树的直径
    Jzoj3555 树的直径
    51Nod1022 石子归并V2
    51Nod1022 石子归并V2
    Bzoj3998 弦论
    Bzoj3998 弦论
    Poj2758 Checking the Text
    Poj2758 Checking the Text
    常用SQL语句大全
    Silverlight调用GP服务第二篇之调用GP服务(Geoprocessing Service)过程详解
  • 原文地址:https://www.cnblogs.com/emanlee/p/4622434.html
Copyright © 2020-2023  润新知