LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Transferring virtual Linux install to physical drive (https://www.linuxquestions.org/questions/linux-software-2/transferring-virtual-linux-install-to-physical-drive-704805/)

Mark_667 02-15-2009 07:49 AM

Transferring virtual Linux install to physical drive
 
I have a Linux installation inside a VirtualBox VM (VDI file) that I would like to transfer to a physical hard disk. What would be the best way to do this? Could I mount the physical hard drive as a shared folder and use the dd command (booting the VM from a LiveCD) to transfer it? Note, both the VDI and the physical drive are the same size. Any ideas/advice would be appreciated.

Tinkster 02-15-2009 01:24 PM

The problem with the mounting is that you normally use dd on a raw-device,
not on a file-system. For the transfer you could use dd & netcat, or tar &
netcat ....

Mark_667 02-16-2009 11:03 AM

How would you use netcat to help do this? Also, what about allowing raw disk access to the destination volume? Potentially dangerous-I know but would it work better? Are there any other ways anyone would recommend?

Tinkster 02-16-2009 12:46 PM

That (raw device) is exactly what you'd be doing with netcat and dd ...

E.g.
http://www.rajeevnet.com/hacks_hints...s_cloning.html
for a how-to (there's heaps - search google for "netcat dd clone").

Cheers,
Tink

CJS 02-16-2009 03:48 PM

Note this method will only work if you have a static .vdi VirtualBox drive image; if you are using a dynamic .vdi drive, I'm still in the process of figuring out how to mount them. But if you happen to have a static .vdi drive, I think probably the easiest way to transfer your VirtualBox OS to a partition would be to mount it, and then copy its entire file system to its new partition with "cp -ax" to preserve all the proper permissions/ownerships of all files. Most VirtualBox .vdi files just have 3 sectors of VirtualBox header info at the beginning, and then the rest is the HDD image. So to mount a static .vdi file, you can usually do:
Code:

losetup -f --show -o $((512*3)) ~/.VirtualBox/HardDisks/HDD_image.vdi
That will also return the loop device that the .vdi file gets associated with, for example "/dev/loop0". And then to see the partitions in that image:
Code:

fdisk -lu /dev/loop0
Using the above command, find the sector offset of the partition you want to mount, say for example the starting sector is 63, then do:
Code:

mount -o loop,offset=$((512*63)) /dev/loop0 /mnt
And that will mount your VirtualBox OS partition on /mnt. After that, it's just a matter of copying the file system to its new partition:
Code:

cp -ax /mnt/* /path_to_mounted_destination_partition/
And lastly, if you do:
Code:

blkid -c /dev/null
It will show you the UUID of your mounted VirtualBox partition, and you can transfer that UUID to the new partition with:
Code:

tune2fs -U <VirtualBox partition UUID> /dev/<new partition device>
You will probably have to modify /boot/grub/menu.lst and possibly /etc/fstab for the OS on the new partition, but that should be about all it takes. Let me know if you decide to give this method a try and how it goes.


All times are GMT -5. The time now is 08:57 PM.