How to transfer your physical disk content to a virtual machine.

Create a image of the disk

There are several tools that we can use to create a clone of our disk, like clonezilla, g4l, or dd. This wiki will focus on dd but there maybe other simple and more efficient ways of doing this.

Assuming a full disk image with all the partitions:

Local storage:

dd if=/dev/<disk device> ( of=/dev/<external disk> | of=/tmp/disk_image.img ) bs=<block size> <other options if needed>

Remote storage:

dd if=/dev/<disk device> bs=16065b | nc <ip of the remote machine> <port>  => Source machine

nc -l <port> | ( dd of=/dev/<device> | dd of=/tmp/disk_image.img) bs=16065b => Target machine (Execute this one first)

If you can't use nc because of firewall, try the following method:

dd if=/dev/<disk device> | ssh root@<remote-machine> 'dd of=/tmp/<disk image>' bs=<block size>

To find out the disk structure use fdisk and df -h.

Variations of the commands are possible, like using gzip or bzip2 to compress the image or "zeroing" all the free space so it compresses to almost nothing. To find out more about dd use man dd

Ramdisk image

After the creation of the disk image you will probably need to build a custom ramdisk for the image. To do this we use the command mkinitrd on a xen machine.

Assuming that the image doesn't contain any vg partition (check with vgs), it is possible to create a working ramdisk image issuing this command...

mkinitrd --with=<module> | --omit-scsi-modules --omit-lvs-modules --omit-raid-modules  <ramdisk name> <kernel>
Important: You may need to adapt this to your particular image. To find out which modules you should put in the ramdisk check the modules that we were in the source pc with the command lsmod

Example:

mkinitrd -f --preload=xenblk --with=xenblk --with=ext3 --with=jbd --with=ata_piix --with=libata --with=e1000 --with=i2c_i801 --with=i2c_core --with=bridge --with=netloop --with=ipv6 --with=ip_tables --with=iptable_filter --with=loop  --omit-scsi-modules --omit-raid-modules --omit-lvm-modules initrd-2.6.18-53.1.19.slc4xen.1.img 2.6.18-53.1.19.slc4xen

Setup the configuration

Below is a possible configuration file to start the virtual machine...with your disk image

name = 'disk-rawimage'
ip = "some ip" #optional
kernel = '/boot/vmlinuz-2.6.18-53.1.19.slc4xen' # Dom0 kernel
ramdisk = '/boot/initrd-2.6.18-53.1.19.slc4xen.1.img' # created ramdisk
hostname = 'some hostname' #optional
memory = '256'
disk = [ 'file:<path to disk image>,xvda,w' ] #may need to replace file to tap:aio
vif = [ '' ]
gateway = 'some gateway' #optional
netmaks = 'put a netmask' #optional
root = "/dev/xvda2 ro" #Points to the root partition
#bootloader = '/usr/bin/pygrub' #Commented
on_reboot = 'restart'
on_crash = 'restart'
#extra = 'single init=/bin/bash' #Single mode

Boot the virtual machine

xm create <config file>

Add -c if you want to attach a console to the virtual machine.

Extras

None yet..to be updated

-- RicardoMendes - 27 May 2008

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r2 - 2008-05-27 - RicardoMendes
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Virtualization All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback