Excluding devices for LVM
Imagine this virtualization situation: Your host server uses LVM, and you decide that each of your virtual servers will get a logical volume as the storage backend. At the same time, you want to use logical volumes in the virtual servers as well. Henceforth, you are using LVM in an LVM environment. Therefore, when your virtual machine boots, it won't be able to initialize the logical volumes, as it complains about the devices already being used.
The above scenario occurs because you didn't exclude your LVM devices from being scanned for logical volumes when the host server boots up. Therefore, the host server will find LVM volumes within the LVM volumes and activate them. This means that the virtual server, when attempting to use these volumes, finds them already in use. The solution is to exclude these logical volumes from being scanned.
To exclude LVM devices, you have to modify the LVM configuration file
/etc/lvm/lvm.conf. Listing 1 gives an overview of some of the sample lines that you can use to exclude devices:
Listing 1: Example lines to exclude devices from lvm.conf
# By default we accept every block device:
filter = [ "a/.*/" ]
# Exclude the cdrom drive
# filter = [ "r|/dev/cdrom|" ]
# When testing I like to work with just loopback devices:
# filter = [ "a/loop/", "r/.*/" ]
# Or maybe all loops and ide drives except hdc:
# filter =[ "a|loop|", "r|/dev/hdc|", "a|/dev/ide|", "r|.*|" ]
As you can see, the filter statement is used to include, as well as to exclude, devices. All devices that you want to include start with
a| and all devices that you want to exclude start with
r|. So if, for example, you want to make sure that your
/dev/drbd0 device is not scanned by pvscan, vgscan or lvscan while booting, include the following line somewhere in the configuration file:
filter = [ "r|/dev/drbd0" ]
This would work for any other device, as well. After that, restart your server to activate the new configuration. The newly mentioned devices are now excluded.
Personally, I don't like all the comment lines that you'll typically find in the
/etc/lvm/lvm.conf file. They tend to clutter up the file and obscure important information, such as which devices you want to allow and which devices you want to deny in the LVM setup. I'd recommend removing all comment lines so that you have an easy-to-read configuration file. That way, it'll be easy to filter out any mistakes that you've accidentally made.
A device is not activated automatically
There are also situations where all logical volumes are discovered, but they remain inactive. If that happens to you, you can use lvchange to change their state to active:
lvchange -a y /dev/system/srv
This command changes the state of the volume from inactive to active. In some cases, however, this doesn't work. I've seen a snapshot volume, linked to the original volume, that was filled up and then automatically deactivated. You would think this was a good thing, as it couldn't do any harm that way, but deactivating the snapshot also deactivates the original volume. If the original is deactivated via the snapshot, there is no way to get it up again with lvchange. In that case, you would have to remove the snapshot with the lvremove command:
Once the snapshot volume has been removed properly, you can change the state of the original volume back to active.
When working with snapshots, remember that they are for temporary use only. Remove them immediately if you don't need them anymore.
This was first published in September 2009