• Edit
  • Delete

lvm cheatsheet

  • apt-get install lvm2
  • pvcreate /dev/sda4 /dev/sdb1
  • vgcreate vg0 /dev/sda4 /dev/sdb1
  • lvcreate -n srv -l 100%FREE vg0
  • mkfs.ext4 /dev/vg0/srv

 

  • pvdisplay
    • Display physical volume information
  • vgdisplay
    vgs
    • Display volume group information
  • lvdisplay
    lvs
    • Display logical volume information
  • lvcreate -L108G -n goldfish vg0
    • Create volume
  • lvextend -L+3T /dev/mapper/vg0-lv--srv
    • -> Enlarges volume by 3GB. Then:
    • umount /dev/mapper/vg0-lv--srv
    • e2fsck -f /dev/mapper/vg0-lv--srv
    • resize2fs /dev/mapper/vg0-lv--srv
    • mount /dev/mapper/vg0-lv--srv

Snapshots

  • lvcreate --size 1G --snapshot --name test /dev/vg0/vm_images
    • create snapshot
  • lvremove /dev/vg0/test
    • remove snapshot

Shrink logical volume

https://blog.shadypixel.com/how-to-shrink-an-lvm-volume-safely/

Example: Reduce /srv from 460G to 422G

  • umount /srv
  • fsck.ext4 -f -y /dev/vg0/srv
  • resize2fs /dev/vg0/srv 400G
    • A good amount smaller than the final size, because it is unclear if the tools work with 1000 or 1024 multipliers
  • lvreduce -L 422G /dev/vg0/srv
  • resize2fs /dev/vg0/srv
    • Resize filesystem to max size
  • fsck.ext4 -f -y /dev/vg0/srv
  • vgs
  • mount /srv

Moving a volume group

http://www.linuxquestions.org/questions/linux-software-2/ubuntu-move-kvm-guest-from-one-host-to-another-870211/

http://www.linuxquestions.org/questions/linux-general-1/cloning-logical-volume-with-dd-341961/

Resizing

http://libguestfs.org/virt-resize.1.html

 

Troubleshooting

/dev/dm-3: read failed after 0 of 4096 at 0: Input/output error

  • dmsetup ls
  • dmsetup info /dev/dm-3
  • lsblk
  • pvs
  • lvdisplay
    •  LV snapshot status     INACTIVE destination for /dev/vg0/vm_images
  • -> deleted snapshot "lvremove /dev/vg0/vm_xxx"