I have an OpenSuse server that runs some services (including Apache web server, mailing list, etc.). Now I need to move all these service to a virtual machine (Virtualbox could run on the same physical machine or somewhere else).

It's ideal if I can "copy" everything to the VM so that the VM will work exactly as the original machine runs. All the user's data (/home/*) is stored in an NFS, that should not be transfer to VM. Then I can have a relatively small (several Gigabyte) VM image so it could be backed up every several days.

I need all the system and application settings be moved to the VM, so I can switch to use the VM smoothly.

Is there any tool or something can do this simply? If not, how should I do this?

migrated from stackoverflow.com Oct 24 '11 at 22:20

This question came from our site for professional and enthusiast programmers.

  • 1
    You could try taking an image of the server's drive and convert it to whatever the VM is expecting for an image format. it might even boot. or it might not. depends on how nice suse is about having its hardware changed out from under it. – Marc B Oct 24 '11 at 21:37

You can do this with dd pretty straight forward.

dd if=/dev/you-root of=/mnt/temp/filesystem.raw bs=1M

Now you're able to convert this raw file into any needed container with qemu-img. Or even let the VM use a block device and copy it to a logical volume. For VirtualBox it would be vdi.

qemu-img convert -O vdi /mnt/temp/filesystem.raw /mnt/temp/filesystem.vdi

You could technically use Rsync for this:

Boot a live CD on the VM, and partition the disk to taste, then mount "/" as /mnt/rootfs/ and run the following from the VM:

rsync -aHAXz root@OLD-SERVER:/ --exclude=/sys/* --exclude=/proc/* --exclude=/dev/* /mnt/rootfs/

-a = archive mode; equals -rlptgoD (no -H,-A,-X)
-H = preserve hard links
-A = preserve ACLs (implies --perms)
-X = preserve extended attributes
-z = compress file data during the transfer

Then fix GRUB, /etc/fstab, etc...

Assuming your "OLD-SERVER" has SSH access, this would (mostly) work...

I've used this method before to clone physical machines...

  • +1 for creativity, although I have reservations about it being a practical solution. – John Gardeniers Oct 25 '11 at 0:21
  • 2
    Many applications do not react well top copying in-use files. If you do choose to use this I strongly suggest you stop any services, especially database engines on the old machine before running the sync. BTW, I have used this method many times. – Zoredache Oct 25 '11 at 0:33

I make this kind of tasks with 'dd' command. But they are commercial solutions like Ghost to do this and open source solutions like Clonezilla, partimage. Move a host from a box to a VM is like move a host from a box to a new one box.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.