Showing posts with label migrate. Show all posts
Showing posts with label migrate. Show all posts

Friday, 16 December 2011

Converting a Debian VM from Xenserver to vSphere

You can transfer the data for the machine from one environment to another using clonezilla. Once it is transferred I found that the machine does not boot. On further investigation I realised that there are many differences between a Debian install on Xenserver and on vSphere.

If you get the message "Operating system not found" you will need to install grub to the virtual hard disk. To do this boot a liveCD (such as clonezilla).

As root run grub, at the grub> prompt type:

grub> find /boot/grub/stage1

This will return the location of grubs stage one, make a note of this location for the next command. Type

grub> root (hd0,0) < this is the location returned by the last command

Now install grub to the master boot record (MBR) with:

grub> setup (hd0)

then quit grub with:

grub> quit

Reboot to get the grub menu but if you let it try and continue using the default settings it will very likely hang because it will try to use a block device name that begins with xvd, these are xenserver specific and will not exist on the VMware VM. To get it to continue booting you need to hit 'e' on the grub selection screen, then edit the boot line to replace the device that looks like /dev/xvda1 and made it look like /dev/sda1, also remove the "console=hvc0" otherwise you will not be able to see interact with your OS via the console (hvc0 is another xenserver specific device name).

Once we have booted the system we need to go about preparing the system to boot correctly when left to it's own devices (geddit?), firstly ensure the keyboard keymap is set up correctly with:

# dpkg-reconfigure console-data

Edit /etc/fstab to change all references to xvd devices to sda in /etc/fstab

On many of the machines I transferred using this method I found that they had no swap partitions after the transfer. So I simply set the disk size slightly bigger than the source disk when initially creating the VM in vSphere, then added a partition with fdisk. I usually set the swap partition as /dev/sda2.
You then need to make that partition a swap partition with (I have found often that a reboot is required before the command works):

# mkswap /dev/sda2

Then you can mount it with:

# swapon /dev/sda2

And see if the swap space is available with:

# free

Don't forget to update /etc/fstab so it is pointing to the correct device for the swap partition so it is automounted at boot.

The CDRom is set to /dev/hdc unless you have changed the VM's hardware settings, update this in /etc/fstab as well.

We need to change grubs configuration so that it automatically boots a with appropriate parameters, this information is stored in /boot/grub/menu.list. You can achieve this by either running the following commands:

sed -i 's/xvd/sd/g' /boot/grub/menu.lst
sed -i 's/console=hvc0//g' /boot/grub/menu.lst

Or edit  /boot/grub/menu.lst, find the line that begins # kopt, remove the console=hvc0 from the end and change the "xvd" device to the correct boot device. move down to the botton where the menu choices are configured and change the device and remove the console=hvc0 from each of the one you will likely use (the top one only in my case).

Edit /etc/inittab and comment out the line that begins "co:"

Remove the xenserver specific packages from your apt sources list with:

rm /etc/apt/sources.list.d/citrix.list

Update your packages list:

apt-get update

Remove all the kernels that are installed with:

apt-get remove linux-image*

You will get a warning asking about the removal of the running linux kernel, say "No" to this as we will install another one that we can get headers for in the next step.

Install a more appropriate kernel with:

apt-get install linux-image-2.6-686

Reboot to run the newly installed kernel.

Install VMware tools, details of how in my post here, then reboot to test.

To get the most out of the VM you should switch hardware to paravirutal drivers for SCSI controllers and NICs.


Thursday, 15 December 2011

Convert a Windows machine to a VMware VM with Clonezilla

I have had need to do manual conversions of physical and virtual machines for several reasons previously. Some of these reasons have included:
  • There is not enough free space on the machine's disk(s), (also know as "I haven't got time to wait for the machine's administrator to tidy up")
  • VMware Convert no longer supports the conversion of that operating system.
  • We can't afford PlateSpin
  • I wonder if I could do a conversion the hard way.
This takes me back to my first ESX Project. The company I worked for had about 8 test machines sitting along one office wall. The situation was already out of hand and I was being asked for more test machines. I decided we needed a to think big and decided on and got approved ESX on a couple of big (at least for us) servers to virtualise the test environment. I managed to simply move all the test machines by installing a fresh OS and installing and configuring all the software my self, with the help of the relevant departments. I then came to our Windows NT 4.0 software build machine.... No-one, not even the developer that put it together knew what was on there. We were building releases every couple of weeks at the time. It goes without saying this is not a good place to be, and baring a complete hardware failure on the physical machine there was no way anyone was going to be rebuilding the machine. I scratched my head and had previously used dd and tar to move installs from one machine to another on Linux, so I had a crack at it, and to my surprise a few hours later I had run a P2V by hand with a Linux live CD. I had even managed convince Windows NT to let me switch the drives from IDE to SCSI.

Having used Clonezilla to store a few images from machines that were shipped without restore media in the past, I wondered how easy it would be to back up an image of a machine and restore it into a new virtual environment. As it turns out with Clonezilla I don't even need to create an image, the tools are there to transfer the data from one machine's disk and write it directly to the disk of another.

The conversion here is from a Xenserver VM to a VMware VM but the technique used here will probably work else where. 
  • Put a Clonezilla live CD in both your (virtual) machines and boot them.
  • The default boot option for Clonezilla worked fine for me on both machines, your mileage may vary.
  • Select your language options as necessary
On the source machine:
  • Select "Start_Clonezilla"
  • Select "device-device"
  • Select "Beginner"
  • Select "disk_to_remote_disk"
  • Select "dhcp" or assign an IP address with "static"
  • Now it should show you a list of disks in the system, select the one you wish to transfer.
  • Select "Skip checking/repairing source file system" 
  • Clonezilla will now show you the command it is about to run, press "Enter."
  • You will be asked to confirm at a few important stages that you wish to proceed.
  • When you see "Waiting for the target machine to connect..." you have finished with the source machine for now, except take a note of the commands it is telling you run on the destination machine (See below image.)
On the destination machine:
  • Select "Enter_shell"
  • Select (2)
  • Type: sudo su - (to change to the root user)
  • Type: ocs-live-netcfg (and setup the networking)
  • Type: ocs-onthefly -s 192.168.1.1 -t sda  (replacing 192.168.1.1 and sda with the relevant IP address and device name)
  • You will again be asked to confirm at poignant stages.
You should see a progress bar which includes an estimate for the finish time.


When this finishes you should now be able to boot the destination VM and install the VMWare tools to make everything pretty and efficient. Don't forget to install the paravirtual SCSI and network card drivers if your OS is supported.


If you have success (or failure) with this migration method please leave a comment below, it certainly helped me out of a hole.