Linux – Transfer a Linux server to virtual machine

linuxmigrationsettingsvirtual-machinesvirtualbox

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?

Best Answer

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