LVM

时间:2019-10-02 09:36:47   收藏:0   阅读:120

Logical Volume Manager

?? Written by Zak Zhu

参考

LVM

LVM依赖于内核Device Mapper模块

LV设备文件: /dev/mapper/VG_NAME-LV_NAME

  • A layer of abstraction that allows easy manipulation of volumes
  • Supports resizing of filesystems
  • Allows filesystems to span multiple physical devices

技术分享图片

  • Block devices are designated as Physical Volumes
  • One or more Physical Volumes are used to created a Volume Group
  • Volume Groups are defined with Physical Extents of a fixed size
  • Logical Volumes are composed of Physical Extents from Volume Group
  • Filesystems may be created on Logical Volumes

yum install lvm2 -y # 安装lvm2

PV相关命令

VG相关命令

PE默认大小: 4M

LV相关命令

扩展LV

  1. 查看所属的VG是否有足够的剩余空间

    vgs

    技术分享图片

  2. *卸载要扩展的LV

    umount /dev/mapper/vg0-lv_data

  3. *强制检查要扩展的LV的文件系统

    e2fsck -f /dev/mapper/vg0-lv_data

  4. 扩展LV的大小

    lvextend -L +1G /dev/mapper/vg0-lv_data

    技术分享图片

  5. 扩展文件系统的范围

    resize2fs /dev/mapper/vg0-lv_data

    技术分享图片

  6. *挂载已扩展的LV

    mount -a

    技术分享图片

缩减LV

危险警告: 尽量不要做缩减LV !!

  1. 一定要先卸载LV

    umount /dev/mapper/vg0-lv_data

  2. 强制检查要缩减的LV的文件系统

    e2fsck -f /dev/mapper/vg0-lv_data

    技术分享图片

  3. 缩减LV的文件系统的范围

    resize2fs /dev/mapper/vg0-lv_data 1G

    技术分享图片

  4. 缩减LV的大小

    强烈建议: 缩减后的LV大小要求略大于缩减后的文件系统大小 !!!

    lvreduce -L 1.2G /dev/mapper/vg0-lv_data

    技术分享图片

  5. 挂载已缩减的LV

    mount -a

    技术分享图片

LVM快照

  • Snapshots are special Logical Volumes
  • Snapshots are perfect for bacups where a temporary copy of an existing dataset is needed
  • Snapshots only consume space where they are different from the original Logical Volume

使用快照

  1. 创建快照

    lvcreate -L 200M -s -n snap_data /dev/mapper/vg0-lv_data

    技术分享图片

  2. 挂载快照

    mount -o ro /dev/mapper/vg0-snap_data /mnt/snap_data

    技术分享图片

  3. 压缩备份

    tar -Jpcv -f snap_data$(date +"%Y%m%d-%H%M").txz /mnt/snap_data/*

    技术分享图片

  4. 卸载删除

    umount /dev/mapper/vg0-snap_data

    lvremove /dev/mapper/vg0-snap_data

    技术分享图片

原文:https://www.cnblogs.com/zakzhu/p/11616627.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!