firewing1 - mbrhttp://www.firewing1.com/taxonomy/term/156
enAttaching MBR or GPT disk partitions to a VirtualBox VMhttp://www.firewing1.com/blog/2013/04/03/attaching-mbr-or-gpt-disk-partitions-virtualbox-vm
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>On one of my development machines I triple-boot so that I can test in a variety of operating environments. My default is OS X and the other day I wanted to write documentation using DocBook. I knew that my Linux installation already had publican installed and ready to go (<a href="https://fedorahosted.org/publican/">publican</a> is a wonderful documentation tool written by Red Hat to facilitate the publishing of DocBook-based documentation) and I really did not want to setup a new Fedora VM that duplicated a setup I already had.</p>
<p>In reality, a new VM would not be all that much effort, but I though it would be really handy to know how to boot a VM up from a physical partition and this way I could kill two birds with one stone. After some research, it seemed using VMWare's VMDK (Virtual Machine Disk Format) images was the most appropriate, as the metadata could be tricked into pointing to physical partitions instead of files. Unfortunately, the tools VirtualBox provide to create them are not compatible with GPT disk tables out of the box. <a href="http://blog.jardinmagique.info/2009/08/setup-virtualbox-on-macosx-to-boot.html">This</a> blog post does mention a trick to convert the VMDK metadata to match the GPT disk layout, but it failed consistently when I tried.</p>
<p>I then, by fluke, found Dave Vasilevsky's <a>vmdk-raw-parts</a> script on GitHub which worked flawlessly! Its usage is well documented so I will not bore you with the details, but with that said after using it to create my custom VMDK, the only change required was to run <code>chmod 666 /dev/diskXsY</code> to grant my user write permissions to the disk (prevents you from having to start VirtualBox as root).</p>
<h4>Some Extra Troubleshooting</h4>
<p>These details are completely irrelevant to the above, but I wanted to mention them here for others wanting to run the same setup:</p>
<ul>
<li>If you need USB pass-through, remember to set your VCPUs to 1; set it to anything higher and <a href="http://www.virtualbox.org/ticket/7462">USB stops functioning</a>.</li>
<li>You'll need to redo the 'chmod' when ever you reboot your machine, as the permissions on the dev node get reset upon boot.</li>
<li>During the trial-and-error process of getting this to work, I often needed to recreate my VMDK and reload it. VirtualBox will moan about mismatched UUIDs... The simple fix is to open <em>File &gt; Virtual Media Manager...</em> to delete then re-add your VMDK file.</li>
</ul>
</div></div></div><span class="submitted-by">Posted on Wed, 2013/04/03 - 5:26pm</span><div class="field field-name-field-vote field-type-fivestar field-label-inline clearfix"><div class="field-label">Rating:&nbsp;</div><div class="field-items"><div class="field-item even"><form class="fivestar-widget" action="/taxonomy/term/156/feed" method="post" id="fivestar-custom-widget" accept-charset="UTF-8"><div><div class="clearfix fivestar-average-stars fivestar-form-item fivestar-minimal"><div class="form-type-fivestar form-item-vote form-item form-group">
<div class="form-type-select form-item-vote form-item form-group">
<select class="form-control form-select" id="edit-vote--2" name="vote"><option value="-">Select rating</option><option value="20">Give it 1/5</option><option value="40">Give it 2/5</option><option value="60" selected="selected">Give it 3/5</option><option value="80">Give it 4/5</option><option value="100">Give it 5/5</option></select>
</div>
</div>
</div><button class="fivestar-submit btn btn-default form-submit" id="edit-fivestar-submit" name="op" value="Rate" type="submit">Rate</button>
<input type="hidden" name="form_build_id" value="form-k7DMiGZDL7AHHOlF8eRfjR2sexsUNysZB68ePH1YPc8" />
<input type="hidden" name="form_id" value="fivestar_custom_widget" />
</div></form></div></div></div><div class="field field-name-field-share field-type-addthis field-label-hidden"><div class="field-items"><div class="field-item even"><div class="addthis_toolbox addthis_default_style " addthis:title="Attaching MBR or GPT disk partitions to a VirtualBox VM - firewing1" addthis:url="http://www.firewing1.com/blog/2013/04/03/attaching-mbr-or-gpt-disk-partitions-virtualbox-vm"><a href="http://www.addthis.com/bookmark.php?v=250" class="addthis_button_email"></a>
<a href="http://www.addthis.com/bookmark.php?v=250" class="addthis_button_facebook"></a>
<a href="http://www.addthis.com/bookmark.php?v=250" class="addthis_button_twitter"></a>
<a href="http://www.addthis.com/bookmark.php?v=250" class="addthis_button_google_plusone_share"></a>
</div>
</div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-inline clearfix"><div class="field-label">Tags:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/183">VirtualBox</a></div><div class="field-item odd"><a href="/taxonomy/term/184">virtual machine</a></div><div class="field-item even"><a href="/taxonomy/term/155">gpt</a></div><div class="field-item odd"><a href="/taxonomy/term/156">mbr</a></div><div class="field-item even"><a href="/taxonomy/term/185">partition</a></div><div class="field-item odd"><a href="/taxonomy/term/186">disk</a></div></div></div>Wed, 03 Apr 2013 21:26:28 +0000firewing1628 at http://www.firewing1.comhttp://www.firewing1.com/blog/2013/04/03/attaching-mbr-or-gpt-disk-partitions-virtualbox-vm#commentsHow to Convert a GPT disk layout to a MS-DOS/MBR layout without data loss (and Gigabyte Hybrid EFI)http://www.firewing1.com/blog/2012/03/05/how-convert-gpt-disk-layout-ms-dosmbr-layout-without-data-loss-and-gigabyte-hybrid
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p><em>If you're coming here from Google searching for how to convert a GPT disk layout to MS-DOS/MBR and don't want to read through my (probably boring) story, click <a href="#gpttombr">here</a> ;)</em></p>
<h1>Adventures with Hybrid EFI</h1>
<p>My gaming PC has been long overdue due for a reformat. I naively allocated only 30GB to the Windows partition (and the other 120GB to 3 flavours of Linux) thinking I wouldn't use Windows for much other than Starcraft 2, but a few months back I had the urge to play Battlefield 2 again. Ever since installing and fully patching it disk space has been running pretty tight. I had to disable sleep, hibernation as well as system restore and still only had 4GB of free space, so my filesystem became fragmented easily. With the release of Windows 8 Customer Preview (download it free <a href="http://windows.microsoft.com/en-us/windows-8/iso">here</a>), I figured it was a good time to reformat my disk and reinstall all my OSs from scratch.</p>
<p>I figured while I'm at it, I would make all of the big changes at once and enabled EFI booting on my Gigabyte GA-Z68A-D3H board. Little did I know that when the BIOS says "EFI," it really means Gigabyte's "Hybrid EFI" implementation and <strong>not</strong> UEFI (although in retrospect, the fact that I made the change in the <em>BIOS</em> should have been enough of a hint, right?). With Hybrid EFI enabled, Windows 7 and Windows 8CP installed perfectly and even created a nice GPT disk layout so reinstalled my games and activated Windows 7. Then I rebooted to play around in Windows 8CP for a bit (I do not like it, btw).</p>
<p>I then tried installing Fedora 16. To my surprise EFI booting failed every time, despite the all of the Fedora 16 installation media being EFI-capable. When attempting to boot from my Fedora 16 Live (x86_64) USB key I just would get a black screen with "........." printed one dot a time and then it would proceed to fall back to the next boot device (Windows boot manager on the hard disk). Upon re-examining my BIOS settings, I was disappointed to find that the setting was actually called "CD/DVD EFI Boot Option" indicating that perhaps USB EFI booting was not supported. Fair enough, I burnt the same F16 image I was using on the USB key to a CD and tried again. The same "........." text appeared.</p>
<p>It was then as I went back to boot Windows 7 that I discovered my attempts to set it as the default OS from Windows 8CP removed my capability of booting Windows 7 somehow. At this point it was 2AM and I was fed up with this stupid Hybrid EFI. I looked for a way to revert to a good old MS-DOS/MBR partition layout. After some Googling I stumbled across <a href="http://www.rodsbooks.com/gb-hybrid-efi/">Rod Smith's website</a>. He has extensive documentation on EFI booting, including with Gigabyte's implementation of Hybrid EFI. He says that it shares a large amount of code with <a href="http://tianocore.sourceforge.net">EFI DUET</a> (tianocore) and although it does work natively with Windows 7, it is not a full UEFI implementation. That would explain the problems I was having with Fedora, then.</p>
<p><a name="gpttombr"></a></p>
<h1>The actual GPT to MBR conversion</h1>
<p>Through the Rod Smith's guidance and a few dirty tricks, I was successfully able to convert my GPT partition - without data loss or deleting any partitions - and then boot Windows 7 in legacy/MBR mode. In order to do this you'll need your Windows installation media at hand as well as a copy of the Fedora 16 Live media. If you don't have a copy of Fedora 16 Live handy, you can download the Live media ISO (64-bit) from a local mirror <a href="http://download.fedoraproject.org/pub/fedora/linux/releases/16/Live/x86_64/Fedora-16-x86_64-Live-Desktop.iso">here</a>. See the <a href="http://docs.fedoraproject.org/en-US/Fedora/16/html/Installation_Guide/sn-making-media.html">Fedora 16 Installation Guide</a> for details on burning this image to a CD or on creating a bootable USB key.</p>
<p>Keep in mind that at this point I only had 3 partitions and a bunch of unpartitioned space on the disk, so conversion was a rather straightforward process (all GPT partitions mapped directly to primary partitions). Although it is theoretically possible to convert GPT partitions with &gt;4 partitions by defining which ones are to be logical partitions after conversion, I have not tested this.</p>
<ol>
<li>Boot your Fedora 16 Live media and wait for your session to start. If you're having troubles booting, press Tab at the boot loader screen and try booting with the <code>nomodeset</code> parameter added.</li>
<li>Depending on your graphics card, you'll either be presented with the new Gnome 3 Shell or with the traditional interface. Start a terminal session by putting your mouse in the top right corner of the screen and typing "terminal" in the search (Gnome Shell) or by selecting Applications &gt; System Tools &gt; Terminal (traditional interface)</li>
<li>Install gdisk:<div class="codeblock"><code>su -<br />yum -y install gdisk</code></div>This may take a few moments.</li>
<li>Make a backup of your current GPT scheme:<div class="codeblock"><code>gdisk -b sda-preconvert.gpt /dev/sda</code></div></li>
<li>Now we will attempt to convert your GPT disk layout to MS-DOS/MBR. Start gdisk:<div class="codeblock"><code>gdisk /dev/sda</code></div><br />
You should be prompted with:<div class="codeblock"><code>Command (? for help):</code></div>
</li>
<li>Press <code>r</code> to start recovery/transformation.</li>
<li>Press <code>g</code> to convert GPT to MBR.</li>
<li>Press <code>p</code> to preview the converted MBR partition table.</li>
<li>Make any modification necessary to the partition layout. See Rod Smith's <a href="http://www.rodsbooks.com/gdisk/mbr2gpt.html#gpt2mbr">Converting to or from GPT</a> page for more details on this.</li>
<li>When you're happy with the MS-DOS/MBR layout, press <code>w</code> to write changes to the disk.</li>
<li>Shutdown Fedora 16 and boot from the Windows 7 installation media</li>
<li>Enter your language &amp; keyboard layout and then select the option to repair your computer in the bottom left corner.</li>
<li>From the available options, select Startup Repair. Windows will ask for a reboot.</li>
<li>Follow the previous three steps again to boot the Windows 7 installation and run startup repair</li>
<li>Once again, boot the Windows 7 installation media but this time opt to open a command prompt instead of choosing startup repair. Type:<div class="codeblock"><code>bootrec /scanos<br />bootrec /rebuildbcd<br />bootrec /fixmbr<br />bootrec /fixboot</code></div>
<li>Close the command prompt and run Startup Repair one last time.</li>
</li>
</ol>
<p>That's it! You should now have a bootable installation of Windows 7 on a MBR partition layout.</p>
<h1>References</h1>
<ul>
<li>Rod Smith's <a href="http://www.rodsbooks.com/gb-hybrid-efi/index.html">Gigabyte's Hybrid EFI</a></li>
<li>Rod Smith's <a href="http://www.rodsbooks.com/gdisk/mbr2gpt.html#gpt2mbr">Converting to or from GPT</a></li>
<li>Rod Smith's <a href="http://www.rodsbooks.com/gdisk/repairing.html">Repairing GPT disks</a></li>
<li>Microsoft KB927392: <a href="http://support.microsoft.com/kb/927392">How to use the Bootrec.exe tool in the Windows Recovery Environment to troubleshoot and repair startup issues in Windows</a></li>
</ul>
</div></div></div><span class="submitted-by">Posted on Mon, 2012/03/05 - 8:34pm</span><div class="field field-name-field-vote field-type-fivestar field-label-inline clearfix"><div class="field-label">Rating:&nbsp;</div><div class="field-items"><div class="field-item even"><form class="fivestar-widget" action="/taxonomy/term/156/feed" method="post" id="fivestar-custom-widget--2" accept-charset="UTF-8"><div><div class="clearfix fivestar-average-stars fivestar-form-item fivestar-minimal"><div class="form-type-fivestar form-item-vote form-item form-group">
<div class="form-type-select form-item-vote form-item form-group">
<select class="form-control form-select" id="edit-vote--4" name="vote"><option value="-">Select rating</option><option value="20">Give it 1/5</option><option value="40">Give it 2/5</option><option value="60">Give it 3/5</option><option value="80">Give it 4/5</option><option value="100" selected="selected">Give it 5/5</option></select>
</div>
</div>
</div><button class="fivestar-submit btn btn-default form-submit" id="edit-fivestar-submit--2" name="op" value="Rate" type="submit">Rate</button>
<input type="hidden" name="form_build_id" value="form-J4Y7AXxc-Z1wr37X-NzzpIjdvz0RgOl6HghbdA0R_RI" />
<input type="hidden" name="form_id" value="fivestar_custom_widget" />
</div></form></div></div></div><div class="field field-name-field-share field-type-addthis field-label-hidden"><div class="field-items"><div class="field-item even"><div class="addthis_toolbox addthis_default_style " addthis:title="How to Convert a GPT disk layout to a MS-DOS/MBR layout without data loss (and Gigabyte Hybrid EFI) - firewing1" addthis:url="http://www.firewing1.com/blog/2012/03/05/how-convert-gpt-disk-layout-ms-dosmbr-layout-without-data-loss-and-gigabyte-hybrid"><a href="http://www.addthis.com/bookmark.php?v=250" class="addthis_button_email"></a>
<a href="http://www.addthis.com/bookmark.php?v=250" class="addthis_button_facebook"></a>
<a href="http://www.addthis.com/bookmark.php?v=250" class="addthis_button_twitter"></a>
<a href="http://www.addthis.com/bookmark.php?v=250" class="addthis_button_google_plusone_share"></a>
</div>
</div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-inline clearfix"><div class="field-label">Tags:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/12">windows</a></div><div class="field-item odd"><a href="/taxonomy/term/43">linux</a></div><div class="field-item even"><a href="/taxonomy/term/42">fedora</a></div><div class="field-item odd"><a href="/taxonomy/term/152">uefi</a></div><div class="field-item even"><a href="/taxonomy/term/153">gigabyte</a></div><div class="field-item odd"><a href="/taxonomy/term/154">hybrid efi</a></div><div class="field-item even"><a href="/taxonomy/term/155">gpt</a></div><div class="field-item odd"><a href="/taxonomy/term/156">mbr</a></div></div></div>Tue, 06 Mar 2012 01:34:54 +0000firewing1610 at http://www.firewing1.comhttp://www.firewing1.com/blog/2012/03/05/how-convert-gpt-disk-layout-ms-dosmbr-layout-without-data-loss-and-gigabyte-hybrid#comments