A presentation by Dustin Laurence for the SGVLUG, 7/8/04.
Key Benefits Of LVM:
Less interesting (to me) features:
| DOS Disk Object/Concept | LVM Equivalent |
| (Physical) Partition | LVM Logical Volume |
| Disk | LVM Volume Group |
| Block | LVM Physical Extent |
| LVM Physical Volume | |
| (Physical) Partition |
(dev1, dev2, ...) -> newdev
Are you comfortable with fdisk & mkfs?
These tools don't care of their powers are used for good or evil! It ain't hard to shred a filesystem with them. =8-O
Operator Error is the operator's problem, not the tool builder's. You know, unix.
To use LVM, we need to make sure our installation supports it:
You need the LVM2 userland tools: pvcreate, lvscan, etc. In Gentoo, just type 'emerge lvm2'.)
Assuming we have the necessary tools, we are ready to use them. I will be using the tools on my home machine as we go (that's the drama part, remember?).
# man lvm
# lvm help
# man pvcreate
Unfortunately, the man pages are out of date (e.g. lvm2 format is the default, 'man lvm' doesn't list all the commands).
# man lvm.conf
# emacs /etc/lvm/lvm.conf
# cfdisk /dev/hda
(Don't forget to set the partition type: 0x8E for LVM, 0xFD for RAID.)
or
# emacs /etc/raidtab; mkraid
or
# mdadm --create /dev/md0 --level=raid1 -n 2 /dev/hda5 /dev/hdc5
# pvcreate /dev/hd[eg]13 /dev/hde14
# pvs
# pvscan
# pvdisplay /dev/hde13
# vgcreate -s 32M newsystem /dev/hd[eg]13
# vgs
# vgscan
# vgdisplay newsystem
# lvcreate -L 300M --contiguous y --name root newsystem
# lvs
# lvscan
# lvdisplay newsystem
# lvdisplay newsystem/root
Note the logical volume size is a multiple of the 32M physical extent size of the volume group.
# mkreiserfs -l '/' /dev/newsystem/root
# mkdir /mnt/newsystem
# emacs /etc/fstab
# mount /mnt/newsystem
# lvremove newsystem/root
You can't remove a mounted logical volume, fortunately.
# vgremove newsystem
You can't remove a volume group that contains logical volumes, either.
# vgs
# lvcreate -L 1.1G --contiguous y --name usr newsystem
There weren't enough contiguous extents on a single physical volume. (Note that LVM uses SI prefixes. It's probably a commie plot.)
# lvcreate -L 1.1G --name usr newsystem
# mkreiserfs -l '/usr' /dev/newsystem/usr
# mkdir /mnt/newsystem/usr
# emacs /etc/fstab
# mount /mnt/newsystem/usr/
All is well.
# lvdisplay newsystem/usr
# lvextend -L +200M newsystem/usr
# resize_reiserfs /dev/newsystem/usr
What didn't I do first?
# resize_reiserfs -s -500M /dev/newsystem/usr
But must umount to shrink.
# pvcreate /dev/hde14
# vgextend newsystem /dev/hde14
# lvextend -L +1G newsystem/usr
# resize_reiserfs /dev/newsystem/usr
# pvs
Note that newsystem/usr is larger than any of the physical volumes in the volume group. As long as it isn't forced to be contiguous, LVM can extend a logical volume with any extent on any physical volume in the volume group.
# umount /mnt/newsystem/usr
# resize_reiserfs -s -900M /dev/newsystem/usr
# lvreduce -L -800M /dev/newsystem/usr
# resize_reiserfs /dev/newsystem/usr
# mount /mnt/newsystem/usr/
# df -h
# pvs
We should be able to do this:
# umount /mnt/newsystem/usr
# resize_reiserfs -s -900M /dev/newsystem/usr
# lvreduce -L -800M /dev/newsystem/usr
# resize_reiserfs /dev/newsystem/usr
# mount /mnt/newsystem/usr/
# df -h
# pvs
# pvmove -v /dev/hde13
But it uses a temporary snapshot to do it, and guess what doesn't work yet?
Definitely RTFM:
How to set up LVM on root under Gentoo
Root-on-LVM-on-RAID HOWTO (from cold install)
Root-on-RAID and Root-on-LVM-on-RAID HOWTO (from existing system
Right now, LVM seems like the best alternative. But on the horizon: