VirtualBox direct access to SD Card in Windows

I’ve trying to get my Raspberry Pi working with a touchscreen (eGalax Touch).

This blog post has been an incredible help, but I stumbled at the very last hurdle – modifying the contents of the SD card.

You see, my compile system (Ubuntu 13.04) was in a virtual machine (VM) – VirtualBox running on Windows 7.

Windows 7 doesn’t know how to read the various linux filesystems, so they’re invisible, which means I needed to access to the whole, raw disk directly from the VM.

Here’s a step-by-step guide to directly mounting raw SD card in your virtual machine, so you can edit it.

  1. Get the DeviceID for you SD Card reader
  2. Open a command window as an administrator. (Press Start, type cmd, right click on cmd.exe in the list, and choose “Run as administrator”)

    type

    wmic diskdrive list brief
    

    and if your system is anything like mine you’ll get 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 top item is the main hard drive, the lower one is the SD card.

    The bit we’re interested in is the DeviceID, in this case \\.\PHYSICALDRIVE1

  3. Navigate to the VirtualBox directory
  4. Next thing you’ll need to find is the installation directory for VirtualBox. This is usually C:\Program Files\Oracle\VirtualBox\. You’ll know it’s the right one if it has lots of files starting with VBox in it.

    Go there by entering this command

    cd C:\Program Files\Oracle\VirtualBox
    
  5. Create the link file to the SD card
  6. VBoxManage internalcommands createrawvmdk -filename "%USERPROFILE%/Desktop/sdcard.vmdk" -rawdisk "\\.\PHYSICALDRIVE1"
    

    The file you’ve just created (sdcard.vmdk, on your Desktop) is a special link that lets a virtual machine access the SD card.

  7. Connect the VM to the SD card using the link
  8. Now, open VirtualBox as Administrator, and open the Settings for your virtual machine. Go to Storage -> Controller: SATA -> (right click) Add Hard Disk -> Choose Existing Disk and open the file you just created.

    Fire up the VM and you should be able to access the SD card in all it’s glory!

