在使用CentOS6.3
版本linux
系统的时候,发现根目录(/)
的空间不是很充足,而其他目录空间有很大的空闲,所以本文主要是针对现在已有的空间进行调整。首先,先来查看一下系统的空间分配情况:
01.[root@CentOS-78 /]# df -h
02.Filesystem Size Used Avail Use% Mounted on
03./dev/mapper/vg_centos-lv_root
04. 50G 14G 34G 30% /
05.tmpfs 1.9G 0 1.9G 0% /dev/shm
06./dev/sda1 485M 37M 423M 8% /boot
07./dev/mapper/vg_centos-lv_home
08. 404G 670M 382G 1% /home
下面的详细步骤部分将从vg_centos-lv_home
分区下取出100G
的空间添加到/vg_centos-lv_root
分区上去。
01.[root@CentOS-78 /]# umount /home
此时在用df
命令查看将会发现/home
目录已经看不见了,如下所示:
01.[root@CentOS-78 /]# df -h
02.Filesystem Size Used Avail Use% Mounted on
03./dev/mapper/vg_centos-lv_root
04. 50G 14G 34G 30% /
05.tmpfs 1.9G 0 1.9G 0% /dev/shm
06./dev/sda1 485M 37M 423M 8% /boot
vg_home-lv_home
的大小01.[root@CentOS-78 /]# resize2fs -p /dev/mapper/vg_centos-lv_home 282G
02.resize2fs 1.41.12 (17-May-2010)
03.Please run 'e2fsck -f /dev/mapper/vg_centos-lv_home' first.
这一步设定vg_home-lv_home
大小没有成功,系统提示我们先运行下面的命令,操作如下:
01.[root@CentOS-78 /]# e2fsck -f /dev/mapper/vg_centos-lv_home
02.e2fsck 1.41.12 (17-May-2010)
03.Pass 1: Checking inodes, blocks, and sizes
04.Pass 2: Checking directory structure
05.Pass 3: Checking directory connectivity
06.Pass 4: Checking reference counts
07.Pass 5: Checking group summary information
08./dev/mapper/vg_centos-lv_home: 1386/26836992 files (0.9% non-contiguous), 1855856/107344896 blocks
从新设定vg_home-lv_home
的大小:
01.[root@CentOS-78 /]# resize2fs -p /dev/mapper/vg_centos-lv_home 282G
02.resize2fs 1.41.12 (17-May-2010)
03.Resizing the filesystem on /dev/mapper/vg_centos-lv_home to 73924608 (4k) blocks.
04.Begin pass 2 (max = 43)
05.Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
06.Begin pass 3 (max = 3276)
07.Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
08.Begin pass 4 (max = 266)
09.Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
10.The filesystem on /dev/mapper/vg_centos-lv_home is now 73924608 blocks long.
检查是否成功:
01.[root@CentOS-78 /]# mount /home
02.[root@CentOS-78 /]#
03.[root@CentOS-78 /]# df -h
04.Filesystem Size Used Avail Use% Mounted on
05./dev/mapper/vg_centos-lv_root
06. 50G 14G 34G 30% /
07.tmpfs 1.9G 0 1.9G 0% /dev/shm
08./dev/sda1 485M 37M 423M 8% /boot
09./dev/mapper/vg_centos-lv_home
10. 278G 663M 263G 1% /home
11.[root@CentOS-78 /]#
lv_home
逻辑分区减小到指定大小01.[root@CentOS-78 /]# lvreduce -L 282G /dev/mapper/vg_centos-lv_home
02. WARNING: Reducing active and open logical volume to 282.00 GiB
03. THIS MAY DESTROY YOUR DATA (filesystem etc.)
04.Do you really want to reduce lv_home? [y/n]: y
05. Reducing logical volume lv_home to 282.00 GiB
06. Logical volume lv_home successfully resized
07.[root@CentOS-78 /]#
我认为这个命令是将已经减少的100G
空间拿到系统公共的区域,可以被其他分区加载和利用。
查询卷组的信息:
01.[root@CentOS-78 /]# vgdisplay
02. --- Volume group ---
03. VG Name vg_centos
04. System ID
05. Format lvm2
06. Metadata Areas 1
07. Metadata Sequence No 5
08. VG Access read/write
09. VG Status resizable
10. MAX LV 0
11. Cur LV 3
12. Open LV 3
13. Max PV 0
14. Cur PV 1
15. Act PV 1
16. VG Size 465.27 GiB
17. PE Size 4.00 MiB
18. Total PE 119109
19. Alloc PE / Size 86472 / 337.78 GiB
20. Free PE / Size 32637 / 127.49 GiB
21. VG UUID 1k4ooN-RFV9-uyf1-uMYf-aERG-YaGs-ZNoSD6
Free PE / Size
指定的应该是现在可在分配的空间。
vg_centos-lv_root
分区的大小将可用的空间添加到vg_centos-lv_root
分区上面:
01.[root@CentOS-78 /]# lvextend -L +127.40G /dev/mapper/vg_centos-lv_root
02. Rounding up size to full physical extent 127.40 GiB
03. Extending logical volume lv_root to 177.40 GiB
04. Logical volume lv_root successfully resized
05.[root@CentOS-78 /]#
从新设定该分区的大小:
01.[root@CentOS-78 /]# resize2fs -p /dev/mapper/vg_centos-lv_root
02.resize2fs 1.41.12 (17-May-2010)
03.Filesystem at /dev/mapper/vg_centos-lv_root is mounted on /; on-line resizing required
04.old desc_blocks = 4, new_desc_blocks = 12
05.Performing an on-line resize of /dev/mapper/vg_centos-lv_root to 46504960 (4k) blocks.
06.The filesystem on /dev/mapper/vg_centos-lv_root is now 46504960 blocks long.
01.[root@CentOS-78 /]# df -h
02.Filesystem Size Used Avail Use% Mounted on
03./dev/mapper/vg_centos-lv_root
04. 175G 14G 153G 9% /
05.tmpfs 1.9G 0 1.9G 0% /dev/shm
06./dev/sda1 485M 37M 423M 8% /boot
07./dev/mapper/vg_centos-lv_home
08. 278G 663M 263G 1% /home
我们发现vg_centos-lv_root
分区的空间已经增加了125G
,之所以比lv_home
减少的空间要多25G
主要是由于我们把系统所有的可用的空间都加在了lv_root
分区。
/home
目录的时候失败可先执行如下fuser
命令,然后再umount
即可:
01.[root@CentOS-78 /]# fuser -m /home
02.[root@CentOS-78 /]#
lv_home
的大小,再次mount
该分区时,发现用df
命令无法看到给分区,此时只要在mount
一次即可lv_root
的大小时,不要把Free PE / Size
的空间全部都用上,这很可能会出现Free PE
空间不足的现象,建议保留一点Free PE
的空间。