Linux服务器默认建立的LVM逻辑卷磁盘空间分配不合理,根目录不够用,如何缩减和扩展逻辑卷?
把home目录缩减到50G,把根目录扩容到400G
第一步:逻辑卷的缩减,有风险,先缩减逻辑边界——再缩减物理边界 注意:1、不能在线缩减,得先卸载; 2、确保缩减后的空间大小依然能存储原有的所有数据; 3、在缩减之前应该强行检查文件,确保文件系统处于一致性状态
df –lh umount 卸载 e2fsck -f /PATH/TO/PV 强行文件系统检查,看是否有问题
开始缩减 用lvdisplay命令查看逻辑卷消息 resize2fs /PATH/TO/PV 50G
缩减(逻辑边界)为50G (缩减后的总共大小为50G)
lvreduce -L [-]# /PATH/TO/LV 缩减(物理边界)为50G mount -a
重新挂在
下面为实际操作过程及结果:
[iyunv@wlm ~]# umount /dev/vg_wlm2/lv_home
[iyunv@wlm ~]# resize2fs /dev/vg_wlm2/lv_home 50G
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 13107200 blocks long. Nothing to do!
[iyunv@wlm ~]# lvreduce -L 50G /dev/vg_wlm2/lv_home
WARNING: Reducing active logical volume to 50.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 50.00 GiB
Logical volume lv_home successfully resized
[iyunv@wlm ~]# mount -a
[iyunv@wlm ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_wlm2-lv_root 50G 38G 8.8G 82% /
tmpfs 1.4G 144K 1.4G 1% /dev/shm
/dev/sda1 485M 40M 420M 9% /boot
/dev/mapper/vg_wlm2-lv_home 50G 23G 25G 49% /home
注意:lv的物理路径要用lvdisplay查看,用df查看的只是挂载点
第二步:逻辑卷的扩张:先扩张物理边界———再扩张逻辑边界 把根目录扩张到400G 扩张物理边界 命令:lvextend -L [+]# /PATH/TO/LV 扩展逻辑边界 resize2fs resize2fs -p /PATH/TO/LV 注意:过程有点长,正常现象
下面为实际操作过程及结果:
[iyunv@wlm ~]# lvextend -L 400G /dev/vg_wlm2/lv_root
Extending logical volume lv_root to 400.00 GiB
Logical volume lv_root successfully resized
You have new mail in /var/spool/mail/root
[iyunv@wlm ~]# resize2fs -p /dev/vg_wlm2/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_wlm2/lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 25
Performing an on-line resize of /dev/vg_wlm2/lv_root to 104857600 (4k) blocks.
The filesystem on /dev/vg_wlm2/lv_root is now 104857600 blocks long.
You have new mail in /var/spool/mail/root
|