42 Comments

  1. hi Sandy,
    thanks for your post it helped me a lot.
    I’ve experienced some issues as my %HOMEPATH% was empty and generated errors during the sdcard.vmdk creation process.
    so I just skipped it and created the file in the virtualbox directory πŸ˜‰
    cheers
    Eric

    • Glad it helped – seems unlucky that you’ve encountered an issue with the environment variable at the same time. With hindsight %USERPROFILE% might have been a safer choice. (Post now edited)

    • What exactly did you do to solve that problem cause I’m having same issues here. Thanks for your help

  2. Hey Sandy,

    I tried the method you suggested but apparently I get an error while creating the .vmdk file.
    I used the command as mentioned above, but the error said that “Could not access the rawdisk ‘\\.\PHYSICALDRIVE1”. so the file was not created. Do you have any idea why this could have happened?

    Thanks for the help
    Aakar

    • The exact error is :

      “Cannot open the rawdisk ‘ \\.\PHYSICALDRIVE1’ : VERR_ACCESS_DENIED”

      • Off the top of my head

        • try to make sure nothing is trying to access it the card, so do it as the first thing after you insert it, and don’t open any files or even view it.
        • make sure that you start the command window as Administrator
  3. Pingback: Setup cjdns on Raspberry Pi | SplatCrashBang

  4. You are genius.

  5. Thank you for the brilliant guide.

    Most useful.

    I would like to add though that certainly on Windows 8.1 you will need to run the Virtual Box manager as administrator or you will get an error access denied when you attempt to add the drive to your virtual machine.

  6. bupthebroker

    I managed to create the image but now when i create files on the SD card from Windows (host) then Linux cannot see the files created from Windows and vice versa.

    • This sounds like an issue with the file system you are using – Windows and Linux arrange files on an SD card (or hard drive) in completely different ways, so can’t read each other’s data.

      This is the wrong process to do what you want – I would use the shared folders feature for this, which lets Virtualbox handle the translation between the two systems. Instructions on how to do that are here: https://www.virtualbox.org/manual/ch04.html#sharedfolders

      The only reason to do the complicated process I’ve described above is for the times when that translation won’t work, because you need to access the really low-level data on the card, and windows either can’t or won’t let you!

  7. Dude, YOU helped me a LOT !

    Actually I’m also trying to install the -same- touch screen to my RPi, with the same blog post you mentioned and also using a VM..!

    Cheers

  8. Michael Behrisch

    Hi,
    thanks for the help. Is it possible that you do not only have to modify the VM as administrator but actually can run it only as admin afterwards?

    Thanks for the help,
    Michael

    • That’s right, you have to run VirtualBox as Administrator whenever you want to access an SD card in this way. Not great, but understandable considering what’s going on under the hood.

  9. You must be genius!
    Thank you very much.

  10. Hi, I did all you said. I’m in the same trouble, but when starting my guest OS is aborted and doesnt work, Until I delete the SATA it finally boots

    • It might be trying to boot from your SD card rather than the guest OS system drive. I’m not very familiar with the subtleties controlling the boot sequence in Virtualbox, but you could try hitting F12 just after the machine starts and see if trying one of the options in that list lets you boot the main system.

  11. Hi !
    My Virtual machine crasches a few sec and message is.
    The I/O cache encountered an error while updating data in medium
    “ahci-0-1” (rc=verr_access_denied) Make sure theres is enough free space on the disk and that the disk is working properly.
    Operation can be resumed afterwards.

    Can u please adwise
    Brgds Patrik

  12. Im having the exactly same problem of Patrick above.
    Im using windows 10 on virtualbox.
    Any changes made on the sd card crashes the vm right after.

    Looks like the virtualbox donΒ΄t mount the sdcard on write mode.

    You guys have any ideas?

    thanks

    • Unfortunately, I have exactly the same problem as Patrick and jeferson -> everything went well, vmdk file created, VM launched as administrator, but right after logon to guest OS (also Windows 10), I am getting that error…

  13. Having the same issue as Patrik, Windows 7, virtual box running ubuntu 14. It seams intermittent, in that is happens at different stages each time I reboot and try manipulating the card.

  14. Hi Sandy,

    thanks for this helpful article. It works for me, a little different though: When I get to add the created link to the VM, it is rejected, when trying to add it to the existing SATA controller. If I add it one level higher though, (“Massenspeicher”, would be something like “mass storage”) it is accepted and then added to the existing SATA controller. I’m on VBox 4.3.30.

    Tchelovek

  15. AWESOME!!! Thanks Sandy….!

  16. Pingback: VirtualBox vo windows 10 a SD karta raspbian - zwieratkov blog

  17. Jesmond Gatt

    Thanks. Have you managed to interface the screen to the RPI? I am trying to interface the Kedei V5 screen to RPI3 B. I am writing new kernel since the one provided is old and the GPIOs on RPI are not working.

    Thanks for the help πŸ™‚

  18. I followed your instructions, but after creating vmdk file, I have to open the VirtualBox as administrator which is causing problem.

    If I open the Virtual Box as Administrator, I did not find any guest OS in the Virtual Box, looks like my guest OS is available only without administrator. How to overcome this problem?

    • I’m not sure, but it could be something to do with VirtualBox using the administrator windows profile, rather than your own. I’d suggest you try this:

      1. Find the path to the .vbox file by opening VirtualBox as you normally would, then right clicking on the VM and choosing “Show in Explorer”
      2. Open VirtualBox as an administrator, then click on the “Machine” menu, then “Add”, then find the .vbox file in the location you found in the previous step.
  19. Any way to get optimal performance? Transfer speeds are around 4mbps while on the host I get 30mbps+. Using a class 10 card.

  20. Am I able to partition the SD card on Centos in VirtualBox ?

    • I would have thought so, as the pass-through link is created to the physical device. Give it a try and see how it goes!

  21. Thank you for sharing! All of them must to perform with “Run as Administrator”

  22. Been trying to configure zero w for headless running kali but so far have been hitting walls to configure Wi-Fi & ssh & running gadget mode has been a waste of time it would seem as it still doesn’t appear. So either mounting this way or via live usb the way to go

Leave a Reply to Robert Cancel reply

Your email address will not be published. Required fields are marked *