无损分区,调整Liunx服务器分区大小,简明扼要
2018-01-25 本文已影响0人
李庆喜
因为开始装的服务器用的自动lvm,后来发现home下分区太大了,/分区太小。zabbix报警空间已用80%,所以必须要压缩home分区给/目录
感觉乱乱的,整理一下使用的命令按顺序和思路,简明扼要后面就不用看了:
1.umount /home ###如果发现busy不能卸载就fuser -m /home查看一下是什么进程在占用,然后kill -9 杀掉
2.resize2fs -p /dev/mapper/VolGroup-lv_home 20G ###先设置一下home的大小,做这部的时候会提醒让先运行下面的命令进行检查
3.e2fsck -f /dev/mapper/VolGroup-lv_home ###强制检查一下磁盘并修复错误
4.resize2fs -p /dev/mapper/VolGroup-lv_home 20G ###再次运行这个命令把home大小设置为20G
5.lvreduce -L 20G /dev/mapper/VolGroup-lv_home ###收缩逻辑卷空间为20G
6.mount /home ###并du -f 查看一下home 大小分配是否成功
7.lvextend -l +100%FREE /dev/mapper/VolGroup-lv_root ###把剩余的所有空间都分配给/目录
8.resize2fs -p /dev/mapper/VolGroup-lv_root ###执行调整根目录的空间大小,并耐心等待,不要操作
9.#等待一段时间后就成功了 df -h看看吧
- 首先:以防万一先备份好/home下的文件,然后umount /home分区
如果发现umount /home分区的时候提示busy说明有进程在占用home分区
建议用fuser -m /home
命令进行查看一下,然后kill -9 杀掉进程。 - 然后,
umount /home
[root@localhost ~]# umount /home
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 50G 40G 7.4G 85% /
tmpfs 16G 0 16G 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
[root@localhost ~]# resize2fs -p /dev/mapper/
control VolGroup-lv_home VolGroup-lv_root VolGroup-lv_swap
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 20G
resize2fs 1.41.12 (17-May-2010)
请先运行 'e2fsck -f /dev/mapper/VolGroup-lv_home'.
[root@localhost ~]# e2fsck -f /dev/mapper/VolGroup-lv_home
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/mapper/VolGroup-lv_home: 124/13942784 files (8.1% non-contiguous), 966453/55744512 blocks
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 20G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-lv_home to 5242880 (4k) blocks.
Begin pass 2 (max = 32873)
正在重定位块 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 1702)
正在扫描inode表 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 22)
正在更新inode引用 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VolGroup-lv_home is now 5242880 blocks long.
[root@localhost ~]# mount /home
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 50G 40G 7.4G 85% /
tmpfs 16G 0 16G 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/VolGroup-lv_home 20G 342M 19G 2% /home
这样就成功把/home分区成功调整到20G大小了,接下来我们进行操作,把剩下的空间分给根目录
[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/VolGroup-lv_rootlvreduce -L 20G /dev/mapper/VolGroup-lv_home
WARNING: Reducing active and open logical volume to 20.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 20.00 GiB
Logical volume lv_home successfully resized
[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/VolGroup-lv_root
Extending logical volume lv_root to 242.65 GiB
Logical volume lv_root successfully resized
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 16
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 63608832 (4k) blocks.
然后就是漫长的等待
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 114G 40G 69G 37% /
tmpfs 16G 0 16G 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/VolGroup-lv_home 20G 342M 19G 2% /home
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 117G 40G 71G 36% /
tmpfs 16G 0 16G 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/VolGroup-lv_home 20G 342M 19G 2% /home
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 118G 40G 73G 36% /
tmpfs 16G 0 16G 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/VolGroup-lv_home 20G 342M 19G 2% /home
可以看到正在扩容,完事