File Systems/LVM

From wiki.mikejung.biz
Jump to navigation Jump to search

Liquidweb 728x90.jpg

LVM

Overview

  • A physical volume is a storage device that has had an LVM label applied; applying such a label is the first step to using the device through the LVM.
  • A Linux LVM configuration proceeds in a few distinct phases:

1) Creating (defining, really) and initializing physical volumes pvcreate /dev/$name

2) Adding the physical volumes to a volume group vgcreate $groupname /dev/$name

3) Creating logical volumes on the volume group lvcreate -L 100G -n $name $vgname

4) From there, you can create a file system mkfs /dev/$groupname/$lvname

Benefits of LVM

  • Move logical volumes among different physical devices
  • Grow and shrink logical volumes on the fly
  • Take copy-on-write “snapshots” of logical volumes
  • Replace on-line drives without interrupting service
  • Incorporate mirroring or striping in your logical volumes

Command Overview

Physical Volume:
##create
pvcreate
##inspect
pvdisplay
##modify
pvchange
##check
pvck

Volume Group:
##create
vgcreate
##modify
vgchange
##extend
vgextend
##inspect
vgdisplay
##check
vgck
##enable  
vgscan

Logical Volume:
##create
lvcreate
##modify
lvchange
##resize
lvresize
##inspect
lvdisplay

Snapshots

  • You can create copy-on-write duplicates of any LVM2 logical volume, whether or not it contains a filesystem.

To create /dev/example/web1-snap as a snapshot of /dev/example/web1, we would use the following command:

lvcreate -L 100G -s -n web1-snap example/web1

Resize a File system

## Unmount volume to be resized
umount /mnt/$volume

## Make the volume unavailable during the resize
lvchange -an $VG/$volume

## Add additional space
lvresize -L +10G $VG/$volume

## Make the volume available again
lvchange -ay $vg/$volume

## Check file system for consistency
e2fsck -f /dev/$vg/$volume

## Automatically resize FS to the size of the volume
resize2fs /dev/$vg/$volume

## Remount the resized volume
mount /dev/$vg/$volume /mnt/$volume

##Check to make sure all went well
df -h /mnt/$volume