Tutorial: Boot existing Ubuntu Partition using Virtualbox inside Windows (deprecated)

Edit 22/11/09
Ubuntu 9.10 uses the new grub 2 as its boot-loader thus this article would not work for 9.10. I am currently in the progress of getting 9.10 to work under Virtualbox.

This tutorial would no longer be supported. Any comments regarding support will be ignored.

If you want to get 9.10 working please READ THIS ARTICLE

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I recently got Windows 7 and Ubuntu running in a dualboot. However, since I’m using more of Windows now I figured I should probably find a way to run Ubuntu inside my Windows. VM’s are great, but it’d be better if I can actually boot into my existing Ubuntu partition. So I searched the web and kept on finding tutorials on how to boot existing XP partitions inside Windows. So I decided to extrapolate from those tutorials and work my way through it. I’ll be writing how I did it here.

Before we begin, you should have a dual boot setup. I will NOT be showing you how to setup a dual boot, if you need help plenty of other guides out there.

Step 1: Creating a grub boot iso

The grub iso file will allow you to specify which partition to boot into.

  1. Boot into Ubuntu
  2. We create the folders and copy the necessary files to setup an iso
    Run the command:  cd ; mkdir -p iso/boot/grub ; cp /usr/lib/grub/*-pc/stage2_eltorito /boot/grub/menu.lst iso/boot/grub
  3. Configure your ~/iso/boot/grub menu.lst file to boot your target OS (in this case Ubuntu). Remove the “savedefault” option from your target entry if it exists.
  4. We now create the bootable iso file
    Run the command: cd ; mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o grub.iso iso
  5. Move the iso to a location that’ll be accessable by your Windows partition

Step 2: Creating the .vmdk file

This creates a file which tells Virtualbox what partition to actually load as the harddrive. Unfortunately, unlike VMWare Workstation, Virtualbox does not support a GUI interface for selecting RAW hard disks as the “virtual hard drive”.

  1. Boot into Windows
  2. cd into the directory you installed virtualbox
  3. We find the partition number that needs to be mounted
    Run the command: VBoxManage.exe internalcommands listpartitions -rawdisk \\.\PhysicalDrive1
    (where 1 is the number of the hard drive ubuntu is installed on. E.g. Master should be 0, you’re second hard-drive should be 1 etc…The output should be something like:

    Number  Type   StartCHS       EndCHS      Size (MiB)  Start (Sect)
    1       0×07  0   /32 /33  1023/254/63        902023         2048
    5       0×83  1023/254/63  1023/254/63         49677   1847346543
    6       0×82  1023/254/63  1023/254/63          2164   1949086188

    In this example, my Ubuntu partition is number 5 and the swap is number 6

  4. We now create the VMDK file with the given information
    Run the command: VBoxManage.exe internalcommands createrawvmdk -filename C:\path\ubuntu.vmdk -rawdisk \\.\PhysicalDrive1  -partitions 5,6 -register

Step 3: Setup Virtualbox

Now everything should be ready to setup Virtualbox. Create a new virtual machine. Select the .vmdk file we just created as the hard drive and mount the grub.iso file we created at Step 1. If everything was successful Ubuntu should boot up nicely.

DONE!

If this has helped you in any way, please take the time to drop a comment! If you have any problems, just post a comment or send me an email through the “Contact me” page.

References:

Boot an existing XP (Physical HD) install with VirtualBox

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

70 Comments »

 
  • Patrick says:

    Howdy! I first want to say you’re fantastic for posting this! Every other tutorial I found was for booting Windows in Ubuntu. I find it spooky that my root/swap partitions are in the same positions on the same physical drive as you. Also, I feel you should know I will teach my children songs about you as they go to bed :)

    In anycase, one problem I ran across was that I had to change root (hd1,5) to root (hd0,5). Do you happen to have any recommendations regarding this situations?

    Additionally, Ubuntu doesn’t seem to recognize my display drivers (I use fglrx) and forces the display into 800×600. Unfortauntely, I don’t know if that has anything to do with the above.

    • John Jiang says:

      Hi there! Thanks for commenting! I hope you’re not serious about the songs though :P

      I’m not too sure what you mean by changing the root from (hd1,5) to (hd0,5), please elaborate.

      But in terms of the display drivers, it’s most likely you don’t have guest additions installed. Just install guest additions in VirtualBox and it should be able to resize your guest resolution to your host resolution.

      Cheers.

  • Patrick says:

    Ah! My mistake. In the menu.lst file it listed to the root as (hd1,5), but the VM hard drive was placed in the first slot, changing it to (hd0,5) and I was too lazy to adjust it to reflect the VM harddrive setup. Just something for people to be aware of, I suppose.

    Also, installing the Guest Additions solved my display troubles! Thanks for the tip =D

    • nick says:

      Hello!

      I’ve followed your tutorial attentively, but when I boot grub, I get error 15 for ubuntu and error 22 for all other items. I either lost it at step 1-3 or 2-4.

      This is hell!

  • Adam says:

    I am planning on booting one windows inside another, could I create a grub boot iso in windows?

  • Paul says:

    Hi there, thanks for the instructions, I am trying to set it up but it fails for me at the create raw vmdk stage, fails saying VERR_INVALID_PARAMETER. I’ve had a look at the docs – can’t find anything. Any suggestions? Possibly its because I have vista?

    • John Jiang says:

      It shouldn’t have anything to do with Vista, what I’d recommend you to do is just copy paste the output of every command that you typed and email it to me. Just use the form in “Contact me”. Cheers.

  • Nick says:

    Hello,

    Great article, it is just what I am looking for. However, I am completely new to this so I don’t understand some things.

    In part 3 of Step 2 you say “We find the partition number that needs to be mountedRun the command: VBoxManage.exe internalcommands listpartitions -rawdisk \\.\PhysicalDrive1″. I don’t understand this step. How do I run this command in Windows XP? Start, Run? Command Prompt? Because both do not work for me. It says Windows cannot find VBoxManage.exe. Do I need to put the directory into it aswell? I really do not know what the exact command is.

    My VBoxManage.exe file is located here on my computer:

    F:\Program Files\Sun\xVM VirtualBox

    Any help would be much appreciated,

    Thanks.

    • John Jiang says:

      Hi,

      You forgot to cd into the directory where you installed virtual box. In your case you need to type “cd F:\Program Files\Sun\xVM VirtualBox” inside command prompt.

      Cheers.

      • Nick says:

        Thanks for the help, but unfortunately I didn’t get very far. The next step creating the VMDK file gave me an error and didn’t create the file.

        Error while creating the raw disk VMDK: VERR_INVALID_NAME

        Here is what I typed:

        VBoxManage.exe internalcommands createrawvmdk -filename “F:\ubuntu.vmdk” -rawdisk \\.\PhysicalDrive0 -partitions 5,6 -register

        Sorry to bother you again!

        • John Jiang says:

          Try removing the speech marks around the filename. For some reason it wasn’t working for me either, I took them out and it began working, I put them back in and it’s working again. How bizarre.

  • Randy says:

    Thanks for the great tutorial. I am trying to follow it but I’m running into a problem with step 2. When I do VBoxManage.exe internalcommands listpartitions -rawdisk \\.\PhysicalDrive0 (or 1 or 2) I get VERR_ACCESS_DENIED. Is there a step I’m missing that is assumed? This is in windows vista, which I don’t know quite as much about as I do xp or ubuntu.

    • John Jiang says:

      I believe this is a read/write issue. Google doesn’t give any sufficient answers. What version of Virtualbox are you using? Try using the latest 3.0 if you’re using 2.x, otherwise if you are using 3.0 go back to a 2.x version and try.

      • kartikeyan says:

        You should be administrator before executing this command.
        so start->accessories->command rightclick->run as administrator.

        Then type the above commands.
        It should work fine.

  • nullpointer says:

    This post looks great. Most of the posts i found are for Linux host with Windows guest OS. I havn’t tried it yet, but plan to. With this setup could i still boot my Ubuntu OS outside VB, i mean as a dual boot to my Windows?

  • Mark Smith says:

    Thanks for the great info it is exactly what I was looking for. I am fine up until the last step.
    —–
    Step 3: Setup Virtualbox

    Now everything should be ready to setup Virtualbox. Create a new virtual machine. Select the .vmdk file we just created as the hard drive and mount the grub.iso file we created at Step 1. If everything was successful Ubuntu should boot up nicely.

    When you say “mount the grub.iso” then everything works can you be more specific. What are you using to “mount the grub.iso”? How is the iso file related to the vm or the .vmdk?

    Also, I am concerned that Ubuntu is mounting my NTFS partition by default. Will this be an issue with XP and Ubuntu writing to the “rawdisk”?

    Thanks for the help.

    • John Jiang says:

      You need to mount the grub.iso inside virtualbox so it knows which partition to boot from. You can do this under the guest-os settings -> CD/DVD-ROM.

      Regarding your second concern, I do not know what problems it can cause as I’ve never tried it.

  • Great tutorial. Only problem I keep having is that the X server won’t start. kvm fails and the error report says “Fatal server error – no screens found”. X Server won’t start and it says to start GDM when the X Server is configured properly. Any ideas? Thanks for the tutorial. (Using nvidia driver 180.44-but it says [OK]).

    • John Jiang says:

      Try installing guest additions, should fix your problems.

      • I did mount the guest editions and clicked on install Guest Editions. Whether it did it or not I don’t know. Still the same problem though. kvm module failed to load and X server is halted and I am left at a command prompt. For whatever reason it does not seem to want to work. At some point maybe I’ll find the reason for Ubuntu’s problem. Thanks for the help.

        • John Jiang says:

          So did you install guest additions via the terminal? It should give you a bunch of output if you did install it.

          • William Logan says:

            Sorry for the long interruption. I’ve gone back into this project with the same results. Guest Additions ISO is mounted. I can start to boot into the ‘virtual’ Ubuntu partition. It fails to boot and I am left at a prompt. I can’t get into the Ubuntu GUI to run anything. All that I have is a black screen being asked to login and start GDE after the problems with the X-server have been resolved. I don’t think it should make a difference, but I am running Ultimate Edition 2.2 with the NVIDIA driver. I have tried clicking on the Install Guest Additions menu item (HOSTS + D, whatever that is) and nothing happens. Not to sound discouraged, but this does not seem possible on the installation I have.

          • John Jiang says:

            are you sure you installed guest additions? mounting guest additions is different to actually installing it. You have to cd into the cdrom at terminal and run guest additions for linux.

  • Karl-Heinz says:

    Great work. Thank you very much. Saved me a lot of time.

    One suggestion to make it easier for newbies like me:

    Instead of generating my own grub.iso I use the Super Grub Iso from here: http://www.supergrubdisk.org

    I installed an external, bootable USB HD with Ubuntu and I carry this HD with me to use it on different computers. It has two partitions, one with ntfs and the other with ubuntu. In the ntfs partition I copied the files for the VirtualBox, so that I can install it where I need it – and this tutorial :-)

    Now I have Ubuntu at hand within my XP machines in a virtual machine. But when I need performance (some number crunching) I will boot the Ubuntu partition directly.

    You did a great job with this tutorial.

    Karl-Heinz

    • John Jiang says:

      I had a look at supergrubdisk and it seems like a nice and simple solution. However, if not careful, users might actually accidentally boot into the host partition which can cause lots of problems.

      I’m glad that my tutorial has helped you :) It’s always good hearing positive feedback.

  • Daniel says:

    Hi, I’m following your instructions, and when I do:
    VBoxManage.exe internalcommands listpartitions -rawdisk \\.\PhysicalDrive0
    It shows :

    Number Type StartCHS EndCHS Size (MiB) Start (Sect)
    1 0×27 0 /32 /33 1023/254/63 10000 2048
    2 0×07 1023/254/63 1023/254/63 34247 20482875
    3 0×07 1023/254/63 1023/254/63 30278 90622665

    Which are the ntfs partitions I have. It doesn’t show the linux ones
    I don’t know if the trouble is with logical partitions (I think, but am not sure, that my linux partitions are logical).
    Anyways what I decided to do is take out the “-partitions …” and run :

    VBoxManage.exe internalcommands createrawvmdk -filename C:\path\ubuntu.vmdk -rawdisk \\.\PhysicalDrive1 -register

    With this, I boot into grub, and can choose kubuntu without needing any iso.

  • Daniel says:

    Be carefull, virtual box corrupted a bit of my ext3 linux filesystem.

    • Jordan says:

      I believe having my ubuntu guest mount an ntfs partition that was also mounted on my windows host corrupted files on my ntfs partition.

  • Datakanja says:

    Nice Tutorial!
    …glad, i found it, as it shows, what i intend to set up.

    Apparently, i am a dummy, as i get:

    C:\Program Files\Sun\xVM VirtualBox>vboxmanage internalcommands listpartitions -rawdisk \\.\PhysicalDrive0
    VirtualBox Command Line Management Interface Version 2.2.4
    (C) 2005-2009 Sun Microsystems, Inc.
    All rights reserved.

    Error opening the raw disk: VERR_ACCESS_DENIED

    …even if i run it as Administrator in Vista. Any Hint on how to get around this? BTW: Of course, createvmdk also fails :-(

    Datakanja

  • Datakanja says:

    Forget it, i missed that cmd isnt executed with admin-priviledge by default. when i changed that, the problem disappeared (“Execute dos prompt as admin”) was what i needed to do.

    nevermind

  • gareth says:

    Hi,
    Nice instructions… I however am coming across a slightly different error, probably due to my odd setup!
    The vmdk file I created is saying my hard disk is inaccessible, so won’t even get close to booting from it. I think the trouble is, I’m set up with Vista installed on one sata disk, and ubuntu on a 20Gb IDE disk, I’ve never seen the IDE disk in windows at all which I think could be part of the issue (I found the disk alright during the creation of the vmdk file)… any thoughts?!Cheers, G

  • gareth says:

    ah ha… scrap that, installed ext2fs in windows so I could read ext2 file systems, remade the vmdk and it worked a treat!

  • Steven Rosato says:

    Thx for the tutorial, however with my odd installation I come myself with a weird error. Here is my little situation:

    My usr and / partitions were on PysicalDrive1 on sda5 and sda7 and
    my home and swap partition were on PhysicalDrive0 on sda6 and sda7 so I basically did

    VBoxManage.exe internalcommands createrawvmdk -filename E:\data\VirtualBox\Harddisks\ubuntu-desktop-root_usr.vmdk -rawdisk \\.\PhysicalDrive1 -partitions 5,7 -register

    VBoxManage.exe internalcommands createrawvmdk -filename E:\data\VirtualBox\Harddisks\ubuntu-desktop-home_swap.vmdk -rawdisk \\.\PhysicalDrive0 -partitions 6,7 -register

    I added the second hard drive as slave to the main one that was created using the wizard manager.

    With or without the grub.iso my ubuntu boots fine, everything is loading except at the end, I get a black screen like if the video or XServer wasn’t able to boot up. I restarted and manually installed the GuestAdditions on my ubuntu partition but that didn’t fix it when I came back on Windows 7 Build 7100 (by the way). If I shut down the virtual machine, start it up again, drop on the root shell prompt and check if everything was mounted correctly, I can see my home, usr and swap really clearly. Does it have anything to do with video drivers or anything? I am using the nvidia proprietary drivers that ubuntu recommands when first installing it. Maybe someone has any tips on how to solve this?

    • Steven Rosato says:

      Oops I meant I’m using the ATI drivers with fglrx (confused myself with laptop which is nvidia). I’m guessing that has something to do with that driver because even if I load the vboxvideo driver there is still the error with no devices detected and no screens found. I’m trying to investigate further on that.

      • Steven Rosato says:

        Alright well, I made it working, I just disabled the ATI propretary drivers and vboxvideo was able to run smoothly, windows 7 with my ubuntu installation running in seamless mode is incredible!

        When I want to switch to some games, I go on the windows 7 partition, start up virtualbox and the seamless mode and I that way I can still continue using all the stuff needed beside gaming since for me windows is only for gaming :P

  • Excellent tutorial – just what I was looking for. I will try this soon.

    However, before I do, can you confirm that I can still boot into Ubuntu natively if required (i.e. NOT virtually through Windows) ??

    I would love to be able to easily access my Ubuntu partition to share files when at work during the day, but at home in the evenings I exclusivly use the Ubuntu partition and would like to still boot straight into it as before…

    Thanks.

  • [...] DONE! Here is the original post. [...]

  • Ryan says:

    Hey, I don’t know if you’re still looking at this, but I’ve tried a tutorial similar to yours (I don’t think it was the same one), and everything worked, except that I can’t get Ubuntu to change the resolution from 800×600 to 1366×768. When I go to Display, it says “Unknown.”

    I did install guest additions. I’m pretty sure it’s working because now I can capture simply by moving my mouse into the window. But its still only giving me 800×600 and 640×480 as display options.

    Also, a lot of the visual effects that I had before are disabled now, which is sort of annoying when I boot this partition from startup.

    • John Jiang says:

      Sorry, never had this problem before. Generally when you install guest additions everything should just work.

      • Ryan says:

        Okay, for some reason, it never works at first. But when I go onto Standby and then log back into Vista, it gives me the proper resolution as an option and sets it to that automatically.

        Another problem though is that when I go back into Vista, sometimes my keyboard gets messed up so that certain keys no longer do what they are supposed to. For instance, pressing “r” will bring up the run prompt rather than typing an “r” onto the screen.

        • Ryan says:

          I’m sorry…I don’t actually have to go on to standby–just locking my screen and unlocking it makes the proper screen resolution appear.

  • Charlie says:

    I have been trying this thing for ages – thanks for eventually posting a great tut.

    My problem is one that I was experiencing right in the beginning. It all works beautifully and boots into Ubuntu only to fail to load X. If I look at the boot process in verbose mode, I see a whole string of events failing due to a read only file system. For this reason, I am also not able to install guest additions as suggested above.

    Has anyone experienced this before?

    Thanks

  • Hi.

    Thanks for the tutorial it was very helpful, I posted it on my blog in spanish, hope you don’t mind, of course I wrote the reference to your blog.

    Have a nice day!

  • Scott says:

    VBoxManage.exe internalcommands listpartitions -rawdisk \\.\PhysicalDrive0

    Results in:
    Number Type StartCHS EndCHS Size (MiB) Start (Sect)
    1 0×07 0 /1 /1 1023/254/63 212720 63
    5 0×83 1023/254/63 1023/254/63 24646 435650733
    6 0×82 1023/254/63 1023/254/63 1106 486126963

    Partition 5 is my ubuntu installation and 6 is swap, totally about 25 gigs. Partition 1 is Vista at around 212 gigs. So my next command is:
    VBoxManage.exe internalcommands createrawvmdk filename C:\ubuntu.vmdk -rawdisk \\.\PhysicalDrive0 -partitions 5,6 -register

    Which works ok:
    RAW host disk access VMDK files C:\ubuntu.vmdk created successfully.

    However, in the Virtualbox media manager ubuntu.vmdk shows a virtual size of 232.89gb, actual size 284.21gb. That looks to me like my Vista install, NOT my 25 gig ubuntu install. Am i doing something wrong?

    Thanks for a great writeup!!!
    -Scott

    • John Jiang says:

      What happens when you actually boot using the VMDK file?

    • cane says:

      Hi,

      I ran into the same problem – when creating VDK for sda2 using /dev/sda and -partitions 2 option I ended with whole disk in VMDK. Solution was as simple as using /dev/sda2 without partitions option. That was under Ubuntu. I installed OpenSolaris and switched to Windows to do the same and I can’t get things working – the PhysicalDisk0 contains 2 partitions, but using -partitions 2 option does the same – I ends with whole disk 0 in VMDK file. How to specify exact partition using something like PhysicalDisk0.2?

      cane

  • Ian says:

    Thanks for the great tutorial – I’ve wanted to do this exact thing for a while but didn’t think it was possible. I tried this with Ubuntu 9.10 (with Win7 64-bit as host) but ran into a few snags and I’m not smart enough to solve them. First is that Karmic uses Grub2, so the stage2 file doesn’t exist. I think I found a way around that problem to make the boot .iso but I can’t load the vmdk file in Virtualbox because it says it can’t access the file. I don’t think this is a permissions problem in Windows – I’m wondering if the problem is the new ext4 filesystem. Any chance you could update your guide for 9.10?

  • Charlie says:

    I posted a question a while back with no response – any feedback would be greatly appreciated.

    My problem is one that I was experiencing right in the beginning. It all works beautifully and boots into Ubuntu only to fail to load X. If I look at the boot process in more detail, I see a whole string of events failing due to a read only file system.

    Has anyone experienced this before?

    Thanks

    • John Jiang says:

      Do you get a terminal at all? You don’t need to load x to install guest additions. As long as you have access to the terminal just cd into the cdrom and install it. Alternatively, just grab the guestadditions iso, burn it to disk, boot into ubuntu natively and install it that way. I’ve never tried it though so cannot guarantee it to work.

      • Anonymous says:

        Hi John

        Sorry for the late reply and thanks for your assistance. I do get a terminal but I can do absolutely nothing constructive as I get permission errors “Read-only file system”. Even it I could somehow do something, almost all processes that Ubuntu tries to load on boot fails due to the same errors. I’m going to try setup the vmdk again from scratch and let you know.

        Thanks

  • craig says:

    Everything works great right up until grub tries to load the linux partition.
    Filesystem type unknown, partition type 0×83
    kernel /boot/vmlinuz-2.6.26-2-686 root=/dev/sda2 ro quiet

    Error 17: Cannot mount selected partition

    It works fantastic when I boot normally, grub comes up and boots linux no problems.. Any idea’s what might be causing this?

  • [...] Ubuntu 9.10 got released several weeks ago and people have been asking about how to get my old tutorial working for [...]

  • mart says:

    Although I have followed the steps described in the tutorial (did it 5 times actually), I keep getting the following error from Grub menu running in Virtual Box :

    Error 15 : File not found

    Can someone help me please?! I would love to see this work!!

  • Gootsch says:

    hello..

    i use windows 7 and it was no problem to start the cmd as admin and create the vmdk. but virtualbox cannot access the vmdk any more. do i have to run virtualbox as admin? this is not the way i like it. how can i avoid this?

    thx,
    gootsch

  • Neil says:

    Great tutorial, still useful today.

    A couple of comments:

    1) If you upgraded to 9.10, your booter was not upgraded to GRUB2, so upgrading Ubuntu users can still use this tutorial. (ie– I upgraded from 9.04 to 9.10 using Synaptic and this tutorial worked fine. If you performed a fresh install of 9.10, use the other tutorial noted at the top.)

    From the Ubuntu site: “Existing systems will not be upgraded to GRUB 2 at this time, as automatically reinstalling the boot loader is an inherently risky operation.” (note the “as of this time” however…)

    quoted from:
    http://www.ubuntu.com/testing/karmic/beta

    2) If you are following this installation, you probably have some third party video driver which won’t work as a Virtualbox guest, even with Guest Additions installed (Nvidia or ATI drivers for instance). When you boot up the VM, Ubuntu will probably struggle through a few boot attempts until it finally gives up and offers you a low-res option. Take it and go alter the /etc/X11/xorg.conf (after backing up your original). You will need a Virtualbox-friendly xorg.conf which supposedly is installed automatically, but was not for me. I found a workable xorg.conf in this thread, but do a search for more options if you wish:

    http://forum.notebookreview.com/showthread.php?t=436427

    Great tutorial, thanks for posting it.

 




Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>