Convert VirtualDisk to PhysicalDisk

This is for discussing general topics about how to use VirtualBox.
socratis
Site Moderator
Posts: 27330
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Convert VirtualDisk to PhysicalDisk

Post by socratis »

mpack wrote:why go for a dumb imager when smart options such as Disk2VHD exist?
Because this works cross-platform. Not all of us are on Windows hosts. And I'm a whiskey/beer person... ;)

And I'm not questioning the drivers; that's a necessary step in every direction. I'm talking about the part where you need to "translate" a Physical Disk to a Virtual one. And the ease of use of that step, versus translating a Virtual Disk to a Physical one, that's orders of magnitude more difficult.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Convert VirtualDisk to PhysicalDisk

Post by mpack »

socratis wrote:
mpack wrote:why go for a dumb imager when smart options such as Disk2VHD exist?
Because this works cross-platform.
Not really. Sudo is not cross platform, but that's trivial. A bigger issue is the practically of doing a raw copy of a huge drive. You would create a 2TB image from a 2TB drive? If yes, then I'm guessing you don't do this a lot.
socratis wrote:And the ease of use of that step, versus translating a Virtual Disk to a Physical one, that's orders of magnitude more difficult.
Not really. It's your choice of tools that makes your work difficult, not the work itself. It's like you arbitrarily decided that you must knock in this nail using a slipper. In reality I can more easily boot a VM from a Macrium ISO than I can boot the physical PC! Then it's just a matter of imaging the virtual drive. These are mechanical steps, there's nothing difficult about it.

And hardware drivers may not be what you had in mind, but getting the OS to boot on the target platform is often the toughest part of the process: the part where the task is often abandoned. In documenting a P2V process this is the part you would concentrate on. You can't just say "image made, job done!".
socratis
Site Moderator
Posts: 27330
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Convert VirtualDisk to PhysicalDisk

Post by socratis »

mpack wrote:You would create a 2TB image from a 2TB drive? If yes, then I'm guessing you don't do this a lot.
If you have any other ideas, I'm all ears. And I hope that you aren't thinking about skipping the empty sectors, because if I'm not mistaken "convertfromraw" skips over the 0-filled sectors, don't know what Disk2VHD does...

I'm talking about a single command (and no, size doesn't matter in this case), versus:
  1. Booting from a CD, that's the easy part. You want Macrium? Acronis? Clonezilla? NameIt? Easy, obviously...
  2. Then what? How/where are you going to restore? Are you going for rawdisk access in the VM? Not easy. Are you going for an intermediate image? Tedious, resource/time consuming. A restore to USB? You better read the FAQ. In any event it's way, way more involved than a single command line. That's all pretty much I'm saying, and no, it's not a question about tools or anything like that, it's the procedure itself that's more complicated, by definition.
Going to put in my tools slippers now and relax... ;)
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Lean_geek
Posts: 44
Joined: 14. Apr 2018, 22:25

Re: Convert VirtualDisk to PhysicalDisk

Post by Lean_geek »

i need to either:
  1. be able to use the install iso to install to my desktop computer, or
  2. be able to reimage the .vdi to a physical partition and add that partition to grub for a boot option
Whatever you say like a poet or anything, you need to clarify some definitions.
  1. Iso's are cd image. You install os to your pc from cd, similarly install iso works in vm.
  2. So for your first 'desire', simply burn the iso to a physical cd from your real pc, boot that pc from the cd, install whatever os and done.
  3. First you said you want to make vm real, then said that you want to image the vdi to physical disk... these all make little sense.
  4. What your vm (and clonezilla) see as dev/sda1 is the virtual hdd, which is stored in your real machine as .vdi (in compressed format). So tools running in vm can never see the vdi but its content (dev/sda1)
  5. For desire 2, what you can do is 1. locate vbox binary folder, 2. execute

    Code: Select all

    /path/to/vboxbin/VBoxManage clonehd --format raw yourvdi.vdi yourimg.img
    3. Now the resulting large .img can be used to write on you favourite partition using dd or whatever.
  6. Learn not to use rude words in these forums. It helps little.
PS: Hope this is sufficiently long answer :D . If you still need more, @socratis will provide :?
Last edited by socratis on 30. Mar 2019, 11:35, edited 1 time in total.
Reason: Fixed formatting.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Convert VirtualDisk to PhysicalDisk

Post by mpack »

socratis wrote: [*]Then what? How/where are you going to restore?
? How do you normally restore a PC from an image backup? You boot from a recovery CD (normally the same CD you used to make the backup image), point the software at the image, click "Restore". This doesn't seem very difficult to me. Surely you must already use this exact technique if you tried something you regret on a physical PC?
socratis
Site Moderator
Posts: 27330
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Convert VirtualDisk to PhysicalDisk

Post by socratis »

