Linux 磁盘空间调整

环境:OS: Red Hat Enterprise Linux Server release 6.5 (Santiago)

准备阶段

1.记录当前卷名称、大小

[root@cdhslave5 ~]# df -h
Filesystem                     Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-LogVol01   50G   41G  6.3G  87% /
tmpfs                           16G     0   16G   0% /dev/shm
/dev/xvda1                     194M   30M  155M  16% /boot
/dev/mapper/VolGroup-LogVol02  2.0T   32G  1.9T   2% /home
cm_processes                    16G     0   16G   0% /var/run/cloudera-scm-agent/process

2.设定目标目标:从 /dev/mapper/VolGroup-LogVol02 调整 1T 到 /dev/mapper/VolGroup-LogVol01

3.记录当前磁盘挂载情况

[root@cdhslave5 ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  ...
  Free  PE / Size       5577 / 21.79 GiB

当前可分配磁盘为 21.79GB

步骤预览

1.卸载分区

[root@cdhslave5 ~]# 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))

[root@cdhslave5 ~]# fuser -m /home
/home:                 336ce  1942ce 16741cm 21443ce 23193ce 25565ce

[root@cdhslave5 ~]# ps -ef | grep 336
[root@cdhslave5 ~]# kill -9 336 
...
[root@cdhslave5 ~]# umount /home

有用户进程正在运行是无法卸载的。可通过fuser找到进程信息,逐个结束进程再卸载。

2.设定被调整卷大小

[root@cdhslave5 ~]# resize2fs -p /dev/mapper/VolGroup-LogVol02 1024G
Please run 'e2fsck -f /dev/mapper/VolGroup-LogVol02' first.

[root@cdhslave5 ~]# e2fsck -f /dev/mapper/VolGroup-LogVol02
Pass 1: Checking inodes, blocks, and sizes
...

[root@cdhslave5 ~]# resize2fs -p /dev/mapper/VolGroup-LogVol02 1024G
...
The filesystem on /dev/mapper/VolGroup-LogVol02 is now 268435456 blocks long.

3.装载分区

[root@cdhslave5 ~]# mount /home
[root@cdhslave5 ~]# df -h
Filesystem                     Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-LogVol01   50G   41G  6.3G  87% /
...
/dev/mapper/VolGroup-LogVol02 1008G   32G  926G   4% /home

如果df命令无法看到分区,可再在mount一次。

4.将逻辑分区减小到指定大小

 [root@cdhslave5 ~]# lvreduce -L 1024G /dev/mapper/VolGroup-LogVol02

摘:"我认为这个命令是将已经减少的100G空间拿到系统公共的区域,可以被其他分区加载和利用。"

5.查看可分配卷信息

[root@cdhslave5 ~]# vgdisplay
 Free  PE / Size       267721 / 1.02 TiB

6.增加目标分区大小

lvextend -L +1024G /dev/mapper/VolGroup-LogVol01 

# 注意在设定目标分区大小时,建议不要把Free PE / Size的空间全部都用上,这很可能会出现Free PE空间不足的现象,建议保留一点Free PE的空间。

7.调整目标卷大小

[root@cdhslave5 ~]# resize2fs -p /dev/mapper/VolGroup-LogVol01

[root@cdhslave5 ~]# df -h
Filesystem                     Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-LogVol01  1.1T   41G  963G   5% /
...
/dev/mapper/VolGroup-LogVol02 1008G   32G  926G   4% /home

参考文档

posted on 2019-03-12 10:27  傅腾(futeng)  阅读(523)  评论(0编辑  收藏  举报