Let's first define de situation: We have one computer with windows 7 we want to migrate to our remote ubuntu server as a virtual machine. The server commands will be shown with this color while the to-be-migrated machine ones as this.
So first thing first, on our server let's create an empty image the size of our disk. I will use 500 GB as size, but you can use any size you want!
qemu-img create win7 500G
Then we need to mount this image as a hard drive, this can be made through qemu-nbd and it's kernel module. And don't forget to give your user the ownership of the newly created device.
sudo -i
modprobe nbd
qemu-nbd -c /dev/nbd0 win7
chown user /dev/nbd0
Now we have to go into our booted win7 machine. There we will clone the partition table.
dd if=/dev/sda count=2048 | ssh user@server 'dd of=/dev/nbd0'
Back in the server we have to remount the nbd drive for it to show the new partition layout. Note the asterisk on the chown command for it is of utmost importance.
sudo -i
qemu-nbd -d /dev/nbd0
qemu-nbd -c /dev/nbd0 win7
chown user /dev/nbd0*
Now and having all set up we can finally get to the real stuff and clone our data. Up to this point we created just an empty disk with absolute nothing but the partitions, we don't even have filesystems there. For this post's sake i will suppose that your windows install consist on only one partition, if you have many partitions you can choose witch to clone.
ntfsclone -sqo - /dev/sda1 | ssh -C user@server 'ntfsclone -r - -O /dev/nbd0p1'
Once we have everything copied we can turn off the computer go to our server and un mount the nbd device. And the image is ready to be used on any hipervisor.
sudo -i
qemu-nbd -d /dev/nbd0
And that's all of it! I hope you can make it at home and have fun ! This process was tested on windows server 2003 and 2008 witch are similar to xp and 7. Newer versions like 8 or 10 were not tested and might not work fine since those use a different partition schema.
Bye and i hope you liked it!
No hay comentarios:
Publicar un comentario