Wednesday, 22 January 2014

Using an SD card with VMware Workstation virtual machines on a Dell M6600 (and maybe other systems as well?)

For some time I had pondered over how I might make SD cards, or other similar, non-USB, removeable media, visible to VMware Workstation virtual machines on my Dell M6600 laptop.
I have a few Raspberry Pi boards now, and I find using the linux tool dd the easiest way to prepare SD cards for them.
Until now I would usually find myself dusting off an old laptop that runs a real installation of Ubuntu 12.04 (Precise Pangolin) in order to be able to do this.

My particular setup with VMs is as follows:

Host machine: Dell Precision M6600 Mobile Workstation
Host OS: Windows 7 Professional 64-bit Service Pack 1
VMware Workstation 8.0.6
Guest OSs: Multiple Linux distributions, but particularly Ubuntu 12.04 and Debian 7

With a previous laptop that I had the SD card reader was, presumably, actually connected to the USB controller as when I inserted SD cards into the slot it would automatically appear as a Removeable Device that I could connect to a guest VM. This does not happen with the SD card reader in the Dell M6600. For information it is listed in Device Manager as "O2Micro Integrated MMC/SD controller."

I had a bit of a random, Eureka! moment the other day when I was thinking about something else entirely. As the SD card reader is not a USB device then presumably Windows is treating it as a physical disk?

To test this theory I opened Computer Management (press the Win Key or open the Start Menu and start typing Computer Management) and had a look. The device was listed, although still as a removeable device:



The next step then would be to see what VMware thought about connecting it to a VM as though it were a physical disk.

In VMware, go to "Edit virtual machine settings" (my VM was powered down at the time) for your VM then in the Hardware tab click Add. 
Select Hard Disk, click Next. Choose Use a physical disk (for advanced users), click Next.
Choose the correct Device, the numbers in the list correspond to the numbers in Computer Management. In my case it is PhysicalDrive2. Make sure Use entire disk is selected, click Next.
Accept the default file name for the .vmdk file, click Finish. It will then add the disk, click OK to leave the VM settings dialog.

At this point I powered on the VM, in this case it's running Ubuntu 12.04. Running sudo fdisk -l in a terminal gave an encouraging output:

Disk /dev/sdb: 15.9 GB, 15931539456 bytes
255 heads, 63 sectors/track, 1936 cylinders, total 31116288 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            8192    31116287    15554048    c  W95 FAT32 (LBA)
tom@tom-virtual-machine:~$

A quick test, writing the latest Raspbian image to the SD card, confirms that it is working:

tom@tom-virtual-machine:~$ sudo dd if=Desktop/2014-01-07-wheezy-raspbian.img of=/dev/sdb
5785600+0 records in
5785600+0 records out
2962227200 bytes (3.0 GB) copied, 375.895 s, 7.9 MB/s
tom@tom-virtual-machine:~$

Selecting Action > Refresh in Computer Management shows the new partition structure:

All that remains is to shut the VM down and remove the 'Hard Disk.' Then you can eject the SD card and use as normal.

8 comments:

  1. Thanks Tom!
    awesome job ;) I have a Sony Vaio SVT13 laptop and the same issue..
    Now I can write Raspberry Pi images without any problems :D

    ReplyDelete
  2. Hi Tom,

    Many Thanks, I thanks you, and my BeagleBoneBlack machines thank you -- you are rescuing them from Angstrom hell ... Even though I have a dual boot ubuntu/win7 -- I hate having to reboot just create a SD card, and unlike for my Raspberry PIs -- there is no easy windows way of creating a bootable image. On the other hand I have an embarrassment of riches in ubuntu VMs.

    Nick

    ReplyDelete
  3. Really glad I discovered your discovery. Thanks Tom, an outstanding contribution.

    ReplyDelete
  4. Have to redo everything again once restart the vm or remove the sdcard. Looking for solution that the vmware will auto detect the sdcard once it is ejected from windows(the host) or vice versa.

    ReplyDelete
    Replies
    1. Hi dante,

      If you have connected the SD card to the virtual machine as a physical disk then restarts of the VM should have no effect, provided nothing has changed on the host. (Specifically the enumeration of physical disks on the host needs to remain constant, which it probably will if the SD card is not removed. In theory, it should persist across host reboots, but I wouldn't rely on it.)

      Auto-detection is not applicable in this particular case, because of the hardware configuration in the M6600. The SD card reader in the M6600 is not a USB device, so VMware does not recognize it as a "removable device", and accordingly doesn't allow the usual removable device actions to be performed.

      Hope this helps.

      Delete