The following commands may be useful if you need to copy some files (SSH keys perhaps) to or from a VM disk image. This assumes the QEMU VM environment, which is the one that's built in to Ubuntu Server 10.04 Linux. You need to be root, of course.
It will only work safely for VM's that aren't running at the time!
-- Shut down our VM guest...# virsh shutdown vm2Domain vm2 is being shutdown
-- Load the required kernel module...# lsmod | grep nbd# modprobe nbd max-part=63# lsmod | grep nbdnbd 9903 0
I believe there's a command to take a snapshot of a running VM, but I haven't tested that myself. "virsh snapshot-create VMname" apparently needs libvirt >= 0.8.1, but Ubuntu Server 10.04 LTS currently only runs libvirt 0.7.5. I guess the LTS releases of Ubuntu Server must be a bit conservative, as they have five years of support, all free of charge.
-- Export the VM image file on /dev/nbd0, then mount that to a temp folder# qemu-nbd -c /dev/nbd0 vm2.img# ls -l /dev/nbd0*brw-rw---- 1 root disk 43, 0 2011-06-01 15:42 /dev/nbd0brw-rw---- 1 root disk 43, 1 2011-06-01 15:42 /dev/nbd0p1brw-rw---- 1 root disk 43, 2 2011-06-01 15:42 /dev/nbd0p2brw-rw---- 1 root disk 43, 5 2011-06-01 15:42 /dev/nbd0p5# mount /dev/nbd0p1 /mnt/vm2
-- You can now access the VM disk folders under /mnt/vm2...... do your stuff ...
-- To clean up...# umount /mnt/vm2# qemu-nbd -d /dev/nbd0/dev/nbd0 disconnected# rmmod nbd# virsh start vm2Domain vm2 started
No comments:
Post a Comment
Spammers: please stop wasting my time. All comments are moderated before publication.