0

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?

John Gardeniers
  • 27,458
  • 12
  • 55
  • 109
Tony
  • 195
  • 1
  • 4
  • 10
  • 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 Answers3

4

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
dbanck
  • 403
  • 1
  • 3
  • 9
4

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

Soviero
  • 4,366
  • 8
  • 36
  • 60
  • +1 for creativity, although I have reservations about it being a practical solution. – John Gardeniers Oct 25 '11 at 00: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 00:33
1

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.

danihp
  • 131
  • 4