1. Introduction
First of all.
HAVE A BACKUP OF YOUR DATA!
There are some chances to destroy them.
I've decided to migrate completely to Linux and run still needed Windows installations only in VirtualBox. So I have to convert my Windows Installations to Virtual Disk Images and manage these VDIs, e.g. increase, decrease or change their type from dynamically expanding to fixed-size etc. I have summarized my experience and information to this here in the hope it may also be helpful for others.
In my examples below I use a Debian etch host system with Windows XP as guest, so Ubuntu should also work direct with them. But with another environment please adapt them to your needs.
First solutions I have posted here:
modify a VDI http://forums.virtualbox.org/viewtopic.php?t=364
import native WinXP http://forums.virtualbox.org/viewtopic.php?t=1404
Here is another solution from rcman80:
http://forums.virtualbox.org/viewtopic.php?t=1878
litemotiv describes another way with HDClone (freeware 4mb) on this topic page 2:
http://forums.virtualbox.org/viewtopic.php?t=585
Aaron_Mason describes an interesting way to convert from vmware to VirtualBox with rsync:
http://forums.virtualbox.org/viewtopic.php?t=3808
This howto http://www.virtualbox.org/wiki/Migrate_Windows assumes that we already have an image.vdi but don't declare how to get it.
Many thanks to QBikal for his excellent work to the internals of a virtual disk image!
http://forums.virtualbox.org/viewtopic.php?t=52
I've tried to use
with documentation at http://www.virtualbox.org/ticket/696.VBoxManage convertdd <filename> <outputfile>
VBoxManage convertdd stdin <outputfile> <bytes>
I do this:
- Code: Select all Expand viewCollapse view
$ VBoxManage convertdd raw.img .VirtualBox/VDI/MyImage.fix.vdi
VirtualBox Command Line Management Interface Version 1.5.0
(C) 2005-2007 innotek GmbH
All rights reserved.
Converting VDI: from DD image file="/home/ingo/raw.img" to file=".VirtualBox/VDI/MyImage.fix.vdi"...
Creating fixed image with size 10010165760Bytes (9547MB)...
$
- Code: Select all Expand viewCollapse view
C:\Documents and Settings\Ingo>dir D:
The volume does not contain a recognized file system.
Please make sure that all required file system drivers are loaded and that the volume is not corrupted.
C:\Documents and Settings\Ingo>
2. Abstract
Independent of the current used operating systems you should be able to adapt my examples below to your needs if you understand the general procedure.
1. Do everything with the target operating system, e.g. partition and format virtual disks, copy data etc.
2. attach the source disks and the target disks as second and third passive devices to your managing virtual machine. So it is ensured that there are no files in access.
3. Modify a Virtual Disk Image
This is the basic procedure. You copy all data from the old VDI to a new one and use that instead of the old one. Dependent on how you create the new one (bigger, smaler, new type) you can increase, decrease or modify the type of the VDI.
1. have a managing WinXP virtual machine
2. create a new VDI of the size and type you want
3. detach your working VDI from your working VM
4. attach your working VDI to the managing VM as primary slave
5. attach the new (modified) VDI to the managing VM as secondary slave
6. start the managing VM
7. partition and format the target drive F: (the new modified one!)
8. don't forget to set it active (set boot flag) in the disk manager if you want to boot from it later
9. to really copy all flags and whistles I use
- Code: Select all Expand viewCollapse view
xcopy D:\ F:\ /s /e /c /g /h /k /o /x /y >xcopy.log 2>&1
10. shut down the managing VM
11. detach the new (modified) VDI from the managing VM
12. attach the new (modified) VDI to your working VM as primary master
13. start your working VM with the modified virtual disk
that's it and only some clicks except the boring wait for xcopy.
4. Import a native installation from a physical disk partition
The trick is to access the physical disk partition in the managing VM through raw hard disk access and copy that data into a virtual disk image.
1. have a managing WinXP virtual machine
2. create a writethrough virtual disk for the physical partition. You must be a member of the group disk (there are NO line breaks!)
- Code: Select all Expand viewCollapse view
VBoxManage internalcommands createrawvmdk -filename .VirtualBox/VDI/WinXPraw.vmdk -rawdisk /dev/hd[a..z] -partitions [1..9] -relative
Warning: Raw hard disk access is for expert users only. Incorrect use or use of an outdated con?guration can lead to total loss of data on the physical disk. Most importantly, do not attempt to boot the partition with the currently running host operating system in a guest. This will lead to severe data corruption.
3. create a target disk image that can hold all stored files from the physical partition
4. attach the physical disk as primary slave
5. attach the target disk image as secondary slave
follow step 6. to 11. from section 3.
12. create a new VM with the coppied virtual drive as primary master
13. mount the Windows Setup CD
14. repair your copy, see http://www.virtualbox.org/wiki/Migrate_Windows
that's it and should always work as long as repair does it.
5. Import a native installation from a raw disk image
This is a little bit sophisticated because we can't access the raw image directly in a virtual machine to copy its data into a VDI. A raw disk image is something like made with dd, e.g.
- Code: Select all Expand viewCollapse view
$ sudo dd if=/dev/hda1 of=raw.img
1. have a managing WinXP virtual machine
2. Have the raw image
3. Create a fixed-size virtual disk image a little bit greater than your raw image (e.g. raw image = 10 GB, vdi = 11 GB). For further use it is important to use fixed-size!
4. Attach this new empty VDI to the managing machine as primary slave
5. start the managing VM
6. partition and format the fixed-size drive D: (the empty one!)
7. don't forget to set it active (set boot flag) in the disk manager if you want to boot from it later
8. shut down the managing VM
9. Grep the magic string "eb 52 90 4e 54 46 53" (= ".R.NTFS") with hexdump from the first MB of the VDI to get the offset the raw data starts at. The cryptic options for hexdump are only to get the offset in decimal and not in default hex (there are NO line breaks!).
- Code: Select all Expand viewCollapse view
$ hexdump -n 1000000 -e '"%08.8_ad " 16/1 "%02x " "\n"' ".VirtualBox/VDI/MyImage.fix.vdi" | grep "eb 52 90 4e 54 46 53"
- Code: Select all Expand viewCollapse view
00077824 eb 52 90 4e 54 46 53 20 20 20 20 00 02 08 00 00
10. Copy your raw image into the VDI at the found offset. This only works with a fixed-size virtual disk image! (there are NO line breaks!)
- Code: Select all Expand viewCollapse view
$ dd if=raw.img of=.VirtualBox/VDI/MyImage.fix.vdi obs=77824 seek=1
11. Create a working virtual disk image that can hold all data of your raw image. It can be a dynamically expanding image and you can choose a size of your need. It must not be the same size as your raw image.
12. Attach this working VDI to the managing machine as Secondary Slave.
13. Boot into the managing machine and check if the fixed VDI shows the copied data. You should do any check/repair actions on it. For this example I do:
- Code: Select all Expand viewCollapse view
chkdsk D: /f
follow step 7. to 11. from section 3.
follow step 12. to 14. from section 4.
That's it.
I have tried to repair the fixed-size VDI in the VM after step 10. above and boot it but with no success.
- Code: Select all Expand viewCollapse view
C:\Documents and Settings\Ingo>diskpart.exe
Microsoft DiskPart version 5.1.3565
Copyright (C) 1999-2003 Microsoft Corporation.
On computer: MyVM
DISKPART> select volume 2
Volume 2 is the selected volume.
DISKPART> extend
DiskPart failed to extend the volume.
Please make sure the volume is valid for extending.
DISKPART> exit
C:\Documents and Settings\Ingo>
Hope I haven't made a mistake in my description. For me it works.