[Linux] 调整服务器磁盘分区

查看服务器分区情况 df -h   ==> 减少db分区大小,增加/分区大小
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VG_XXX-LV_ROOT
                      145G  130G  7.0G  95% /
/dev/mapper/VG_XXX-LV_OPT_DATA_DB
                      193G  271M  183G   1% /opt/xxx/data/db

卸载db分区,并压缩db分区大小(注意:调整后的空间大于已使用的空间)
# umount /opt/xxx/data/db

将db分区大小压缩至100G
# e2fsck -f /dev/mapper/VG_XXX-LV_OPT_DATA_DB
# resize2fs -p /dev/mapper/VG_XXX-LV_OPT_DATA_DB 100G
# mount /opt/xxx/data/db
# lvreduce -L 100G /dev/mapper/VG_XXX-LV_OPT_DATA_DB

将/分区大小增加92G
# lvextend -L +92G /dev/mapper/VG_XXX-LV_ROOT
# resize2fs -p /dev/mapper/VG_XXX-LV_ROOT

过程参考:

[root@xxx ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VG_XXX-LV_ROOT
                      145G  130G  7.0G  95% /
tmpfs                  64G   72K   64G   1% /dev/shm
/dev/sda1             1.9G   70M  1.8G   4% /boot
/dev/mapper/VG_XXX-LV_OPT
                      173G  155G   11G  94% /opt
/dev/mapper/VG_XXX-LV_OPT_DATA_DB
                      193G  271M  183G   1% /opt/xxx/data/db
/dev/mapper/VG_XXX-LV_OPT_LOGS
                       96G   60M   92G   1% /opt/xxx/logs
You have mail in /var/spool/mail/root
[root@xxx ~]#
[root@xxx ~]# umount /opt/xxx/data/db
[root@xxx ~]#
[root@xxx ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VG_XXX-LV_ROOT
                      145G  130G  7.0G  95% /
tmpfs                  64G   72K   64G   1% /dev/shm
/dev/sda1             1.9G   70M  1.8G   4% /boot
/dev/mapper/VG_XXX-LV_OPT
                      173G  155G   11G  94% /opt
/dev/mapper/VG_XXX-LV_OPT_LOGS
                       96G   60M   92G   1% /opt/xxx/logs
[root@xxx ~]#
[root@xxx ~]# resize2fs -p /dev/mapper/VG_XXX-LV_OPT_DATA_DB 100G
resize2fs 1.41.12 (17-May-2010)
Please run 'e2fsck -f /dev/mapper/VG_XXX-LV_OPT_DATA_DB' first.

[root@xxx ~]# e2fsck -f /dev/mapper/VG_XXX-LV_OPT_DATA_DB
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
/lost+found not found.  Create<y>? yes

Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/mapper/VG_XXX-LV_OPT_DATA_DB: ***** FILE SYSTEM WAS MODIFIED *****
/dev/mapper/VG_XXX-LV_OPT_DATA_DB: 502/12804096 files (22.9% non-contiguous), 905533/51200000 blocks
[root@xxx ~]# resize2fs -p /dev/mapper/VG_XXX-LV_OPT_DATA_DB 100G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VG_XXX-LV_OPT_DATA_DB to 26214400 (4k) blocks.
Begin pass 2 (max = 53057)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 1563)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 12)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VG_XXX-LV_OPT_DATA_DB is now 26214400 blocks long.

[root@xxx ~]#
[root@xxx ~]# mount /opt/xxx/data/db
[root@xxx ~]#
[root@xxx ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VG_XXX-LV_ROOT
                      145G  130G  7.0G  95% /
tmpfs                  64G   72K   64G   1% /dev/shm
/dev/sda1             1.9G   70M  1.8G   4% /boot
/dev/mapper/VG_XXX-LV_OPT
                      173G  155G   11G  94% /opt
/dev/mapper/VG_XXX-LV_OPT_LOGS
                       96G   60M   92G   1% /opt/xxx/logs
/dev/mapper/VG_XXX-LV_OPT_DATA_DB
                       99G  271M   94G   1% /opt/xxx/data/db
[root@xxx ~]#
[root@xxx ~]# lvextend -L +92G /dev/mapper/VG_XXX-LV_ROOT
  Insufficient free space: 23552 extents needed, but only 0 available
[root@xxx ~]#
[root@xxx ~]#
[root@xxx ~]#
[root@xxx ~]# vgdisplay
  --- Volume group ---
  VG Name               VG_XXX
  System ID
  Format                lvm2
  Metadata Areas        7
  Metadata Sequence No  10
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                7
  Open LV               7
  Max PV                0
  Cur PV                7
  Act PV                7
  VG Size               760.77 GiB
  PE Size               4.00 MiB
  Total PE              253638
  Alloc PE / Size       253638 / 760.77 GiB
  Free  PE / Size       0 / 0
  VG UUID               JGfWv6-lkiX-na7P-tdxo-x0X5-W0Mh-bpsOQM

[root@xxx ~]# lvreduce -L 100G /dev/mapper/VG_XXX-LV_OPT_DATA_DB
  WARNING: Reducing active and open logical volume to 100.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LV_OPT_DATA_DB? [y/n]: y
  Size of logical volume VG_XXX/LV_OPT_DATA_DB changed from 195.31 GiB (50000 extents) to 100.00 GiB (25600 extents).
  Logical volume LV_OPT_DATA_DB successfully resized
[root@xxx ~]#
[root@xxx ~]# lvextend -L +92G /dev/mapper/VG_XXX-LV_ROOT
  Size of logical volume VG_XXX/LV_ROOT changed from 146.48 GiB (37500 extents) to 238.48 GiB (61052 extents).
  Logical volume LV_ROOT successfully resized
[root@xxx ~]#
[root@xxx ~]# resize2fs -p /dev/mapper/VG_XXX-LV_ROOT
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VG_XXX-LV_ROOT is mounted on /; on-line resizing required
old desc_blocks = 10, new_desc_blocks = 15
Performing an on-line resize of /dev/mapper/VG_XXX-LV_ROOT to 62517248 (4k) blocks.
The filesystem on /dev/mapper/VG_XXX-LV_ROOT is now 62517248 blocks long.

[root@xxx ~]#
[root@xxx ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VG_XXX-LV_ROOT
                      235G  130G   93G  59% /
tmpfs                  64G   72K   64G   1% /dev/shm
/dev/sda1             1.9G   70M  1.8G   4% /boot
/dev/mapper/VG_XXX-LV_OPT
                      173G  155G   11G  94% /opt
/dev/mapper/VG_XXX-LV_OPT_LOGS
                       96G   60M   92G   1% /opt/xxx/logs
/dev/mapper/VG_XXX-LV_OPT_DATA_DB
                       99G  271M   94G   1% /opt/xxx/data/db
[root@xxx ~]#

参考资料: 
Centos/Linux下调整分区大小(以home和根分区为例) https://blog.csdn.net/qq_33233768/article/details/65437609
 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值