LVM

Logical Volume Manager

😄 Written by Zak Zhu

参考

  • 马哥linux视频
  • RHCE培训(rh133-unit13)

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

lv_process

  • 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相关命令

  • pvcreate

    pvcreate /dev/PHYSICAL_PARTION
    

    1

  • pvs & pvdisplay

    pvs				# 简要显示
    pvdisplay		# 详细显示
    

    2

    3

  • pvremove

    pvremove /dev/PHYSICAL_PATIONS
    
  • pvmove

    pvmove SRC_PV DEST_PV
    
  • pvscan

    pvscan			# scan all disks for physical volumes
    

    4

VG相关命令

PE默认大小: 4M

  • vgcreate

    vgcreate [-s PE_SIZE[bBkKmMgG]] VG_NAME PV_NAME
    

    5

  • vgs & vgdisplay

    vgs 			# 简要显示
    vgdisplay		# 详细显示
    

    6

    7

  • vgchange

    vgchange -s PE_SIZE[bBkKmMgG]			# 修改PE的大小
    
  • vgremove

    vgremove VG_NAME
    
  • vgextend

    vgextend VG_NAME PV_NAME
    

    8

  • vgreduce

    务必先考虑pvmove迁移数据, 再vgreduce

    vgreduce VG_NAME PV_NAME
    
  • vgscan

    vgscan			# scan all disks for volume groups and rebuild caches
    

LV相关命令

  • lvcreate

    lvcreate -L LV_SIZE[mMgGtT] -n LV_NAME VG_NAME 
    

    9

  • lvs & lvdisplay

    10

    11

  • lvremove

    lvremove /dev/mapper/VG_NAME-LV_NAME
    

    12

  • lvscan

    lvscan			# scan all disks for Logical Volumes
    

扩展LV

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

    vgs

    13

  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

    14

  5. 扩展文件系统的范围

    resize2fs /dev/mapper/vg0-lv_data

    15

  6. *挂载已扩展的LV

    mount -a

    16

缩减LV

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

  1. 一定要先卸载LV

    umount /dev/mapper/vg0-lv_data

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

    e2fsck -f /dev/mapper/vg0-lv_data

    17

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

    resize2fs /dev/mapper/vg0-lv_data 1G

    18

  4. 缩减LV的大小

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

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

    19

  5. 挂载已缩减的LV

    mount -a

    20

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

    21

  2. 挂载快照

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

    22

  3. 压缩备份

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

    23

  4. 卸载删除

    umount /dev/mapper/vg0-snap_data

    lvremove /dev/mapper/vg0-snap_data

    24

posted @ 2019-10-02 01:29  ZakZhu  阅读(163)  评论(0编辑  收藏  举报