New partition

  1. Use lsblk to ID the disk.
  2. Create LVM physical disk
sudo pvcreate /dev/$device     
  1. Create LVM volume group
sudo vgcreate $vg_name /dev/$device
  1. Create LVM logical volume
sudo lvcreate -l 100%FREE -n $lv_name $vg_name
  1. Format volume
sudo mkfs.ext4 /dev/$vg_name/$lv_name
  1. Create mountpoint
sudo mkdir /$mountpoint
  1. Find LVM device UUID (LVM-<something>)
dmsetup info -c --noheadings -o uuid /dev/$vg_name/$lv_name 
  1. Insert LVM device UUID into fstab, prefixed with /dev/disk/by-id/dm-uuid-:
sudo vi /etc/fstab
[...]
/dev/disk/by-id/dm-uuid-LVM-<something> /$mountpoint ext4 defaults 0 2
  1. Reload fstab
sudo systemctl daemon-reload
  1. Mount all disks
sudo mount -a

Extend partition

  1. Scan for new disk devices
ls /sys/class/scsi_host/ | while read host; do echo "- - -" > /sys/class/scsi_host/$host/scan; done

or Scan for resized disk (at /dev/sdb)

echo 1 > /sys/block/sdb/device/rescan
  1. Use fdisk/cfdisk/parted to create new partition or growpart -v /dev/sdb 1 to automatically expand the first partition of /dev/sdb to fill the disk
  2. Refresh partition table (if fdisk -l)
partx -v -a /dev/sdb
  1. Resize LVM stuff
vgextend $vg_name /dev/sdbX
lvextend -l +100%FREE -r /dev/$vg_name/$lv_name

The -r flag will automatically resize the file system too.


See also: