Refining application shortcut for shared BootCamp / VirtualBox Windows VM
Here’s a follow-up to my previous posts on sharing Windows 7 in BootCamp and VirtualBox and launching a VirtualBox VM directly through an icon shortcut.
Concerning this topic I was asked if it’s possible to have the BootCamp partition only umounted upon startup of the Windows VM.
My original post referred to creating the file /etc/rc.local (or just editing it, if it already existed) and adding these commands in there:
# grant VirtualBox permissions to Boot Camp partition
#
sudo chmod 777 /dev/disk0s3
diskutil umount /Volumes/BOOTCAMP
The method described basically causes the system to grant permissions for raw partition access and permanently umount the BootCamp partition during bootup.
If you however want the BootCamp partition only umounted upon startup of the Windows VM then please proceed as outlined below.
First of all, edit your /etc/rc.local to just include these lines:
# grant VirtualBox permissions to Boot Camp partition
#
sudo chmod 777 /dev/disk0s3
This will cause the permission to be properly set upon boot of OS X, which is still required. The partition however will not be umounted and thus appear on your Finder as usual.
Now, assuming that you implemented the application shortcut method, you need to change the application launcher like this from your Terminal:
cd "VirtualBox VMs/Win7onMBP"
cat > "Windows 7.app/Contents/MacOS/startvm" << EOF
#!/bin/sh
diskutil umount /Volumes/BOOTCAMP
[ ! -d /Volumes/Bootcamp ] && /usr/bin/VBoxManage startvm Win7onMBP
EOF
This will try to umount the BootCamp partition automatically when you click the icon.
However, I’ve added an additional safety switch in there: I’m checking if the BootCamp partition is still mounted at /Volumes/BOOTCAMP. VirtualBox will only start if the BootCamp partition is not mounted. This will help in preventing ugly issues with partition access.
August 11th, 2011 at 9:40 pm
This is great! You’ve got the best tutorial on the web about how to do this. Thank you.
I only have three points to add:
1) Lion usually wants /dev/disk0s4 and -partitions 4.
2) I had to run the VBoxManage command w/ superuser privileges (i.e. sudo VBoxManager …) and then “sudo chown *” the resulting files.
3) Your script unmounts the Boot Camp partition before running the virtual machine. Is there any way to modify the script to remount it once the virtual machine shuts down?
Thanks again.