LVM

Introduction
LVM (Logical Volume Manager) allows the use of virtual logical devices to access disks, thus masking the nature of the physical devices on which the data resides. It is therefore possible to use a virtual device of which several physical hard disks can be part, even of different nature, speed and size. The advantages of such an approach to file system management are greater flexibility and scalability, high service availability and redundancy.

Schema
- Logical Volumes (LV)   |    lv_share   |    lv_backup   |   (unused)   | - Volume Groups   (VG)   |                 vg_fileserver                 | - Physical Volumes (PV)  | /dev/sdb1 | /dev/sdc1 | /dev/sdd1 | /dev/sde1 | -

Search for new or modified discs
To see new discs added to the machine: if [ -n "$(which rescan-scsi-bus.sh)" ]; then rescan-scsi-bus.sh -a -w 0-15; fi ls /sys/class/scsi_host/host*/scan | while read HOST; do echo "- - -" > "${HOST}"; done ls /sys/class/scsi_disk/*/device/rescan | while read DISK; do echo 1 > "${DISK}"; done

Physical Volumes (PV)
To create a Physical Volume (PV) on an existing partition, making the partition suitable for hosting Volume Groups (VG): pvcreate /dev/sdb1

To display all the Physical Volume (PV) present: pvdisplay pvs

To move all data from one Physical Volume (PV) to another: pvmove -i 10 /dev/sdb1 /dev/sdc1

Volume Groups (VG)
To create a Volume Group (VG) on a previously created Physical Volume (PV): vgcreate vg_name /dev/sdb1 /dev/sdc1

To activate an inactive Volume Group (VG): vgchange -a y vg_name

To extend a Volume Group (VG): vgextend vg_name /dev/sdd1

To view all Volume Group (VG) present: vgdisplay vgs

To rename a Volume Group (VG): vgrename vg_name vg_new_name

Logical Volumes (LV)
To create a Logical Volume (LV) large 2 GB on a previously created Volume Group (VG): lvcreate -L2G -n lv_name vg_name

To create a Logical Volume (LV) as large as the Volume Group (VG) previously created: lvcreate -l 100%FREE -n lv_name vg_name

To format the newly created Logical Volume (LV) in xfs: mkfs.xfs /dev/vg_name/lv_name

To extend a Logical Volume (LV) of 1 GB: lvextend -L+1G /dev/vg_name/lv_name

To extend a Logical Volume (LV) giving it all available space: lvextend -l+100%FREE /dev/vg_name/lv_name

To extend the filesystem on the newly extended Logical Volume (LV): xfs_growfs /mountpoint resize2fs /dev/vg_name/lv_name

To view all Logical Volume (LV) present: lvdisplay lvs

Add a new disk presented by VMware
fdisk -l 2>/dev/null | grep "Disk /dev/sd.\:" | sort
 * List of present disks:

pvcreate /dev/sdb
 * Creation of the new Physical Volume:

vgextend vg_name /dev/sdb
 * Extension of the existing Volume Group:

lvextend -L+1G /dev/vg_name/lv_name
 * Extension of existing Logical Volume:

xfs_growfs /mountpoint
 * Extension of the existing File System:

Enlargement of a disk presented by VMware
fdisk -l 2>/dev/null | grep "Disk /dev/sd.\:" | sort
 * Display current size:

if [ -n "$(which rescan-scsi-bus.sh)" ]; then rescan-scsi-bus.sh -a -w 0-15; fi ls /sys/class/scsi_host/host*/scan | while read HOST; do echo "- - -" > "${HOST}"; done ls /sys/class/scsi_disk/*/device/rescan | while read DISK; do echo 1 > "${DISK}"; done
 * Rescan for scsi device changes:

fdisk -l 2>/dev/null | grep "Disk /dev/sd.\:" | sort
 * Display new size:

fdisk /dev/sda
 * Repartitioning (only if there is one or more partitions on the disk):

Command (m for help): p Command (m for help): d Partition number (1-4): 2 Command (m for help): n Command action e  extended p  primary partition (1-4) Select (default p): p Partition number (1-4, default 2): 2 Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM) Command (m for help): p Command (m for help): w

partx -uv /dev/sda partprobe
 * Update of the partition table:

pvresize /dev/sda2
 * Resize of the PV:

lvextend -L+2G /dev/vg_name/lv_name xfs_growfs /mountpoint
 * Resize of the filesystem

More information
http://tldp.org/HOWTO/LVM-HOWTO/