How to migrate a bare metal Linux installation to a virtual machine

Solution 1:

You're missing an important piece of information here - which virtualisation hypervisor?

If it's VMWare there are both free, limited and paid, more-powerful, P2V convertors available that can create VMs native to VMWare or to the .OVA open virtual machine format.

Others will know the P2V conversion options for Hyper-V/KVM/Xen etc. better than I.

Solution 2:

There's an unsupported script out that's published on a Red Hat URL. It basically is an ISO that boots from CD, sucks your network config from the HDD to get online, and then SCPs your filesystem to an awaiting host. It also sends a Xen config.

Works great. Once those files get transferred, you can fire them right up on your Xen server.

In a way this is safe, because you're doing read-only ops on your physical machine. But, if it's a production machine, the usual disclaimers apply. The only trouble I ran into was that I had to fiddle with the kernels so that I had *xen kernels on the new virtual machine instead of non-xen. That caused a bit of unexpected downtime but I wasn't working on a critical machine either.

This is definitely experimental, but it worked for me. If you have trouble, you can always fire the physical back up immediately.

PS: Be familiar with kpartx ahead of time, in case you need to get inside your disk images when they're not running.

http://people.redhat.com/~rjones/virt-p2v

Solution 3:

I wrote a step-by-step detailed answer of how I solved a very similar challenge on the question: Turning a running Linux system into a KVM instance on another machine. I hope it proves a useful answer for this question too.

Goal of the answer: to take a physical Linux P node running live-production and virtualise it. Without having to create and allocate multi terabyte disks, nor have to use md raid in the V guest, because the target hypervisor (Proxmox 5) used ZoL/ZFS. Also wanted to mitigate downtime/reboots on the running P node.