实验环境
虚拟机软件:VMware Workstation
操作系统:Read Hat Enteprise 6.3
注意: 1、不能在线缩减,得先卸载;
2、确保缩减后的空间大小依然能存储原有的所有数据;
3、在缩减之前应该先强行检查文件,以确保文件系统处于一致性状态;
1.查看home磁盘映射的位置
[ root@template ~]# mount
/dev/mapper/vg_template-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/vg_template-lv_home on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sr0 on /media type iso9660 (ro)
2.卸载home目录
[ root@template ~]# umount /dev/mapper/vg_template-lv_home
3.检查home文件目录
[ root@template ~]# e2fsck /dev/mapper/vg_template-lv_home
e2fsck 1.41.12 (17-May-2010)
/dev/mapper/vg_template-lv_home: clean, 11/6553600 files, 459349/26214400 blocks
4.缩小home文件目录
[ root@template ~]# resize2fs -f /dev/mapper/vg_template-lv_home 5G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_template-lv_home to 1310720 (4k) blocks.
The filesystem on /dev/mapper/vg_template-lv_home is now 1310720 blocks long.
5.缩小home的lv
[ root@template ~]# lvreduce -L 5G /dev/mapper/vg_template-lv_home
WARNING: Reducing active logical volume to 5.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 5.00 GiB
Logical volume lv_home successfully resized
6.查看lv
[ root@template ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
lv_home vg_template -wi-a--- 5.00g
lv_root vg_template -wi-ao-- 50.00g
lv_swap vg_template -wi-ao-- 1.94g
7.挂载home目录
[ root@template ~]# mount -a
8.检查home目录的大小
[ root@template ~]# df -h
Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_template-lv_root
50G 1.4G 46G 3% /
tmpfs 242M 0 242M 0% /dev/shm
/dev/sda1 485M 32M 429M 7% /boot
/dev/sr0 3.5G 3.5G 0 100% /media
/dev/mapper/vg_template-lv_home
5.0G 160M 4.6G 4% /home