Linux下调整目录的空间大小
一、目的
在使用CentOS6.5版本linux系统的时候,发现根目录(/)的空间不是很充足,而其他目录空间有很大的空闲,所以本文主要是针对现在已有的空间进行调整。首先,先来查看一下系统的空间分配情况:
[root@innoplay01 ~]# lsb_release -aLSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.5 (Final)
Release: 6.5
Codename: Final
[root@innoplay01 java]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_innoplay01-lv_root 50G 2.0G 45G 5% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/mapper/vg_innoplay01-lv_home 860G 200M 816G 1% /home
下面的详细步骤部分将从/dev/mapper/vg_innoplay01-lv_home 分区下取出661G的空间添加到/dev/mapper/vg_innoplay01-lv_root 分区上去。
卸载/dev/mapper/vg_innoplay01-lv_home分区:
[root@innoplay01 java]# umount /home
此时在用df命令查看将会发现/home目录已经看不见了,如下所示:
[root@innoplay01 java]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_innoplay01-lv_root 50G 2.0G 45G 5% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
从新设定/dev/mapper/vg_innoplay01-lv_home的大小:
resize2fs -p /dev/mapper/vg_innoplay01-lv_home 210G
[root@innoplay01 java]# resize2fs -p /dev/mapper/vg_innoplay01-lv_home 210G
resize2fs 1.41.12 (17-May-2010)
Please run 'e2fsck -f /dev/mapper/vg_innoplay01-lv_home' first.
依照提示执行:
e2fsck -f /dev/mapper/vg_innoplay01-lv_home
[root@innoplay01 java]# e2fsck -f /dev/mapper/vg_innoplay01-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_innoplay01-lv_home: 11/57237504 files (0.0% non-contiguous), 3643567/228918272 blocks
[root@innoplay01 java]# resize2fs -p /dev/mapper/vg_innoplay01-lv_home 210G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_innoplay01-lv_home to 55050240 (4k) blocks.
Begin pass 2 (max = 32768)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 6987)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/vg_innoplay01-lv_home is now 55050240 blocks long.
检查是否成功:
[root@innoplay01 java]# mount /home
[root@innoplay01 java]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_innoplay01-lv_root 50G 2.0G 45G 5% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/mapper/vg_innoplay01-lv_home 207G 188M 197G 1% /home
将/dev/mapper/vg_innoplay01-lv_home逻辑分区减小到指定大小:
lvreduce -L 210G /dev/mapper/vg_innoplay01-lv_home
[root@innoplay01 java]# lvreduce -L 210G /dev/mapper/vg_innoplay01-lv_home
WARNING: Reducing active and open logical volume to 210.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 210.00 GiB
Logical volume lv_home successfully resized
查询卷组的信息:
vgdisplay
[root@innoplay01 java]# vgdisplay
--- Volume group ---
VG Name vg_innoplay01
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 931.02 GiB
PE Size 4.00 MiB
Total PE 238341
Alloc PE / Size 68548 / 267.77 GiB
Free PE / Size 169793 / 663.25 GiB
VG UUID SyMjnp-iGwM-MkT1-UBUM-rSx8-hviz-EzTUEr
Free PE / Size指定的应该是现在可在分配的空间。
增加/dev/mapper/vg_innoplay01-lv_root分区的大小:
lvextend -L +661.00G /dev/mapper/vg_innoplay01-lv_root
[root@innoplay01 java]# lvextend -L +661.00G /dev/mapper/vg_innoplay01-lv_root
Extending logical volume lv_root to 711.00 GiB
Logical volume lv_root successfully resized
从新设定该分区的大小:
resize2fs -p /dev/mapper/vg_innoplay01-lv_root
[root@innoplay01 java]# resize2fs -p /dev/mapper/vg_innoplay01-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_innoplay01-lv_root is mounted on /; on-line resizing required
old desc_blocks = 18, new_desc_blocks = 45
Performing an on-line resize of /dev/mapper/vg_innoplay01-lv_root to 186384384 (4k) blocks.
The filesystem on /dev/mapper/vg_innoplay01-lv_root is now 186384384 blocks long.
再次查看分区大小:
[root@innoplay01 java]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_innoplay01-lv_root 700G 2.0G 663G 1% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/mapper/vg_innoplay01-lv_home 207G 188M 197G 1% /home
注意点:
1、在卸载/home目录的时候失败,可先执行如下fuser命令,然后再umount即可:fuser -m /home ;
2、设定完lv_home的大小,再次mount该分区时,发现用df命令无法看到给分区,此时只要在mount一次即可;
3、在设定lv_root的大小时,不要把Free PE / Size的空间全部都用上,这很可能会出现Free PE空间不足的现象,建议保留一点Free PE的空间。
更多推荐
所有评论(0)