Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to format an SD card from my Linux virtual machine. I have a built-in SD card reader in my laptop. I tried using VirtualBox and VMware Player and installed Ubuntu 10.04 guest. None of them are showing the SD card reader as a device. I can access the SD card from the Windows host.

I am not interested in solutions using shared folders as I want to access the SD card as hardware (it should show up in /dev).

I basically want to set up the SD card for BeagleBoard, but I don't want to install a physical Ubuntu on my PC.

share|improve this question

migrated from stackoverflow.com Jan 1 '12 at 3:06

This question came from our site for professional and enthusiast programmers.

    
Had you installed virtualbox guest addons? –  tumchaaditya Aug 6 '12 at 9:46

7 Answers 7

On newer MacBook Pro's the SD card slot is no longer exposed as a USB device. Because of this you'll need to attach the raw device to the VM in order to gain raw access to the whole card. Full documentation is in the Advanced Storage Configuration section of the VirtualBox documentation.

As clearly stated in the docs:

Warning - Raw hard disk access is for expert users only. Incorrect use or use of an outdated configuration can lead to total loss of data on the physical disk. Most importantly, do not attempt to boot the partition with the currently running host operating system in a guest. This will lead to severe data corruption.

As a quick guide these are the steps to attach the device to a linux VM:

  1. Identify the raw disk block device on your host system

    1. Insert the SD card into the slot
    2. Open a Terminal and type "mount". You'll see output identifying the mounted volume from your SD card. On my system I get the following

      $ mount
      /dev/disk1 on / (hfs, local, journaled)
      devfs on /dev (devfs, local, nobrowse)
      map -hosts on /net (autofs, nosuid, automounted, nobrowse)
      map auto_home on /home (autofs, automounted, nobrowse)
      /dev/disk2s1 on /Volumes/NO NAME (msdos, local, nodev, nosuid, noowners)`
      
    3. In my case the "NO NAME" volume is the SD card, so I take note of the /dev/disk2s1 part. In this particular case the s1 part represents a partition (slice) on the raw device, so the part we'll use later is just the /dev/disk2 part.

  2. Open Disk Utility and "Unmount" the volume. Do not "Eject" it. Note that you may need to unmount the volume once in a while during the next steps as I found OSX would automatically remount it at random.
  3. Now we set up VirtualBox to be aware of the raw device with the following command in the Terminal.

    1. Note that the /path/to/file.vmdk can be put anywhere, though it's a good idea to store this in the guest VM folder such as ~/VirtualBox VMs/guest-vm/sdcard.vmdk
    2. Note that the -rawdisk we use doesn't reference the partition (slice) but only the block device as a whole.

      $ VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk -rawdisk /dev/disk2
      
  4. Next we attach the raw disk to a guest VM within the VirtualBox UI

    1. Ensure the guest VM is not running.
    2. Open the settings area for the guest VM
    3. Click on "Storage" in the toolbar
    4. Next to the controller click on the icon to "Add Hard Disk"
    5. Select "Choose existing disk"
    6. Navigate to the /path/to/file.vmdk you used in step 3 and select it
    7. You should now be returned to the Storage tab and see your file.vmdk in the list.
  5. Start the VM
  6. Depending on whether you have a GUI or not the SD card may or may not automatically mount. If you need to mount is manually it is simply exposed as another standard block device, so on my guest this was exposed as /dev/sdb.

Update

It seems some people may have trouble with accessing the raw device in step 3.2 or 4.6. Attempts to run some of the commands with sudo won't help as VirtualBox will be running as your logged in user and still won't be able to access the raw device correct or the generated vmdk file.

The following steps should help, though I haven't tested them.

  1. Check the account you're using on OSX has Admin privileges in the System Preferences/Users section. There's a good chance it should also be the primary account on the system for raw device access to work.
  2. Check the raw disk permissions

        $ ls -l /dev/disk2
        brw-r----- 1 jinn staff    14,  5 Aug 26 15:33 /dev/disk2
    

    These permissions must match your current logged in user account:

        $ id
        uid=501(jinn) gid=20(staff) ...snip...
    

    The permissions on the device should also permit your usual user account to both read (r) and write (w) to this device. DO NOT CHANGE PERMISSIONS ON THE DEVICE UNLESS YOU ABSOLUTELY KNOW WHAT YOUR'RE DOING.


Update #2

Turns out OSX Mountain Lion created the device with "root:operator" privileges and 0640 permissions. Unfortunately for now the only way to gain access to this device is to "sudo chown $USER" it to your current user each time you insert the device, however this is not recommended unless you really understand what you're doing. Hopefully either Apple or VirtualBox will find a more suitable solution.

share|improve this answer
    
Any advice on what to do if you don't see your device with mount? My host system is Windows 7 with a built-in SD Card Reader. I've tried accessing the card from an Ubuntu 10.04 system through VMware Player and VirtualBox, but without any luck. –  GrandAdmiral Apr 9 '13 at 22:13
    
Sorry @GrandAdmiral, no idea about details on Windows. However the key point is in the first paragraph: "you'll need to attach the raw device to the VM in order to gain raw access to the whole card". The same principle will apply on any host system regardless of OS. –  JinnKo Apr 13 '13 at 13:32
2  
In Mountain Lion, got diskarbitrationd mounting partition from sdcard, to stop this : $ sudo launchctl list | grep diskarbitrationd 188 - com.apple.diskarbitrationd $ sudo kill -SIGSTOP 188 # pauses diskarbitrationd, disabling automount $ sudo kill -SIGCONT 188 # resumes diskarbitrationd, reenabling automount –  kenji Aug 21 '13 at 14:47
    
Thanks @kenji, that's an additional great tip for Mtn Lion users (I struggled a bit with the automount issue myself). My detailed instructions on the VirtualBox forums would benefit from this tip; I'll add a link to your comment there and below. Thanks again. –  likethesky Oct 25 '13 at 0:04
    
I followed this guide but had permission issues, I then preformed a chmod 777 on the device and it worked fine. More details here: balage.blogs.balabit.com/2010/10/… –  Samantha Catania Oct 19 at 16:11

Answer for Windows 7 users

  1. Get the DeviceID of your SD card reader.

    You'll need a card in the drive, mounted by windows.

    Enter this command

    wmic diskdrive list brief
    

    It should look something like this:

    C:\Users\Sandy Scott>wmic diskdrive list brief
    Caption                      DeviceID            Model                        Partitions  Size
    WDC WD7500BPKT-75PK4T0       \\.\PHYSICALDRIVE0  WDC WD7500BPKT-75PK4T0       3           750153761280
    O2Micro SD SCSI Disk Device  \\.\PHYSICALDRIVE1  O2Micro SD SCSI Disk Device  1           3964584960
    

    The last device is the SD card reader, so the DeviceID is \\.\PHYSICALDRIVE1

  2. Create the link file to the SD card

    Open a command windows as Administrator

    "C:\Program Files\Oracle\VirtualBox\VBoxManage" internalcommands createrawvmdk -filename "%USERPROFILE%/Desktop/sdcard.vmdk" -rawdisk "\\.\PHYSICALDRIVE1"
    

    This assumes the default installation path - change it if you need to. (Ensure quotes are around the rawdisk argument.)

    The .vmdk file is a link to the SD card, you can put it anywhere on your host system, but this command just puts it on your desktop for convenience.

  3. Follow steps 4-6 in JinnKo's answer, the only minor tweak is that you need to start VirtualBox as an Administrator

  1. Next we attach the raw disk to a guest VM within the VirtualBox UI
    1. Ensure the guest VM is not running.
    2. Ensure VirtualBox is not running
    3. Start VirtualBox by right-clicking on it and choosing "Run as administrator"
    4. Open the settings area for the guest VM
    5. Click on "Storage" in the toolbar
    6. Next to the controller click on the icon to "Add Hard Disk"
    7. Select "Choose existing disk"
    8. Navigate to the /path/to/file.vmdk you used in step 3 and select it
    9. You should now be returned to the Storage tab and see your file.vmdk in the list.
  2. Start the VM
  3. Depending on whether you have a GUI or not the SD card may or may not automatically mount. If you need to mount is manually it is simply exposed as another standard block device, so on my guest this was exposed as /dev/sdb.
share|improve this answer

You are most likely missing the extensions if your SD reader is using your USB controller.

enter image description here

Under File > Preferences, follow the pic. Add and point to the downloaded extension.

enter image description here

Restart your Virtual Machine and you should have access to USB devices.

share|improve this answer
    
Hi, I tried this solution and installed the virtualbox extension pack but still no success. I am doing this in macbook if that makes any difference. Also, in my macbook system profiler, the sd card reader is not listed under USB devices but as a separate category called "card reader". Also, I am able to see the devices which are listed under USB in virtualbox. –  Punit Soni Jan 2 '12 at 22:16

I had a lot of troubles getting the solution by JinnKo to work, mostly due to my being on Mountain Lion (OS X 10.8) ... But with his kind assistance, I've solved the issues.

The full solution is detailed here.

However, the essence of my solution--for Mountain Lion users--is as follows (use JinnKo's steps above, but insert my step here before running the 'VBoxManage internalcommands createrawvmdk [...]' command (that is, in between his steps 2 & 3):

** Particularly for Mtn Lion ** Make sure you are the owner of this device. On 10.8 Mtn Lion, you will probably find that you aren't. Check it by doing:

ls -l /dev/disk*

With the '*' you will see ALL your disk devices, you can also do: ls -l /dev/diskX to just see 'X', for instance, I did:

ls -l /dev/disk5

On Mtn Lion ( 10.8.x ) you will see something like:

brw-r----- 1 root operator 1, <today's date/time> /dev/diskX

Where 'X' is your device number, like the '5' in /dev/disk5 ...

On Lion ( 10.7.x ), Snow Leopard (10.6.x ), or perhaps earlier versions of OS X, you will--if your username is 'brad'--likely see something like:

brw-r----- 1 brad operator 1, <today's date/time> /dev/diskX

Where 'X' is your device number, like the '5' in /dev/disk5 ... If you are the owner, then all's good, nothing to do here, go to the next step, that is, the createrawvmdk step (in @JinnKo 's great instructions above).

If you are not the owner (but 'root' or some other user is), then either (a) login as that admin user or (b) do the following (again, be very sure you are using the correct device number/letter here!):

* CAUTION * The below is only for those who want to risk permanently destroying data on their hard drive or flash storage drive. DO NOT DO THIS if you aren't sure you know what you're doing:

sudo chown <your username> /dev/disk5
sudo chown <your username> /dev/disk5s1

* CAUTION * DO NOT DO THIS if you aren't sure you know what you're doing. The above is only for those who want to RISK permanently destroying data on their hard drive or flash storage drive.

You will need to do it for ALL of your slices (s1, s2, s3, ... however many there are). For example, my username is 'brad', so I did: sudo chown brad /dev/disk5, then sudo chown brad /dev/disk5s1, then for s2, and s3 (since I had 3 existing partitions or slices already).

If you haven't partitioned the SD card, then you may only need to do the sudo chown <your username> /dev/diskX once (without doing any of the slices/partitions)

Hope this helps some other poor Mtn Lion users out there!

share|improve this answer
    
Excellent solution. I would have been lost without this write up. Thank you very much! –  ggutenberg Sep 14 '13 at 2:02

I've so far failed in finding a way to do this directly, even with a USB card reader (it put the card on /dev/dm-1 rather than the expected /dev/mmcblk1).

My workround was to create a 4 GB virtual drive in VirtualBox. This could then (as /dev/sdb) take an install of BeagleBoard Ubuntu as documented.

I then shut down the VM, converted it to a RAW DD file and used DD to put it on the card: (on the host Mac):

VBoxManage clonehd UbuntuBeagleImage.vdi UbuntuBeagleImage.dd --format RAW
sudo dd if=UbuntuBeagleImage.dd of=/dev/rdisk(NUMBER) bs=1m

(/dev/disk2 in my case, but triplecheck as getting it wrong could bork your hard disk drive).

The dd command took about 1 hr 20 min!

I hope this helps. I'm still working towards an easier and quicker way - we shouldn't need to transfer 4 GB of data for 600 MB of OS.

share|improve this answer

On newer MacBook Pro's the SD card slot is no longer exposed as a USB device

To overcome this problem you can simply use an external Usb Memory Card Reader (i.e. sd card to usb adapter) instead of built-in card reader. It will expose your sd card as a USB device so that you can mount it easily just like any usb device. They're cheap devices and would be an acceptable solution considering all the hassle in the other way.

share|improve this answer

For me the solution was to turn-on USB device with SD card, using
Devices -> USB devices ->My card reader,
and after few seconds new disks appear in my VM.

I have installed VirtualBox Extensions Pack before that.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.