Linux下如何调整根目录的空间大小
一、目的
在使用centos6.3版本linux系统的时候,发现根目录(/)的空间不是很充足,而其他目录空间有很大的空闲,所以本文主要是针对现在已有的空间进行调整。首先,先来查看一下系统的空间分配情况:
[root@centos-78 /]# df -h filesystem size used avail use% mounted on /dev/mapper/vg_centos-lv_root 50g 14g 34g 30% / tmpfs 1.9g 0 1.9g 0% /dev/shm /dev/sda1 485m 37m 423m 8% /boot /dev/mapper/vg_centos-lv_home 404g 670m 382g 1% /home
下面的详细步骤部分将从vg_centos-lv_home分区下取出100g的空间添加到/vg_centos-lv_root分区上去。
二、详细步骤
1、卸载vg_centos-lv_home分区
[root@centos-78 /]# umount /home
此时在用df命令查看将会发现/home目录已经看不见了,如下所示:
[root@centos-78 /]# df -h filesystem size used avail use% mounted on /dev/mapper/vg_centos-lv_root 50g 14g 34g 30% / tmpfs 1.9g 0 1.9g 0% /dev/shm /dev/sda1 485m 37m 423m 8% /boot
2、从新设定vg_home-lv_home的大小
[root@centos-78 /]# resize2fs -p /dev/mapper/vg_centos-lv_home 282g resize2fs 1.41.12 (17-may-2010) please run 'e2fsck -f /dev/mapper/vg_centos-lv_home' first.
这一步设定vg_home-lv_home大小没有成功,系统提示我们先运行下面的命令,操作如下:
[root@centos-78 /]# e2fsck -f /dev/mapper/vg_centos-lv_home e2fsck 1.41.12 (17-may-2010) pass 1: checking inodes, blocks, and sizes pass 2: checking directory structure pass 3: checking directory connectivity pass 4: checking reference counts pass 5: checking group summary information /dev/mapper/vg_centos-lv_home: 1386/26836992 files (0.9% non-contiguous), 1855856/107344896 blocks
从新设定vg_home-lv_home的大小:
[root@centos-78 /]# resize2fs -p /dev/mapper/vg_centos-lv_home 282g resize2fs 1.41.12 (17-may-2010) resizing the filesystem on /dev/mapper/vg_centos-lv_home to 73924608 (4k) blocks. begin pass 2 (max = 43) relocating blocks xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx begin pass 3 (max = 3276) scanning inode table xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx begin pass 4 (max = 266) updating inode references xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx the filesystem on /dev/mapper/vg_centos-lv_home is now 73924608 blocks long.
检查是否成功:
[root@centos-78 /]# mount /home [root@centos-78 /]# [root@centos-78 /]# df -h filesystem size used avail use% mounted on /dev/mapper/vg_centos-lv_root 50g 14g 34g 30% / tmpfs 1.9g 0 1.9g 0% /dev/shm /dev/sda1 485m 37m 423m 8% /boot /dev/mapper/vg_centos-lv_home 278g 663m 263g 1% /home [root@centos-78 /]#
3、将lv_home逻辑分区减小到指定大小
[root@centos-78 /]# lvreduce -l 282g /dev/mapper/vg_centos-lv_home warning: reducing active and open logical volume to 282.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 282.00 gib logical volume lv_home successfully resized [root@centos-78 /]#
我认为这个命令是将已经减少的100g空间拿到系统公共的区域,可以被其他分区加载和利用。
查询卷组的信息:
[root@centos-78 /]# 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 465.27 gib pe size 4.00 mib total pe 119109 alloc pe / size 86472 / 337.78 gib free pe / size 32637 / 127.49 gib vg uuid 1k4oon-rfv9-uyf1-umyf-aerg-yags-znosd6
free pe / size指定的应该是现在可在分配的空间。
4、增加vg_centos-lv_root分区的大小
将可用的空间添加到vg_centos-lv_root分区上面:
[root@centos-78 /]# lvextend -l +127.40g /dev/mapper/vg_centos-lv_root rounding up size to full physical extent 127.40 gib extending logical volume lv_root to 177.40 gib logical volume lv_root successfully resized [root@centos-78 /]#
从新设定该分区的大小:
[root@centos-78 /]# 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 = 12 performing an on-line resize of /dev/mapper/vg_centos-lv_root to 46504960 (4k) blocks. the filesystem on /dev/mapper/vg_centos-lv_root is now 46504960 blocks long.
5、再次查看分区大小
[root@centos-78 /]# df -h filesystem size used avail use% mounted on /dev/mapper/vg_centos-lv_root 175g 14g 153g 9% / tmpfs 1.9g 0 1.9g 0% /dev/shm /dev/sda1 485m 37m 423m 8% /boot /dev/mapper/vg_centos-lv_home 278g 663m 263g 1% /home
我们发现vg_centos-lv_root分区的空间已经增加了125g,之所以比lv_home减少的空间要多25g主要是由于我们把系统所有的可用的空间都加在了lv_root分区。
三、所遇到的问题
1、在卸载/home目录的时候失败
可先执行如下fuser命令,然后再umount即可:
[root@centos-78 /]# fuser -m /home [root@centos-78 /]#
2、设定完lv_home的大小,再次mount该分区时,发现用df命令无法看到给分区,此时只要在mount一次即可
3、在设定lv_root的大小时,不要把free pe / size的空间全部都用上,这很可能会出现free pe空间不足的现象,建议保留一点free pe的空间。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: Bootstrap导航简单实现代码
下一篇: SEO工作中外链建设15个最佳技巧