I hear and I forget. I see and I remember. I do and I understand. — Chinese Proverb

Leave a comment

Dual Boot and Virtualize same partition on Mac

I recently installed Linux Mint on my old MacBook and set it up to dual boot. I needed this for some tools that I was developing for my research. However all my documents were still on the Mac installation and going back and forth on the dual boot would be counter productive hence with some google magic, found out a guide by Whitson Gordon on how to run the dual boot installation on a virtual machine. He suggested using Parallels or VMWare Fusion (not free) for Mac, however I made some changes and used VirtualBox (free) instead. This is how:

  1. Firstly you would need the dual boot installation. There are several guides out there, I used the rEFIt method.
  2. Create the Virtual Machine (vmdk) file. I created this in a separate folder called “vmstuff” in my home directory.
    • You’d first need to get the id of the physical partition Linux is installed on. Run “diskutil list” without the quotes. It would be something like “disk0s4“.
    • Run the following command to create the vmdk (in my case mint.vmdk) file using the partition id found in the previous step. Please note “~” refers to your home directory in both Mac and Linux.
    • sudo VBoxManage internalcommands createrawvmdk -filename ~/vmstuff/mint.vmdk -rawdisk /dev/disk0s4
  3. Create the GRUB iso file.
    • You have to copy the required GRUB files in to a specific directory structure. So open the terminal and create a directory called “iso”, then another directory called “boot” inside “iso”, then another directory called “grub” inside “boot”. So you’d have ~/iso/boot/iso as the directory structure.
    • Now run the following two commands.
    • cp /usr/lib/grub/i386-pc/* ~/iso/boot/grub
    • cp /boot/grub/grub.cfg ~/iso/boot/grub
    • Customize the Grub menu by editing the grub.cfg file you copied. It’s your preference. Personally I don’t see any reason why you would even need a Grub menu for the VirtualMachine. Changing this file will not effect the original Grub menu that you see when you dual boot.
    • Now after editing the menu to your preference, create the iso file.
    • grub-mkrescue -o boot.iso ~/iso/
    • If you get an error saying “xorriso: not found“, then do an apt-get and install “xorriso“.
    • You would end up with an iso file called “boot.iso“, which you must copy back to the Mac installation. You can either mount the linux partition from Mac, or just use a flash drive to copy it back. If you chose to mount the Linux partition from Mac, make sure you unmount it before proceeding with step 4.
  4. Start the new virtual machine in VirtualBox.
    • Start VirtualBox, you would need sudo/root level to do the next steps.
    • Create a new virtual machine, choose the desired RAM, BUT choose to use an “Existing Virtual Hard Drive File”, and choose the vmdk file that you created in step 1, and press create.
    • In the storage settings, add the boot.iso file created in step 3 to the “Controller:IDE”.
    • Start the virtual machine and hopefully it would work.

For more details it would be worth having a look at the original article I used as my guide.