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/dbmasterkpartx -av /dev/vol1/ss_dbmastervgscanlvscan inactive '/dev/VolGroup00/LogVol00' [61.84 GB] inherit inactive '/dev/VolGroup00/LogVol01' [2.00 GB] inheritlvchange -ay /dev/VolGroup00/LogVol00lvscan ACTIVE '/dev/VolGroup00/LogVol00' [61.84 GB] inheritmount -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 :)
As I understand you, you take the snapshot from dom0, right? Why did you do this? As far as I understand the inner yards of LVM, this way it is not guaranteed that the snapshotted FS is in a consistent state. The domU FS doesn't know that the snapshot is taken. If you have taken the snapshot from within domU, the fs is aware of the snapshot and brings everthing into a consistent state.
ReplyDeleteThat's the reason why most of the backup procedurece concerning xen found in the web are broken - they pause the domU and then they snapshot the LVM from within dom0. TO have a complete and guaranteed working backup you need the memory image of the paused domU too. Not so if you snapshot from within domU.
Thanks Matt - the nested lvm mount was just what I needed!
ReplyDeleteJames