When you need to convert a CentOS machine into a Virtual Machine on XenServer, you may find you’re out of luck. I know I did, as I scoured the internet for a solution and never quite found one.
What you need:
1. A physical machine with linux installed. In this case we will use CentOS 5.
2. A XenServer Host which you can make a VM on.
3. Network connectivity between the two.
4. Root access to both machines.
Physical access to the physical machine is not needed if the steps are done correctly.
1. First on the physical server run the command:
What you are looking for here is any directories which are mounted from other devices, NFS mounts, etc. Anything not local to the disk. Keep track of the paths you find.
2. Next you will need to make sure that when you start runlevel 1, your networking and sshd will come up. In many cases running init 1 from another runlevel will preserve these. Better safe than sorry.
# chkconfig –level 1 sshd on
# chkconfig –level 1 network on
On debian systems or other linux systems you may need to do other commands instead. If in doubt you could probably get away with:
# echo /etc/init.d/network start >> /root/.bashrc
# echo /etc/init.d/sshd start >> /root/.bashrc
Or where ever your sshd and network daemons are located.
3. Next you need to go into runlevel 1 on the physical machine (beginning of down time for some, many or all services):
# init 1
4. After this is done, get back into the box if you were disconnected.
5. Now on the XenServer Host you need to create a VM. What I did which was successful was I made a VM with the exact same version of linux you are trying to migrate.
6. After installing the VM, enter it into runlevel 1 as well:
# init 1
7. rsync the physical server to the virtual server, by issuing this command. Each of the directories you may have found which are non-local filesystems will need an exclude. On the VM run:
# rsync -av –numeric-ids –delete –progress –exclude /sys –exclude /boot –exclude /dev –exclude /proc –exclude /etc/mtab –exclude /etc/fstab –exclude /etc/udev/rules.d –exclude /lib/modules physical-server-ip-or-hostname:/ /
8. Shut the physical box down:
# init 0
9. If you are planning on using both the VM and the physical machine, change the IP settings on the VM to the new ones:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
# vi /etc/hosts
# vi /etc/sysconfig/network
10. Remember to change IP settings on things like mysql user permissions, http.conf, conf.d/* files, etc.
11. Reboot the VM:
# init 6