LVM

From Noah.org
Jump to navigationJump to search

See also LVM Howto


You can resize ext2/ext3 filesystems while mounted.

copy an LVM virtual machine partition

This was based on a Xen virtual machine system I manage.

#!/bin/sh
VG_NAME=$1
LV_NAME=$2
SSH_LOGIN=$3
LV_SIZE=$(lvs --noheadings -o lv_size /dev/${VG_NAME}/${LV_NAME})
ssh ${SSH_LOGIN} "lvcreate -L ${LV_SIZE} -n ${LV_NAME} ${VG_NAME}"
dd bs=1M if=/dev/${VG_NAME}/${LV_NAME} | ssh -C ${SSH_LOGIN} 'dd of=/dev/${VG_NAME}/${LV_NAME}'

For Xen, you will also want to copy the guest.cfg file.

scp /etc/xen/guest.cfg ${SSH_LOGIN}:/etc/xen/.

Remember

a Volume Group is the equivalent of a physical device

It can be made up of a collection of drives. You can add or remove drives from a VolGroup. Note that this isn't strictly correct. Parts of a drive can be part of different VolGroups.

a Logical Volume is the quivalent of a partition

Logical Volumes are mapped to a device in /dev. A LogVol is what you actually mount to a mount point.

Basic commands

  • vgdisplay -- display attributes of volume groups. See also `vga` for a more brief display.
  • pvdisplay -- display attributes of physical volumes. See also `pvs` for a more brief display. Use this to figure out how much physical space is available.
  • vgscan -- to identify your volume groups by name. example: VolGroup00
  • lvscan -- to identify your logical volumes by name. example: LogVol00 LogVol01 LogVol02 LogVol03 LogVol04
  • pvcreate -- Add a partition to a physical volume.
  • vgextend -- Add a partition to a volume_group.
  • df -- to see which device names are mapped to which Logical Volumes. The device name is what mount/umount/ext2online care about.
  • ext2online -- this resizes an online ext2 or ext3 filesystem. You do not have to umount it. If you don't have ext2online then your Linux is old. You will have to umount the device first; use ext2resize; then mount the device again.

Examples

list volume group names

vgs --noheadings -o vg_name

extend an ext3 partition to be 100GB

Say that you have some unallocated space that you want to give to /var. Use `vgs` too see how much unallocated space is free. If not enough space is free then you will have to shrink another logical volume or add more physical disk. Say that /var is mounted on device /dev/mapper/VolGroup00-LogVol04.

Use the following the determine how much free space you can extend to:

# vgdisplay

Look for the line " Free PE / Size".

Use the following commands:

lvextend -L100GB /dev/VolGroup00/LogVol04
ext2online /dev/mapper/VolGroup00-LogVol04

Device Mapper

What is this dm or mod-dm.ko thing? This is the very heart of LVM. See `man dmsetup` or visit Device-mapper Resource Page.

Sometimes while using partimage you might get this error:

/dev/dm inode doesn't exists.
Partimage can create it for you.
You can also use the manual mknod
command. Do you want this inode
to be created for you now ?

The solution is to create the /dev/dm node:

# mknod -m 644 /dev/dm b 240 0

Which device mapper device name maps to a LVM volume name?

It's annoying that LVM uses friendly symlink names under /dev/VolGroup00/ to work with. The Linux kernel only pays attention to the mapped device names which look like /dev/dm-* where * is a number. So if you run iostat you will see disk statistics for /dev/dm-*, but now you have to go through an extra step to get the logical volume name associated with the device mapper name.

The following works pretty well.

# dmsetup info /dev/dm-5
Name:              VolGroup00-LogVol03
State:             ACTIVE
Read Ahead:        256
Tables present:    LIVE
Open count:        0
Event number:      0
Major, minor:      252, 5
Number of targets: 1
UUID: LVM-EFlXU2iiHXvYuRhp9XfjtgnsorqguOyCB17SpCBqFkJtH9hbWf5ZgQ8krqiO4bWT

Something like this also works, but it is not very pretty.

ls -la /dev/VolGroup00/ | grep dm-5


Note that this won't work. This shows the device of the Volume Group for a logical volume.

lvs -o +devices