Author
Christopher Marshall (christopherlmarshall@yahoo.com)
Raw Notes on LVM
# main configuration file is at
/etc/lvm/lvm.conf
# it controls many things.
# one of which is what types of devices lvm will consider OK as PV devices.
# to get it to allow devices mapped through /dev/mapper, for example,
# like you would have to do if you wanted to encrypt PVs, you have to add
# this line
types = [ "device-mapper", 16 ]
# the first argument is the name of one of the device categories found in
# /proc/devices and the second is the number of partitions of the device
# to serach over.
# another aspect to this is which device nodes lvm will query.
# this is controlled by the "filter" line
# a filter is an array of regular expressions prefixed with "a"
# (for add) and "r" (for remove.
# Here are some examples:
# searches every possible block device
filter = [ "a/.*/" ]
# Exclude the cdrom drive
filter = [ "r|/dev/cdrom|" ]
# only allow loop devices
filter = [ "a/loop/", "r/.*/" ]
# only allow devices setup in the device-mapper
filter = [ "a/mapper/", "r/.*/" ]
# startup commands for rc.d scripts
vgscan
vgchange -ay
# configuring a whole disk as a physical volume
pvcreate /dev/hdb
# configuring a single partition as a physical volume
pvcreate /dev/hdb1
fdisk /dev/hdb, toggle type of part 1 to 0x8e (linux lvm partition)
# creating a volumne group with the default extent size of 32m
vgcreate -s 32m my_volume_group /dev/hda1 /dev/hdb1 ...
# activating
vgchange -a y my_volume_group
#deactivate, and remove a volume group
# note the sequence: unmount, mark lv as unavailable, make vg as unavailable
umount /dev/my_volume_group/lv1
umount /dev/my_volume_group/lv2
...
lvchange -a n /dev/my_volume_group/my_logical_volume
(repeat for all logical volumes in volume group)
vgchange -a n my_volume_group
vgremove my_volume_group
# adding physical volumes to a volume group
vgextend my_volume_group /dev/hdc1
# removing a physical volume from a volume group
pvdisplay /dev/hda1
vgreduce my_volume_group /dev/hda1
# creating a logical volume
# use these commands to decide which physical volumes you want the logical volume
# to be allocated on
vgdisplay
pvdisplay
# this makes a 1500MB linear LV named 'testlv' with block device /dev/testvg/testlv
lvcreate -L1500 -ntestlv testvg
# remove it
lvremove /dev/testvg/testlv
# extend it
lvextend -L12G /dev/testvg/testlv
# reduce it
lvreduce
# removing a logical volume from a VG
# I usually have to reboot before doing this since there seems to be more
# to deactivating a volume group than unmounting all of its logical
# volumes.
# when you deactivate a volume group, the directory
# /dev/testvg
# disappears. You still refer to the logical volume by that name, however,
# in the lvremove command.
vgchange -a n testvg
lvremove /dev/vgtestvg/testlv
vgchange -a y testvg
# adding and removing PV to a VG
# move PE's off of /dev/hda1 (and onto the rest of the VG's PV's)
pvmove /dev/hda1
# remove PV from VG
vgreduce my_vg /dev/hda1
# add new PV to VG
vgextend my_vg /dev/hdb1
# move PE's from one PV to another (specific PV)
pvmove /dev/hda1 /dev/hdb1
# renaming
# we deactivate vg00, rename it to vg01, then reactivate it
vgchange -a n /dev/vg00
vgrename /dev/vg00 /dev/vg01
vgchange -a y /dev/vg01
# lvm metadata
# is important to make backups of in case power goes out during
# certain types of operations like pvmove, where the metadata could be left in
# an inconsistent state.
#
# this writes the lvm metadata to /etc/lvmconf/vg01.conf and copies it to /boot
vgcfgbackup -v vg01
cp /etc/lvmconf/vg01.conf /boot
# this restores the lvm metadata from our copy stored in /boot
vcfgrestore -f /boot/vg01.conf
# commands at a glance
vgchange lvchange
pvcreate pvdisplay pvmove pvscan
vgcreate vgremove vgrename vgextend vgreduce vgchange vgscan
lvcreate lvremove lvrename lvextend lvreduce
vgcfgbackup vgcfgrestore
# creating a lvm based root partition
# this creates the initrd file /boot/initrd-lvm-2.4.20.gz, if you were running
# linux 2.4.20 when you ran it, that is.
lvmcreate_initrd
# this allows you to specify a kernal version that is installed but not running
# in this case, kernel 2.4.26
lvmcreate_initrd -v 2.4.26
# continue with vg, lv, and filesystem creation
pvcreate /dev/hdb5
vgcreate /dev/vg00 /dev/db5
lvcreate -L3690 -n lv_root vg00
mkreiserfs /dev/vg00/lv_root
# stick slackware on it
# the last step is very important since it creates shared library links and you won't
# be able to boot from such a partition until you have run ldconfig
mkdir /mnt/lv_root; mount /dev/vg00/lv_root /mnt/lv_root
installpkg -root /mnt/lv_root pkg1.tgz pkg2.tgz ...
chroot /mnt/lvroot /sbin/ldconfig
# create a lilo.conf that looks like this:
boot = /dev/hda
image = /boot/vmlinuz-ide-2.4.20
initrd = /boot/initrd-lvm-2.4.20.gz
root = /dev/vg00/lv_root
label = rootonlv
append = "ramdisk_size=8192"
# the ramdisk_size needs to be at least as large as lvmcreate_initrd reports
# you don't need to copy lilo.conf to /mnt/lv_root. Whatever directory on whatever
# filesystem you are running from, create lilo.conf there and invoke lilo like this:
lilo -C ./lilo.conf
# now create an fstab like this and copy it to lv_root
none /dev/pts devpts gid=5,mode=620 0 0
none /proc proc defaults 0 0
/dev/vg00/root_lv / reiserfs defaults 1 1
/dev/hda1 /boot ext2 defaults 1 2
# the copy command would be
cp fstab /mnt/lv_root/etc/fstab
