LVM

Creating Logical Volumes
1.
Prepare underlying block devices
Can use partitions of type 0x8e or software RAID devices
2.
Create physical volumes
# pvcreate /dev/hda3
3.
Create volume group containing physical volume
# vgcreate vg0 /dev/hda3
4.
Create logical volumes inside volume groups
# lvcreate -L 256M -n data vg0
5.
Format and mount logical volume (/dev/vg0/data)

Resizing Logical Volumes
Growing logical volumes and filesystems
lvextend can grow logical volumes
resize2fs can grow ext3 filesystems online or offline
Shrinking filesystems and logical volumes
Must be done offline (umount)
Requires a filesystem check (e2fsck) first
Filesystem then reduced (resize2fs)
Lastly, lvreduce can then reduce the volume

Resizing Volume Groups
Volume Groups can be enlarged with:
# vgextend vg0 /dev/sdb1
Volume Groups can be reduced with:
# pvmove /dev/hda3
# vgreduce vg0 /dev/hda3

Logical Volume Manager Snapshots
Snapshots are special Logical Volumes that are an exact copy of an existing Logical Volume at the time the snapshot is created
Snapshots are perfect for backups and other operations where a temporary copy of an existing dataset is needed
Snapshots only consume space where they are different from the original Logical Volume
Snapshots are allocated space at creation but do not use it until changes are made to the original Logical Volume or the Snapshot
When data is changed on the original Logical Volume the older data is copied to the Snapshot
Snapshots contain only data that has changed on the original Logical Volume or the Snapshot since the Snapshot was created.

Using LVM Snapshots
1. Create snapshot of existing Logical Volume
# lvcreate -l 64 -s -n datasnap /dev/vg0/data
2. Mount snapshot
# mkdir -p /mnt/datasnap
# mount -o ro /dev/vg0/datasnap /mnt/datasnap
3. Perform backup
4. Remove snapshot
# umount /mnt/datasnap
# lvremove /dev/vg0/datasnap

Leave a Reply

You must be logged in to post a comment.