notes blog about

LVM is the implementation of logical volume management in Linux. As I don’t use it on a day-to-day basis, I created this blog in case I forgot the basics :-).

Terminology

       sda1   sdc       (PVs on partitions or whole disks)
          \   /
           \ /
          diskvg        (VG)
          /  |  \
         /   |   \
     usrlv rootlv varlv (LVs)
       |      |     |
    ext4  reiserfs  xfs (filesystems)

Working with LVM

Creating Volumes

  1. Create PV (initialize disk)

    pvcreate /dev/md0
    

    Check the results with pvdisplay

  2. Create VG

    vgcreate rootvg /dev/md0
    

    Check the results with vgdisplay

  3. Create LV

    lvcreate --name backuplv --size 50G rootvg
    

    Check the results with lvdisplay

  4. Create filesystem

    mkfs.ext3 /dev/rootvg/backuplv
    
  5. Edit /etc/fstab

    # RAID 1 + LVM
    /dev/rootvg/backuplv   /backup        ext3    rw,noatime      0       0
    
  6. Create mount point and mount volume(s)

    mkdir /backup
    mount /backup
    

Extending LV

  1. Extend the LV

    lvextend -L +5G /dev/rootvg/backuplv
    
  2. Re-size the filesystem (online re-sizing doesn’t seem to cause troubles)

    resize2fs /dev/rootvg/backuplv
    

Snapshotting LV (e.g. for doing backups)

lvcreate -L 50G -s -n backuplv-snap rootvg/backuplv  # should be short-lived or of the same size as source LV

See also