查看当前磁盘信息:
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
154G 7.9G 139G 6% /
tmpfs 1.9G 100K 1.9G 1% /dev/shm
/dev/sda1 485M 69M 391M 15% /boot
/dev/mapper/VolGroup-lv_home
299G 984M 283G 1% /home
将VolGroup-lv_home缩小到20G,并将剩余的空间添加给VolGroup-lv_root
先卸载/home:
[root@localhost ~]# umount /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: 21/19857408 files (0.0% non-contiguous), 1498180/79429632 blocks
注:e2fsck为检查磁盘正确性
[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 = 32778)
正在重定位块 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 2424)
正在扫描inode表 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 10)
正在更新inode引用 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VolGroup-lv_home is now 5242880 blocks long.
注:resize2fs 为重新设定磁盘大小,只是重新指定一下大小,并不对结果有影响,需要下面lvreduce的配合
[root@localhost ~]# mount /home
[
[root@localhost ~]# lvreduce -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
注:lvreduce -L 20G的意思为设置当前文件系统为20G,如果lvreduce -l 20G是指从当前文件系统上减少20G
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
154G 7.9G 139G 6% /
tmpfs 1.9G 100K 1.9G 1% /dev/shm
/dev/sda1 485M 69M 391M 15% /boot
/dev/mapper/VolGroup-lv_home
20G 962M 18G 6% /home(说明成功了)
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 7
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 46660 / 182.27 GiB
Free PE / Size 72449 / 283.00 GiB
VG UUID gPA8XS-ZncK-mGQj-2Vn9-TFTQ-6yOU-6atjE9
注:vgdisplay为显示LVM卷组的元数据信息
[root@localhost ~]# lvextend -L +283G /dev/mapper/VolGroup-lv_root
Extending logical volume lv_root to 439.39 GiB
Logical volume lv_root successfully resized
注:lvextend -L +283G为在文件系统上增加238G
[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 = 10, new_desc_blocks = 28
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 115183616 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 115183616 blocks long.
检查一下调整的结果:
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
433G 7.9G 403G 2% /
tmpfs 1.9G 100K 1.9G 1% /dev/shm
/dev/sda1 485M 69M 391M 15% /boot
/dev/mapper/VolGroup-lv_home
20G 962M 18G 6% /home