实验目的:
调整前
lv_root分区大小为50G
Lv_home分区大小为45G
调整后(将lv_home分区减少30G,将30G空间加到lv_root分区)
lv_root分区大小为80G
Lv_home分区大小为15G
操作前注意备份重要数据
1查看磁盘使用情况Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_lvm-lv_root 50G 769M 46G 2% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/mapper/vg_lvm-lv_home 45G 180M 43G 1% /home
2卸载/homeFilesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_lvm-lv_root 50G 769M 46G 2% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
注意:umount /home 如果提示无法卸载,则是有进程占用/home,使用如下命令来终止占用进程:
[[email protected] ~]# fuser -m /home
3调整lv_home分区大小[[email protected] ~]# resize2fs -p /dev/mapper/vg_lvm-lv_home 15G
resize2fs 1.41.12 (17-May-2010)
Please run 'e2fsck -f /dev/mapper/vg_lvm-lv_home' first.
[[email protected] ~]# e2fsck -f /dev/mapper/vg_lvm-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_lvm-lv_home: 12/2992416 files (0.0% non-contiguous), 233858/11962368 blocks
[[email protected] ~]# resize2fs -p /dev/mapper/vg_lvm-lv_home 15G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_lvm-lv_home to 3932160 (4k) blocks.
Begin pass 2 (max = 32769)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 366)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 6)
Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/vg_lvm-lv_home is now 3932160 blocks long.
注:resize2fs 为重新设定磁盘大小,只是重新指定一下大小,并不对结果有影响,需要下面lvreduce的配合
4挂载/home查看使用情况[[email protected] ~]# mount /dev/mapper/vg_lvm-lv_home /home
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_lvm-lv_root 50G 769M 46G 2% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/mapper/vg_lvm-lv_home 15G 168M 14G 2% /home
5设置空闲空间
使用lvreduce指令用于减少LVM逻辑卷占用的空间大小。可能会删除逻辑卷上已有的数据,所以在操作前必须进行确认。记得输入 “y[[email protected] ~]# lvreduce -L 15G /dev/mapper/vg_lvm-lv_home
WARNING: Reducing active and open logical volume to 15.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 15.00 GiB
Logical volume lv_home successfully resized
注:lvreduce -L 15G的意思为设置当前文件系统为15G,如果lvreduce –l 15G是指从当前文件系统上减少15G
使用lvreduce减小逻辑卷的大小。注意:减小后的大小不能小于文件的大小,否则会丢失数据。
可以使用vgdisplay命令等查看一下可以操作的大小。也可以是用fdisk -l命令查看详细信息。--- Volume group ---
VG Name vg_lvm
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 99.51 GiB
PE Size 4.00 MiB
Total PE 25474
Alloc PE / Size 17632 / 68.88 GiB
Free PE / Size 7842 / 30.63 GiB
VG UUID NOS2vP-0HRm-eh9K-cHx1-ZnOS-45CA-SOvjGz
注:vgdisplay为显示LVM卷组的元数据信息
6把闲置空间添加到lv_rootFilesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_lvm-lv_root 50G 769M 46G 2% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/mapper/vg_lvm-lv_home 15G 168M 14G 2% /home
[[email protected] ~]# lvextend -L +30G /dev/mapper/vg_lvm-lv_root
Extending logical volume lv_root to 80.00 GiB
Logical volume lv_root successfully resized
注:lvextend -L +30G为在文件系统上增加30G
[[email protected] ~]# resize2fs -p /dev/mapper/vg_lvm-lv_root
执行后需要等待几分钟才能显示执行结果
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_lvm-lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 5
Performing an on-line resize of /dev/mapper/vg_lvm-lv_root to 20971520 (4k) blocks.
The filesystem on /dev/mapper/vg_lvm-lv_root is now 20971520 blocks long.
7查看调整结果Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_lvm-lv_root 79G 773M 74G 2% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/mapper/vg_lvm-lv_home 15G 168M 14G 2% /home