Lean_geek wrote:
/path/to/vboxbin/VBoxManage clonehd --format raw yourvdi.vdi yourimg.img
Lean_geek, you're absolutely right, I completely forgot about this one! The full command actually goes as:
VBoxManage clonemedium      [disk|dvd|floppy] <uuid|inputfile> <uuid|outputfile>
                            [--format VDI|VMDK|VHD|RAW|<other>]
                            [--variant Standard,Fixed,Split2G,Stream,ESX]
                            [--existing]
which makes me wonder what would happen if I run:
  • 
    VBoxManage clonemedium "<MyVM.vdi>"  /dev/disk<N> --format RAW --existing
I need to "sacrifice" an actual disk to test that theory, but that would pretty much bring the V2P at the one-line, command-line, ease of use that I had in mind with the equivalent P2V procedure...
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
socratis
Site Moderator
Posts: 27330
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Convert VirtualDisk to PhysicalDisk

Post by socratis »

I have an 8 GB multi-boot USB stick, created with YUMI 2.0.6.4 (invaluable little tool!) that can multi-boot into:
  1. Hiren's Boot CD,
  2. Ultimate Boot CD, and
  3. Linux Mint 19 (Tara) Cinnamon 64-bit DVD.
I did the following:
$ sudo VBoxManage convertfromraw /dev/disk2 MultibootUSB.vdi
Converting from raw image file="/dev/disk2" to file="MultibootUSB.vdi"...
Creating dynamic image with size 8036285952 bytes (7664MB)...
and build a simple VM around it:

Code: Select all

$ VBoxManage showvminfo MultibootUSB
Name:                        MultibootUSB
Groups:                      /
Guest OS:                    Other/Unknown (64-bit)
UUID:                        270a1588-614d-4529-99be-236fed361b56
Config file:                 /Users/Shared/VirtualBox/Machines/MultibootUSB/MultibootUSB.vbox
Snapshot folder:             /Users/Shared/VirtualBox/Machines/MultibootUSB/Snapshots
Log folder:                  /Users/Shared/VirtualBox/Machines/MultibootUSB/Logs
Hardware UUID:               270a1588-614d-4529-99be-236fed361b56
Memory size                  2048MB
Page Fusion:                 disabled
VRAM size:                   128MB
CPU exec cap:                100%
HPET:                        disabled
CPUProfile:                  host
Chipset:                     piix3
Firmware:                    BIOS
Number of CPUs:              2
PAE:                         enabled
Long Mode:                   enabled
Triple Fault Reset:          disabled
APIC:                        enabled
X2APIC:                      disabled
Nested VT-x/AMD-V:           disabled
CPUID Portability Level:     0
CPUID overrides:             None
Boot menu mode:              message and menu
Boot Device 1:               DVD
Boot Device 2:               HardDisk
Boot Device 3:               Not Assigned
Boot Device 4:               Not Assigned
ACPI:                        enabled
IOAPIC:                      enabled
BIOS APIC mode:              APIC
Time offset:                 0ms
RTC:                         UTC
Hardw. virt.ext:             enabled
Nested Paging:               enabled
Large Pages:                 enabled
VT-x VPID:                   enabled
VT-x unr. exec.:             enabled
Paravirt. Provider:          Default
Effective Paravirt. Prov.:   None
State:                       powered off (since 2019-03-30T15:30:14.376000000)
Monitor count:               1
3D Acceleration:             enabled
2D Video Acceleration:       disabled
Teleporter Enabled:          disabled
Teleporter Port:             0
Teleporter Address:          
Teleporter Password:         
Tracing Enabled:             disabled
Allow Tracing to Access VM:  disabled
Tracing Configuration:       
Autostart Enabled:           disabled
Autostart Delay:             0
Default Frontend:            
VM process priority:         default
Storage Controller Name (0):            IDE
Storage Controller Type (0):            PIIX4
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0):  2
Storage Controller Port Count (0):      2
Storage Controller Bootable (0):        on
IDE (0, 0): /Users/Shared/VirtualBox/Machines/MultibootUSB/MultibootUSB.vdi (UUID: 3ed414f4-f43f-48ec-a2e3-7debece3dbfe)
IDE (1, 0): Empty
NIC 1:                       MAC: 08002765947F, Attachment: Host-only Interface 'vboxnet0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 2:                       MAC: 0800272F577F, Attachment: Internal Network 'VBoxIntNetwork', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 3:                       MAC: 08002758BAED, Attachment: NAT Network 'VBoxNATservice', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 4:                       MAC: 0800272B4275, Attachment: Bridged Interface 'en0: Wi-Fi (AirPort)', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 5:                       disabled
NIC 6:                       disabled
NIC 7:                       disabled
NIC 8:                       disabled
Pointing Device:             USB Tablet
Keyboard Device:             PS/2 Keyboard
UART 1:                      disabled
UART 2:                      disabled
UART 3:                      disabled
UART 4:                      disabled
LPT 1:                       disabled
LPT 2:                       disabled
Audio:                       enabled (Driver: CoreAudio, Controller: HDA, Codec: STAC9221)
Audio playback:              enabled
Audio capture:               enabled
Clipboard Mode:              Bidirectional
Drag and drop Mode:          disabled
VRDE:                        disabled
OHCI USB:                    disabled
EHCI USB:                    disabled
xHCI USB:                    enabled

