Logical Volume Manager

Example usage

Start by looking at our existing disks

cat /proc/scsi/
dmesg |grep sd

Next, partition the new disks using fdisk

fdisk /dev/sdb
  • p to Print the existing table (should be blank)
  • n to create a new partition
  • t to change partition system ID to 8e (Linux LVM)
  • w to write new table to disk

Repeat for /dev/sdc Create the physical volumes

pvcreate /dev/sdb1
pvcreate /dev/sdc1

NOTE: You can create multiple PVs on a single disk, but it is not recommended. Show existing Physical Volumes

pvscan

Show Volume Groups

vgscan (should return nothing)

Create a Volume Group from the Physical Volumes

vgcreate opt_vg /dev/sdb1 /dev/sdc1

NOTE: You can specify PE size in vgcreate. Default is 4M. You'd use larger PE sizes for LVs greater than 256G. 65K PEs per LV.

Show Volume Groups

vgscan (now shows the VG we created)

Display information about the VG

vgdisplay 

Create a Logical Volume within the VG

lvcreate -l num_of_extents -n opt_lv opt_vg
lvcreate -L 100M -n opt_lv opt_vg
lvcreate -L 100M -n opt_lv -i num_stripes opt_vg
lvcreate -L 100M -n opt_lv opt_vg [PhysicalVolumePath]

Display information about the LV

lvdisplay
lvdisplay -m (Show maps. Compare striped vs un-striped)

Create a mount point

mkdir /opt/foo1
mkdir /opt/striped

Create a filesystem

mkfs.ext3 /dev/opt_vg/opt_lv
mkfs.ext3 /dev/opt_vg/striped_lv

Mount the filesystems

mount /dev/opt_vg/opt_lv
df -h 

Growing a Filesystem

Grow an EXT2/3 filesystem (with unmount)

Unmount the FS

umount /mnt/lvm_filesystem

Extend the LV

lvresize -l +50 /dev/opt_vg/opt_lv
lvresize -L +200M /dev/opt_vg/opt_lv

fsck the filesystem

e2fsck -f /dev/opt_vg/opt_lv

Resize the filesystem

resize2fs /dev/opt_vg/opt_lv

Remount the filesystem

mount -t ext3 /dev/opt_vg/opt_lv /mnt/lvm_filesystem

Grow an EXT2/3 filesystem (without unmount)

Extend the LV

lvresize -l +50 /dev/opt_vg/opt_lv
lvresize -L +200M /dev/opt_vg/opt_lv

Grow the filesystem

ext2online /mnt/lvm_filesystem (using mount path)
ext2online /dev/opt_vg/opt_lv (using device)

Grow a ReiserFS filesystem Create a ReiserFS on /dev/opt_vg/striped_lv

mkreiserfs /dev/opt_vg/striped_lv

Mount the FS

df -h
lvresize -L +50M /dev/opt_vg/striped_lv
resize_reiserfs -f /dev/opt_vg/striped_lv
df -h

Add a Physical Volume to a VG

vgextend vgname /path/to/PV

Resizing crypted LVM

 cryptsetup -c aes -h ripemd160 -s 256 create home /dev/disk_array/data
 pvcreate /dev/hde1
 vgextend disk_array /dev/hde1
 lvresize -L +114G /dev/disk_array/data
 cryptsetup resize home
 resize_reiserfs -s +114G /dev/mapper/home
linux/lvm.txt · Last modified: 2009/05/25 00:35 (external edit)
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready