One thing that bugs the hell out of me is when a seemingly simple task isn’t so, especially on the Mac. For example, I use VMWare Fusion on my Mac and I can’t add a raw partition or disk to any of my VMs. So, for example I can’t plug up a USB hard drive to my Mac with a partition formatted with Reiser-FS and directly mount that partition in a virtual machine. But, through some googling around and some trial and error I figured out how to do it. This tutorial isn’t for the faint of heart, but if you’re comfortable with a terminal in OS-X you’ll be fine.
First thing that you need to do is find out the name of the raw disk you want to use. To do this, startup your OS-X Disk Utility application (/Applications/Utilities/Disk Utility.app). Once inside, control-click on the device that you want to use on the left, and select Information OR click on the disk and hit CMD-I OR click on it and go to the File Menu, and select Get Info. Control clicking should look like…
Next, you’re looking for what it says under Disk Identifier, seen below highlighted in red.
You’ll see in my example above I am looking at disk4. This is IMPORTANT to remember for the commands below… now, you need to decide which partition you want to use, and we’ll need the Terminal for this. Run the following command, replacing disk4 with whatever disk identifier your disk has.
sudo /Library/Application\ Support/VMware\ Fusion/vmware-rawdiskCreator print /dev/disk4
That command should ask for your password, and the results should look something like (although yours WILL be different) the following…
Nr Start Size Type Id Sytem
– ———- ———- —- — ————————
1 63 401562 BIOS 83 Linux
2 401625 3919860 BIOS 82 Linux swap
3 4321485 73834740 BIOS 83 Linux
The above is a typical Linux installation with a 200MB boot partition (partition 1), swap (partition 2) and the root (/) partition (partition 3). This particular example I am doing because I wanted to backup all the files on this disk before reformatting it. So I want to grab the root partition, which is partition 3 on this list. You need to use this partition number in the next command to actually create your raw disk for VMWare Fusion to use…
sudo /Library/Application\ Support/VMware\ Fusion/vmware-rawdiskCreator create /dev/disk4 3 /MyRawDisk4Partition3 lsilogic
Unfortunately due to the fact that you need to run sudo for this command, the resulting files in the root of your OS-X install are now owned by root, with 600 (locked down) permissions. You need to set your user as the owner to fix this problem…
sudo chown yourunixusername /MyRawDisk4Partition3*
NOTE: Replace the “yourunixusername” with your actual OS-X “short” unix user name. This can be found by opening a new terminal and typing the command pwd. It should show something like “/Users/afarley” making afarley my username.
You should have two files in your / partition named MyRawDisk4Partition3.vmdk and MyRawDisk4Partition3-pt.vmdk.
Now to put this virtual disk into one of your Virtual Machines, that was the point of this tutorial after all! Problem is… Fusion isn’t very friendly about this. When you create a raw disk device like this, it doesn’t let you just +(add) the device in the “Disks” settings area. You must manually add it to the configuration file of the VM you want to add this disk to. In my example I have a simple Linux VM with a single disk (bootcamp-partition) as a SCSI device. So I need to add a second SCSI drive to this machine by adding the following to the configuration file. Here is the procedure…
- First, make sure your VMWare Fusion application is not running (this is VERY important).
- Second, navigate to your Virtual Machines folder where the configuration files are stored (typically ~/Documents/Virtual Machines.localized/).
- Third, go into the folder that is the VM you want to edit.
- Fourth, make a BACKUP of your configuration file (should be the only .vmx file in this folder) incase you mess it up, easiest way is to right-click on it and select duplicate, or just click on the .vmx file and hit CMD-D. If you cannot see file extensions then you should enable them, or do this in the terminal. Do NOT duplicate this whole folder, that would be a huge waste of space.
- Fifth, open up this .vmx file in your favorite text editor! Mine is TextMate.
- Sixth, add the following lines to this file, preferably right after your scsi0:0 similar drive declaration. Also, search through the rest of the .vmx file for ’scsi0:1.present = “FALSE”‘. Usually by default they have this somewhere littered towards the end of the config file. Just delete this entry since you have it set to true in the additions above.
scsi0:1.present = “TRUE”
scsi0:1.virtualDev = “lsilogic”
scsi0:1.fileName = “/MyRawDisk4Partition3.vmdk”
WARNING: This above example is assuming you already have a scsi device setup as your primary disk so that SCSI is already enabled for your VM. If you do not, there are a few other options that you need to add and this will get messy. If this is your case… you should first go into your Fusion settings interface and add a virtual SCSI device just so SCSI is enabled. You cannot use IDE for raw devices imho.
Now save and close this file… startup your VMWare, and launch this VM! It will (of course) ask you for your administrator credentials to access a raw device, and then it will start. Hopefully, with your new drive in there. You should be able to fdisk it and see the drive’s raw partitions, in my case…
# fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0×000e91cb
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 25 200781 2d Unknown
/dev/sdb2 26 269 1959930 2d Unknown
/dev/sdb3 270 4865 36917370 83 Linux
The reason you don’t see sdb1 and sdb2’s actual partition types above, is VMWare abstracts them and does this to recommend that you don’t access them. Access to them is not restricted though, you can still mount sdb1 and sdb2 if you wish.
NOTE: Because of how this process works, you will need to run through this whole procedure for every raw disk/partition you want to use.
NOTE2: This example will work also for passing through NTFS partitions into a Windows VM. Thought I’d mention it to not leave you Windows-junkies out! :)
That concludes my tutorial! If you ran into any problems or questions, leave a comment!
Trackback URL for this article:
|Share this article:|