2012-04-17

Use natively installed Ubuntu in VMware Fusion (Mac)

This post is an extension to my article about setting up a triple-boot Mac.

It describes how to use a linux partition from a natively installed linux in VMware Fusion on a Mac. I did this with Ubuntu 11.10 after I had set up my triple-boot system and therefore I'm able to boot the same Ubuntu both natively and in a virtual machine using VMware Fusion in Mac OS X.




1. Create a new virtual machine


First of all, you have to create a new virtual machine.

  1. click on "Create New"
  2. select "Continue without disk" and then "Create a custom virtual machine"
  3. select "Linux" and "Ubuntu 64-bit" on the next page
  4. click on "Finish" or "Customize Settings" if you want to change something (like the memory or number of processors)
  5. save the file

2. Create a new virtual raw disk based on the Ubuntu partition


To be able to use the physical ubuntu partition as a virtual disk in VMware, you have to create a new "raw disk" using the vmware-rawdiskCreator which is included in the VMware Fusion.app.
  1. open a terminal
  2. navigate to the VMware Fusion.app/Contents/Library folder
    "cd /Applications/VMware\ Fusion.app/Contents/Library/"
  3. list all available partitions with
    "./vmware-rawdiskCreator print /dev/disk0"
  4. create the rawdisk (in my case the linux partition is partition 4) and save it to the folder of your created VM (I named the file "ubuntu-partition")
    "./vmware-rawdiskCreator create /dev/disk0 4 ~/Documents/Virtual\ Machines.localized/Ubuntu\ 64-bit.vmwarevm/ubuntu-partition ide"

    The tool will create two files ("ubuntu-partition.vmdk" and "ubuntu-partition-pt.vmdk")
  5. to set the new virtual disk file as the default hard drive in the VM, go to the folder of the VM, open the .vmwarevm file (in Finder: right-click and select "Show Package Contents") and edit the file with the extension .vmx in a text editor.

    Add or edit the following lines
    ide0:0.present = "TRUE"
    ide0:0.fileName = "ubuntu-partition.vmdk"
    ide0:0.deviceType = "rawDisk"

    and remove the current disk entry (look at the lines starting with "scsi0:0").

When I started the VM after these steps, I got an error from grub saying "No such partition".  Why? Well, the problem is that I installed GRUB directly to the partition to boot it from rEFIt in my triple-boot setup. But in the VM this doesn't work (maybe because there is only this partition and it is not bootable)!
So, I had to find a way to boot ubuntu in the VM with a different GRUB installation than on the physical partition.


3. Make it bootable in VMware Fusion


Finally, I found a solution/workaround for the problem described above:

  1. add a small new virtual disk to the VM
    (Settings... -> Add Device.. -> New Hard Disk -> Add...)
  2. boot the VM with a live system like GParted or the ubuntu installation disk (yes, the VM has a BIOS and you can open a boot menu or change the boot order pressing "Esc" ;-) )
  3. create a partition on the new virtual disk (ext3) and flag it as bootable
Now we have to install GRUB to the MBR of that virtual disk:
  1. boot the VM from the ubuntu live system
  2. once it is started:
    Open a terminal and run "sudo fdisk -l" to find out the partition where the real ubuntu system is installed
  3. mount it using "sudo mount /dev/sda4 /mnt" (assuming that the ubuntu partition is /dev/sda4)
  4. install grub to the MBR of the new virtual disk:
    "sudo grub-install --root-directory=/mnt /dev/sdb"
    (assuming /dev/sdb is the small virtual disk)
  5. reboot the VM and setup the VM-BIOS to boot from the new (small) virtual disk where you installed GRUB

Now it should be possible to boot ubuntu in the VM!



BUT:
It's  not possible anymore to boot ubuntu from rEFIt! ;-) But there is also a solution to that:



4. Reinstall GRUB to the physical partition


You also have to reinstall GRUB to the ubuntu partition to be able to boot ubuntu from rEFIt as before.
  1. boot your Mac to the ubuntu live system
    CAUTION: You need to insert both the installation DVD and the USB-stick and hold down "C"
  2. open a terminal and follow the steps from above to find and mount the ubuntu partition to the live system, e.g.:
    "sudo fdisk -l"
    "sudo mount /dev/sda5 /mnt"
  3. reinstall GRUB to the partition (NOT to the MBR of your disk!!!)
    "sudo grub-install --root-directory=/mnt /dev/sda5 --force"


Now it should be possible to boot ubuntu from rEFIt AND also from VMware Fusion!

