Linux: Logical Volume Manager (LVM) - Paiet/Tech-Journal-for-Everything GitHub Wiki

  • Drive naming convention
    • /dev/sda
    • /dev/sda1
    • /dev/sdb
    • /dev/sdb3
  • List available physical drives:
    • fdisk -l
  • Create a partition
    • fdisk /dev/sdb
    • n - Create new partition
    • p - primary partition
      • When done press "p" for a list
    • w - write the changes
  • Reboot or execute "partprobe"
  • If install was a minimal install
    • yum install lvm2
  • Create physical volumes
    • pvcreate /dev/sdb1 /dev/sdc1
  • Verify creation
    • pvdisplay or pvs
  • Create a volume group
    • vgcreate vg1 /dev/sdb1 /dev/sdc1
    • vgdisplay or vgs
  • Create logical volumes
    • lvcreate -L <size> vg1 -n <name>
    • lvcreate -L 250G vg1 -n website
  • Format and mount the logical volume
    • mkfs.ext4 /dev/vg1/website
    • mkdir /website
    • mount /dev/vg1/website /website
    • semanage fcontext -a -t httpd_sys_content_t /website
    • restorecon /website
  • Add more storage to the volume group / logical volume
    • fdisk /dev/sdd
      • n - create new partition
      • w - write changes
    • partprobe
    • pvcreate /dev/sdd1
    • vgextend vg1 /dev/sdd1
    • lvresize -L +1G /dev/vg1/website
    • df -h
    • resize2fs /dev/vg1/website
    • df -h
    • lvs or lvdisplay
  • Verify volume added to /etc/fstab if needed at boot
    • more /etc/fstab/dev/mapper/vg1-lv1
    • /website ext4 defaults 1 1
      • 1 - Do backup
        • 1 - Do check for errors
  • Tear it all down
    • umount /website
    • lvremove /dev/vg1/website
    • vgremove /dev/vg1
    • pvremove /dev/sdb1 /dev/sdc1 /dev/sdd1
⚠️ **GitHub.com Fallback** ⚠️