Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

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

3 Answers 3

up vote 3 down vote accepted

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
share|improve this answer

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...

share|improve this answer
    
+1 for creativity, although I have reservations about it being a practical solution. –  John Gardeniers Oct 25 '11 at 0:21
1  
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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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