I setup a xen based system for our production environment at work. I'm using LVM throughout for all the benefits it provides (resizing, snapshot backups, etc). Each domU gets its own logical volume on dom0's volume group. This logical volume actually looks like an entire physical disk to the domU, and the domU then further partitions it into a boot partition and a nested LVM partition (swap + root fs). Aren't the layers of unix file abstractions a thing of beauty to behold? :)

In retrospect I probably should have mapped LVM logical volumes direct from dom0 as partitions in domU rather than having domU add the extra LVM layer on top - though reading around shows that this _may_ not be supported in the future, so...Recently I completely horked our mysql db slave replica and needed to re-replicate the master to the db. Since our DB is ~ 60GB, I didn't want to shut down (read lock) our master DB for the length of time it would take to copy it over to the slave. The solution to this would be to use an LVM snapshot. This way I could read lock the master db, create the LVM snapshot (very quick - a few seconds at most), unlock the master, then copy the data from the snapshot to the slave at my leisure, letting standard db replication do the catch up later.

For those not in the know about DB repication, one has to make a copy of the master and record the position in its transaction log at that point in time - this way the slave can know where in the transaction log to start repicating from once it comes up with the copy of the data up to that point.

Ok, so, now knowing what I needed to do, I just needed to do it - not as easy as I thought it would be due to the extra layer of LVM.

Fortunately, googling around found me my solution, which I'm recording here for the next time I need to do it :)

Basically, the trick is two fold, frst we have to use kpartx to map the partitions from our virtual disk into partition devices in /dev. Then we have to tell LVM to rescan these devices to find our embedded LVM partition, and activate the logical volumes on there so that we can then mount them as regular filesystems.

lvcreate --size 1G --snapshot --name ss_dbmaster /dev/vol1/dbmaster

kpartx -av /dev/vol1/ss_dbmaster


lvscan inactive '/dev/VolGroup00/LogVol00'

[61.84 GB] inherit inactive '/dev/VolGroup00/LogVol01' [2.00 GB] inherit

lvchange -ay /dev/VolGroup00/LogVol00

lvscan ACTIVE '/dev/VolGroup00/LogVol00' [61.84 GB] inherit

mount -t ext3 /dev/VolGroup00/LogVol00 /tmp/dbmaster/

Lets hope I don't have to do that again anytime soon! I just think its cool how unix can have these layers of abstractions between files and partitions, with files in partitions and partitions in files :)