Notes‎ > ‎

LVM

Logical Volume Manager

Logical Volume Layers:
pv (pysical volume)
vg (volume group)
lv (logical volume)

Useful commands:
fdisk -l
vgchange -a y <vg>

pvscan
vgscan
lvscan

pvcreate /dev/sda1 /sdb1 …
pvdisplay
pvremove /dev/sda1 /sdb1 …

vgcreate vg_01 /dev/sda1 /dev/sdb1 …
vgdisplay
vgrename vg_01 data

note) if the total lv is less than 50%, we can apply RAID1

lvcreate -l 100%FREE -n lv_share vg_data
or
lvcreate –name share –size 40G vg_01
lvcreate –name media –size 10G vg_01
lvdisplay
lvrename media film or lvrename vg_01 media film
lvremove /dev/vg_01/film
lvextend -L50G /dev/vg_01/share
lvreduce -L1G /dev/vg_01/share

mkfs.ext3 /dev/vg_01/share

note) edit fstab to retain mount

mount /dev/vg_01/share /var/share

note) all those commands are fine and dandy, but now for the maintenance like resizing logical volumes that are in use.

extend:
umount logical volume from filesystem
lvextend share as shown above
resize the filesystem to match the LVs size resize2fs -p /dev/vg_01/share
now we resize the ext3 filesystem on the logical volume e2fsck -f /dev/vg_01/share
now mount the logical volume

reduce:
again umount as above
now you reduce the ext3 filesystem first resize2fs /dev/vg_01/share <active_size>
reduce the logical volume lvreduce /dev/vg_01/share -L<active_size>
mount

snapshots:
lvcreate --size 128m --snapshot --name snap0 --verbose /dev/vg_data/lv_datastore
dmsetup remove /dev/vg_data/snap0
lvremove /dev/vg_data/snap0

troubleshoot:
when lvremove fails with 'Can’t remove open logical volume “/dev/vg_data/lv_datastore_snap”'
dmsetup info -c /dev/vg_data/lv_datastore_snap
dmsetup remove /dev/vg_data/lv_datastore_snap

[References]
http://www.howtoforge.com/linux_lvm
Comments