USB Device Filters:

<none>

Bandwidth groups:  <none>

Shared folders:<none>

Capturing:                   not active
Capture audio:               not active
Capture screens:             0
Capture file:                /Users/Shared/VirtualBox/Machines/MultibootUSB/MultibootUSB.webm
Capture dimensions:          1024x768
Capture rate:                512kbps
Capture FPS:                 25kbps
Capture options:             

Guest:

Configured memory balloon size: 0MB
To my delight it worked right out of the box; audio "sung", all 4 networking cards got an IP, all tools, name it. Even the "Live Mint 19" that was installed in the USB worked. I guess because there was not any "custom" or "fancy" hardware to begin with, and the Live ones are more flexible regarding the hardware changes.

The only problem is that "convertfromraw" didn't take into account the 0-filled sectors, and the whole thing had to be "translated" to VDI-ish:
$ ls -al
total 15691784
drwx------    4 socratis  staff         136 30 Μαρ 17:38 .
drwxrwxrwx  108 socratis  staff        3672 30 Μαρ 17:37 ..
-rw-------    1 socratis  staff        3699 30 Μαρ 17:38 MultibootUSB.vbox
-rw-------    1 socratis  staff  8034189312 30 Μαρ 17:38 MultibootUSB.vdi

$ VBoxManage showmediuminfo MultibootUSB.vdi
UUID:           3ed414f4-f43f-48ec-a2e3-7debece3dbfe
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       /Users/Shared/VirtualBox/Machines/MultibootUSB/MultibootUSB.vdi
Storage format: VDI
Format variant: dynamic default
Capacity:       7663 MBytes
Size on disk:   7662 MBytes
Encryption:     disabled
Property:       AllocationBlockSize=
In use by VMs:  MultibootUSB (UUID: 270a1588-614d-4529-99be-236fed361b56)

I then decided to be bold, and transform the VM into a real disk, the very thing that the OP is asking for. So I went for my "insiration" from the previous post, with another, new/virgin USB stick:
$ sudo VBoxManage clonemedium MultibootUSB.vdi /dev/disk2 --format RAW --existing
Syntax error: Specified options which cannot be used with --existing
:shock: Why not? That's a bummer...

Then I took out the "--existing" and I got the answer I was afraid of:
$ sudo VBoxManage clonemedium disk MultibootUSB.vdi /dev/disk2 --format RAW
0%...
Progress state: VBOX_E_FILE_ERROR
VBoxManage: error: Failed to clone medium
VBoxManage: error: Could not create the clone medium '/dev/disk2'.
VBoxManage: error: Raw: cannot create image '/dev/disk2' (VERR_ALREADY_EXISTS)
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium
VBoxManage: error: Context: "RTEXITCODE handleCloneMedium(HandlerArg *)" at line 1071 of file VBoxManageDisk.cpp
If you can't overwrite an existing partition, there was only one thing to be done, but which defeats the whole purpose; create an intermediate IMG file which could be then transferred to the Physical disk with 'dd':
$ sudo VBoxManage clonemedium MultibootUSB.vdi MultibootUSB.img --format RAW
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone medium created in format 'RAW'. UUID: 4c476ace-af22-4216-9126-ef56ec47ed47

$ sufo dd if=MultibootUSB.img of=/dev/disk2 bs=1024
7847935+1 records in
7847935+1 records out
8036285952 bytes transferred in 5192.400374 secs (1547702 bytes/sec)
So I did go from Physical-to-Virtual just the way I had hoped, but not from Virtual-to-Physical, mainly because the "clonemedium" doesn't work with Physical devices. Something to ask the developers come Monday...
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Lean_geek
Posts: 44
Joined: 14. Apr 2018, 22:25

Re: Convert VirtualDisk to PhysicalDisk

Post by Lean_geek »

Off topic( pls don't block :P )
Is there any way to do this for some specific sectors?
Suppose I have a vdi, I convert it to raw, then save the first 14 sectors and delete the rest. Is there a way to do this directly( ie without converting the whole <N>GB disk)?
socratis
Site Moderator
Posts: 27330
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Convert VirtualDisk to PhysicalDisk

Post by socratis »

This is not VirtualBox related. Try to think outside of VirtualBox, how would you do it with a real computer? That's how you'd do it in a VM a well, that is boot with a CD such as SystemRescueCD and extract the first 14 sectors.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Post Reply