15 comments:

  1. Awesome stuff. Can't say enough about these posts. Can Fusion just automatically see the window partition like it can with bootcamp or is there another process similar to this one?

    ReplyDelete
    Replies
    1. Thanks. ;-)

      Unfortunately, I wasn't able to setup the Windows partition in VMWare Fusion. It doesn't work if you try to just configure it as a Bootcamp partition. But I didn't spend much time on that because I don't really need to boot Windows in a VM.

      But if anyone finds a way to boot the Windows partition in Fusion, please let me know. :-)

      Delete
    2. i dont really need it either but it might be nice. im waiting till i start my summer job and have enough to purchase a SSD and RAM upgrade and then will try triple booting that using your other post. plan on doing some experimenting with it. ie Ubuntu 12.04 and Mountain lion. I'll let you know how it goes. Btw, have you upgraded to fusion 4?

      Delete
  2. Thank you!

    Your post on creating a triple-boot system was incredibly helpful. After getting things working, being able to boot the Linux partition was the last thing I could not get to work.

    I am using the VMWare Fusion Technology Preview, since the current release of VMWare Fusion does not work with Windows 8 properly.

    Unfortunately your above instructions did not work, but I finally found a way. Create the custom VM for Ubuntu, like you explain above, then open the directory under ~/Documents/Virtual\ Machines/Ubuntu\ 64-bit and see what the default drive is called. In my case, it was called "Virtual Disk.vmdk"

    Remove all the files for the existing virtual disk. Then go to the "vmware-rawdiskCreator" command, like you outline above, but instead of "ide", use "lsilogic" for the disk type, then save it to the same location where the old default drive was saved. Presto, I got the "grub rescue" screen.

    For anyone who is lazy (like I was) regarding the boot partition, you can download the latest version of Super Grub Disk, add it to the VM and set the startup disk to CD/DVD. That way you can boot right away without having to setup grub any differently on the disk.

    Thanks again! Have a great day :)

    ReplyDelete
    Replies
    1. Hi Joshua!

      Thanks for your comment and your hints about the VM!

      Of course, using Super Grub Disk is a really easy and comfortable way to boot Ubuntu in the VM! I don't know why I didn't try that! ;-)

      Delete
  3. THANK YOU to both Fabian and Joshua!

    For VMware Fusion 5 and Ubuntu 12.04, I used a combination of the original approach and Joshua's approach. I followed parts 1 and 2 of the original approach, then set the VM to boot from a Super Grub2 Disk ISO, and everything seems to work. I also gave the VM an additional CD drive, in case I ever want to use real CDs or other ISOs with it.

    ReplyDelete
    Replies
    1. Hi.

      Can you detail how you used super grub 2? I have downloaded the iso but no idea what to do with it?
      Thanks

      Delete
  4. I haven't tried this yet, but it seems like you could also add an entry in grub.conf for your VM boot to specify the "root" to your kernel (root="/device_path") as it is now seen through the VM "bios".

    My problem is that I'm trying to avoid using the hybrid mbr on the mac (all my boots are pure EFI now) and my linux partitions are all above 4 so I can't use mbr anyway. So far vmware only uses the mbr so rawdiskCreator fails. I read somewhere you can edit the hybrid mbr adding only the partitions you want to keep it under 4.

    Super Grub2 is a good idea. Might work for my problem.

    ReplyDelete
  5. this vid shows how to do everything. both windows and linux virtulisation, using super grub 2

    http://www.youtube.com/watch?v=zNYXWEdVivo

    ReplyDelete
  6. snowmusicman5/22/2013 2:40 AM

    Hi,

    thx for that vid! I had my LMDE partition quickly running as a VM in my Hack. One problem I had, was that I was using the nvidia proprietary drivers. Only after I changed the driver in my xorg.conf from "nvidia" to "vmware" was I able to startx.
    Is there a way to tell the VM to start with a specific driver? It's a bit annoying having to manually change drivers when switching from VM to native mode. Anyway, thank you all!

    ReplyDelete
  7. Thanks so much for this tutorial. It was incredibly useful.

    ReplyDelete
  8. Easier just to remove all disks, add a new 'ide' disk in the gui, and replace the file vmware creates with your 'file' created from step 1. Works with new vmware, where old process doesn't seem to work. Just get 'corrupted vmx file'.

    ReplyDelete
  9. So I followed the steps, but I get Operating System not found.. :S

    I did

    Ignacios-MacBook-Pro:Ubuntu (64 bits).vmwarevm nacho$ diskutil list
    /dev/disk0 (internal, physical):
    #: TYPE NAME SIZE IDENTIFIER
    0: GUID_partition_scheme *251.0 GB disk0
    1: EFI EFI 209.7 MB disk0s1
    2: Apple_HFS Os X 210.0 GB disk0s2
    3: Linux Filesystem 32.8 GB disk0s3
    4: Linux Swap 8.0 GB disk0s4
    Ignacios-MacBook-Pro:Ubuntu (64 bits).vmwarevm nacho$

    Ignacios-MacBook-Pro:Ubuntu (64 bits).vmwarevm nacho$ ./vmware-rawdiskCreator create /dev/disk0 3 ~/Documents/Virtual\ Machines.localized/Ubuntu\ \(64\ bits\).vmwarevm/ubuntu-partition ide

    Changed the vmx file
    And got that :-/

    ReplyDelete
  10. Wow man, this is insane. I got the raw Ubuntu partition to boot on VMWare Fusion 7 on my cylinder Mac Pro (2013). I haven't tried rebooting from rEFInd yet (and thus encounter the other problem you detail), but I still wanted to say wow... nice work.

    ReplyDelete

Copyright

Creative Commons License
All the content in this blog is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.