Digital Hermit  -- Unix and Linux Solutions  About    Linux    Mathematics    Science    The Project   
 

Introduction

  • What is an LVM?
    • Logical Volume Manger
    • Veritas, Solstice, AIX
    • Allows greater flexibility in defining volumes and filesystems
    • Ability to span disks
    • Resize filesystems without backup
  • Linux/Logical Volume Manager
  • Hierarchy
    • Physical Volumes
      • Disks
      • Partitions
      • "Disk File"
    • Logical Volumes
    • Volume Groups
    • Filesystems
  • Creating and Administering an LVM volume
    • Create Physical Volumes
    • Create a Volume Group from the physical volumes
    • Craete a Logical Volume within the Volume Group
    • Create a Filesystem withing the Logical Volume
    • Growing an LVM-based filesystem
      • Unmount the Filesystem
      • Extend the Volume Group if needed
      • Added Extents to the Logical Volume
      • Fsck the Filesytem
      • Remount

Demonstration

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
	
 
© 2002, 2003     Kwan Lowe     DigitalHermit