[libvirt-users] Suggestions on building VM disks from scratch

This may not be the best forum to ask, but it does seem to be one where it is as likely as anywhere that someone will have dealt with a similar problem. I need to define a procedure for last resort disaster recovery from an incremental file level backup of the root partition (and any others that are critical.) Now it is easy enough to create a raw virtual disk with dd, then to losetup and do a cfdisk and mkfs, then mount it and rsync the backup onto it. At this point I would like to be able to install grub and make the virtual disk bootable. I have 'issues' with the way grub does things and the way it seems to make certain assumptions for you. The virtual disk is in actuality going to become an hd(0) on the virtual machine; but my past experience with grub is that it is going to assume you really intend to install the MBR on your running system disk; but if you tell it hd(1) then when you try to boot it ain't gonna work. Has anyone dealt with these issues? It's more than just a VM one; I run up against it time and again. A few months ago I attempted to attach a brand new SATA disk via a USB converter to my laptop so I could build a system on it for a machine that has not CD, no floppy, etc, etc. I damn near clobbered my laptop but fortunately caught the problem in time and fixed it before a reboot... in which case I'd have *really* had issues.

Here's how far I've progressed this evening: $ dd if=/dev/zero of=/recover2.my.net.raw count=20M $ losetup /dev/loop0 recover2.my.net.raw $ cfdisk /dev/loop0 create a 9G bootable linux partition and a 1G swap $ kpartx -a -v /dev/loop0 $ mkfs.ext4 /dev/mapper/loop0p1 -m 0.01 -L "RecoverTest" $ mkdir tmp $ mount /dev/mapper/loop0p1 tmp
From the backup server:
$ rsync -av tree/ root@vmserver.my.com:/srv/pool/tmp/ $ umount tmp $ kpartx -d /dev/loop0 $ losetup -d /dev/loop0 $ virsh attach-disk recovery.my.net --source /srv/pool/recover2.my.net.raw --target sdb But no joy from the running VM itself. It does not show sdb, only its own vda1. rescan-scsi-bus.sh fails to bring make /dev/sdb appear. Is the hotplugging failing perhaps? Suggestions?

On 03/31/2012 01:39 PM, Dale Amon wrote:
I need to define a procedure for last resort disaster recovery from an incremental file level backup of the root partition (and any others that are critical.)
Now it is easy enough to create a raw virtual disk with dd, then to losetup and do a cfdisk and mkfs, then mount it and rsync the backup onto it.
It sounds like you want to use the features of libguestfs, possibly via the command line program 'virt-rescue'; see http://libguestfs.org for more details about what this can let you do. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Sat, Mar 31, 2012 at 04:37:54PM -0600, Eric Blake wrote:
On 03/31/2012 01:39 PM, Dale Amon wrote:
I need to define a procedure for last resort disaster recovery from an incremental file level backup of the root partition (and any others that are critical.)
Now it is easy enough to create a raw virtual disk with dd, then to losetup and do a cfdisk and mkfs, then mount it and rsync the backup onto it.
It sounds like you want to use the features of libguestfs, possibly via the command line program 'virt-rescue'; see http://libguestfs.org for more details about what this can let you do.
It looks really nice. But not an easy fix. I'm at the moment crossing my fingers and running an update to pre-release Ubuntu Precise on my test box... I need to confer with another person before adding in the backports.org version to get it on our squeeze based production server. One does not do such things lightly on production boxes!

Eric: Perhaps you can help. I'm at the point of screaming frustration. First, I had to search for a machine on which I could install guestfish and virt-rescue. None of the production machines were safe for this as the closest I could come was either adding a backports line to an apt sources file on a squeeze machine or upgrading an Ubuntu machine to the not-yet-ready for prime time Precise. I finally realized one machine *was*, for strange hysterical reasons, already on the Precise release. So I selected the package. This took an hour or more because the not ready for prime time Precise wanted to remove diffutils and warned you that you should not. After a bunch of research I figured it would work, because a new one was coming in immediately... and it did. Mostly. It took about a dozen iterations to get everything settled again. Then I created my blank 'disk' file and tried to run virt-rescue on it. It crashed out with an error from febootstrap. After finding nothing terribly useful or current on this in searching, I tried guestfish instead. After some fiddling I got it to attach my blank disk. However I cannot find a reasonable way to partition it with the part-add which seems to want me to count sectors. All I want is a 9G linux and a 2G swap. It also lacks access to rsync. I'd hoped for something like Knoppix for VM's. So, I found the guy's web site in another google search. Wrote up a nice long explanation of what I need to do and what pointers he might have to get up the learning curve on his application or whether there was something better for my purpose... and when I hit the post button, Wordpress asked me to login. I did so. It then put me back on the same page with my long well thought out comment gone. I am trying seriously not to throw my laptop through a window at this point. Really. Have you worked at all with either? You pointed me to them a few days ago, so I'm hoping you have. All I want is to: create a blank disk (dd works fine) put a partition table on it create an X GB root linux partition and a Y GB swap do the mkfs and mkswap rsync a backup image onto the 9GB partition write the mbr from grub so that the disk is a bootable VM. boot it from virsh I've managed through a number of arcane commands to ge as far as the grub problem. Perhaps I can do everything manually and only use guestfish for the last step with the grub. It would be nice if there were a better way to do it. I am sure someone will pipe in "this is the wrong list". After the day I have had on this so far, with dead end after dead end, as Rhett Butler said to Scarlett: "Frankly m'am, I don't give a damn." Any one have some ideas? This really should be something that is easy to do.
participants (2)
-
Dale Amon
-
Eric Blake