Page 1 of 1

Can't create SD card vmdk on guest: Ubuntu 12.04--2012 rMBP

Posted: 15. Aug 2012, 04:34
by likethesky
This question is for a new 2012 Macbook Pro (retina and it's running 10.8, Mountain Lion--poor me, eh? ;-)), running VirtualBox 4.1.18.

I've installed guest extensions, screen looks great/resizes, etc. and I *can* access another USB-based TTY device attached to the MBP USB port, via my Ubuntu guest OS, like with 'screen' and 'ls /dev/ttyUSB0' shows up, etc.

According to this excellent SuperUser answer on how to create a vmdk for one's SD card on new MBPs: http://superuser.com/a/458085/146236 (which unfortunately isn't working for me), one is supposed to--in JinnKo's step 3.2--do the following:
VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk -rawdisk /dev/disk2
Substituting for /dev/disk[your drive goes here], of course and using a good path for /path/to/.

Mine, for instance, looked like this when I entered it:

Code: Select all

VBoxManage internalcommands createrawvmdk -filename ~/VirtualBox\ VMs/Ubuntu\ 12.04\ Precise\ Pangolin\ i386/sdcard.vmdk -rawdisk /dev/disk1
But I get the following output when I execute the above:
VBoxManage: error: Cannot open the raw disk '/dev/disk1': VERR_ACCESS_DENIED
VBoxManage: error: The raw disk vmdk file was not created
I tried it with 'sudo ' in front, and it then seemed to work fine and gave me the following output:
RAW host disk access VMDK file /Users/brad/VirtualBox VMs/Ubuntu 12.04 Precise Pangolin i386/sdcard.vmdk created successfully.
But though that worked (with 'sudo'), I get the following when I try to "Add a hard disk" (to either the IDE Controller or the SATA Controller), it's not clear from JinnKo's SuperUser post referenced above which type of controller to use (I tried both IDE and SATA, but didn't add SCSI or anything else):
Failed to open the hard disk /Users/brad/VirtualBox VMs/Ubuntu 12.04 Precise Pangolin i386/sdcard.vmdk.
Permission problem accessing the file for the medium '/Users/brad/VirtualBox VMs/Ubuntu 12.04 Precise Pangolin i386/sdcard.vmdk' (VERR_ACCESS_DENIED).
Result Code: VBOX_E_FILE_ERROR (0x80BB0004)
Component: Medium
Interface: IMedium {53f9cc0c-e0fd-40a5-a404-a7a5272082cd}
Callee: IVirtualBox {c28be65f-1a8f-43b4-81f1-eb60cb516e66}
Any ideas what I'm doing wrong? I imagine I should be able to execute the VBoxManage command without sudo... ?

Re: Can't create SD card vmdk on guest: Ubuntu 12.04--2012 r

Posted: 16. Aug 2012, 17:08
by likethesky
Ok. *bump* :-) Sorry, I'm a newb. I did find a seemingly helpful thread, where I discovered this entry, which looked like it told me what I needed to try: viewtopic.php?f=1&t=333&sid=8a8d0cdbef4 ... 45#p162236

When I tried it (leaving out the partitions stuff, since I think that's only relevant to the OP's issue), here's what I got:
$ sudo umount /dev/disk1
$ sudo chown 666 /dev/disk1*
$ sudo VBoxManage internalcommands createrawvmdk -filename ~/Vir[...]\ i386/sdcard.vmdk -rawdisk /dev/disk1
RAW host disk access VMDK file /Users/brad/VirtualBox VMs/Ubuntu 12.04 Precise Pangolin i386/sdcard.vmdk created successfully.
$ sudo chown brad:staff ~/VirtualBox\ VMs/Ubuntu\ 12.04\ Precise\ Pangolin\ i386/sdcard.vmdk
However, when I continue to VirtualBox's GUI, choose Storage | SATA Controller | Add Hard Disk ... <button> and Choose Existing Disk ..., putting in the sdcard.vmdk listed above, I get the following error:
Failed to open the hard disk /Users/brad/VirtualBox VMs/Ubuntu 12.04 Precise Pangolin i386/sdcard.vmdk.

The medium '/Users/brad/VirtualBox VMs/Ubuntu 12.04 Precise Pangolin i386/sdcard.vmdk' can't be used
as the requested device type.

Result Code: NS_ERROR_FAILURE (0x80004005)
Component: Medium
Interface: IMedium {53f9cc0c-e0fd-40a5-a404-a7a5272082cd}
Callee: IVirtualBox {c28be65f-1a8f-43b4-81f1-eb60cb516e66}
Any further thoughts on what I need to do to solve this? (Perhaps I just don't know which type of controller I need? Or maybe the issue is back when I created the VMDK?)

UPDATE: Edited VBoxManage line above to show whole thing by cutting down the path [...]

FURTHER UPDATE: I have used both absolute paths as well as quoted paths in the above, with the same result. So for instance, I have issued both:

Code: Select all

sudo VBoxManage internalcommands createrawvmdk -filename /Users/brad/VirtualBox\ VMs/Ubuntu\ 12.04\ Precise\ Pangolin\ i386/sdcard.vmdk -rawdisk /dev/disk1
-and-

Code: Select all

sudo VBoxManage internalcommands createrawvmdk -filename "/Users/brad/VirtualBox VMs/Ubuntu 12.04 Precise Pangolin i386/sdcard.vmdk" -rawdisk /dev/disk1
commands; and they both seem to work as above (and yes, I delete the sdcard.vmdk in between each try!), but when I go to the VirtualBox UI and try to 'Add Hard Disk...' with that sdcard.vmdk created, I get the same "NS_ERROR_FAILURE" with any of the three methods (non-absolute, absolute with '\ ' (backslash spaces) and quoted with spaces).

*bump* Re: Can't create SD card vmdk on guest: Ubuntu 12.04

Posted: 17. Aug 2012, 20:11
by likethesky
Trying one more bump here. Is it that I'm being so bone-headed that no one can stand to answer my question? Total newbie here--just trying to get an SD card reader in my Macbook to work on an Ubuntu guest...

Or is it that Mountain Lion is having a lot more difficulties than my little issue and hence this isn't a priority now ... ?

Or is it something else? If someone knowledgeable about the issues I'm facing would at least say, "Wow, you have me stumped, I have used an SD card on a new Macbook and I have no idea how to solve your problem," that would at least tell me I should try other avenues...

Thanks!

Re: Can't create SD card vmdk on guest: Ubuntu 12.04--2012 r

Posted: 18. Aug 2012, 11:51
by mpack
I can tell you that I don't like to support people who are trying to use raw disk access. My opinion is that it's a dangerous, expert level feature: and if you need to ask how to get it working, then you shouldn't be using it - sorry to be so blunt. Also I'm not a Mac user and hence I don't know what security features it has in place to prevent sector level access to disk drives. Certainly elevated permissions would be required.

I especially don't like to help when it isn't even made clear why it must be raw access instead of (say) the more usual shared folders.

Re: Can't create SD card vmdk on guest: Ubuntu 12.04--2012 r

Posted: 19. Aug 2012, 21:59
by likethesky
Ok, fair enough. I clearly don't know enough to know what I want!

I'm trying to write & read to/from an SD card using a Mac OS X host ( 10.8 ) and an Ubuntu 12.04 (and ideally also, a 10.04) guest.

I need to be able to execute commands on the Linux guest like: 'dd' and 'mount' and so forth to that SD card (like to /dev/sdb or whatever device letter it's assigned). (I'm helping script low-level routines that write new Linux images to these SD cards and I'd like to test them on my Mac, using a Linux guest.)

Tell me what's the easiest, most straightforward way to get access to the SD card slot in my MBP, if you would. (I thought, given JinnKo's answer--see link in my first/original post ( http://superuser.com/a/458085/146236 ) --that this wasn't possible without using rawdisk... happy to use shared folders if I can, to do this.)

Please send me a link some docs on shared folders showing me what I need to know, if you would. Or if not, then please help me to use this SD slot to read/write from my Linux guest, if you would.

Thanks for replying. I look forward to figuring this out.

Re: Can't create SD card vmdk on guest: Ubuntu 12.04--2012 r

Posted: 20. Aug 2012, 10:19
by mpack
If all you want to do is test some scripts then why not simply create a fixed size VMDK and mount it in the VM? Why mess with physical disks at all? Go to the storage section of the VM, Add a disk, select VMDK, and fixed size, and select the size in GB to match the exact size of the SD card you want to simulate. The disk appears as a drive inside the VM and can be used in all the normal ways (format with a filesystem, dd to it, etc). On the host side you'll find two .vmdk files, a small descriptor and the flat disk image. That disk image can be given to other people to burn to SD cards, or you can burn it yourself with the appropriate host tool. Do however make sure that your VM is shut down before you make copies of any of its disks.

This will be far more reliable that what you had in mind. However, one thing this doesn't simulate is plug and play add/remove - if that was relevant to your purposes.

Re: Can't create SD card vmdk on guest: Ubuntu 12.04--2012 r

Posted: 27. Aug 2012, 19:47
by likethesky
Sorry for the delay--been busy with other parts of this project. Yeah, for just testing scripts your answer is fine.

However: I *do* need to test that the resulting image written to the SD card that I create with the script actually works in another piece of hardware. So, I need to actually be able to write to an SD card (actually, it's a Micro SD card, in an SD card holder to be exact). Once I get done writing it (with my Mac hardware), I load it onto a board and boot it up.

So ..., any way to do that? (Write to a physical SD card, inserted in a new rMBP, via an Ubuntu 10.04 and/or 12.04 guest on a Mac OS X host--ideally a Mtn Lion host, that is: 10.8 running on the rMBP.)

Thanks again @mpack !

Re: Can't create SD card vmdk on guest: Ubuntu 12.04--2012 r

Posted: 28. Aug 2012, 10:16
by mpack
I think I covered that above.

Re: Can't create SD card vmdk on guest: Ubuntu 12.04--2012 r

Posted: 29. Aug 2012, 17:02
by likethesky
Hi @mpack,

Thanks for continuing to reply. I don't understand what you mean. Do you mean that you won't help me use the SD card in my MBP because it's too dangerous?

If there are instructions, I'm perfectly willing to perform a potentially dangerous operation (I'm an adult) in order to get this to work.

Please provide instructions on how to write to an SD card from a virtual guest running Ubuntu, if you would, or let me know where I'm misunderstanding you.

Thanks.

Re: Can't create SD card vmdk on guest: Ubuntu 12.04--2012 r

Posted: 29. Aug 2012, 17:10
by mpack
No, I mean that running the script inside the VM, writing to a virtual disk, proves that the script works. If you want to physically test the created disk image then you can take the raw image associated with the fixed VMDK (that was why I specified fixed) and dd it to a USB drive. There simply isn't any need to mount the raw usb drive in the VM.

And yes, as I explained above, I do have a personal policy of not helping people to use raw disk access - but even if that wasn't the case I am not a Mac user and couldn't give a detailed Mac howto on that subject anyway.

SOLVED: create SD card vmdk on guest: Ubuntu 12.04--2012 rMB

Posted: 30. Aug 2012, 00:09
by likethesky
Thanks again @mpack... I got in touch with JinnKo, in my original post, and he helped me through it, so I've solved this issue myself with his help.

See http://superuser.com/questions/373463/h ... ne/#458085 for JinnKo's version of the below.

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

Here are the steps I took:
1. Determine my SD Card device letter. *WITHOUT* inserting the SD card in your OS X Mtn Lion ( 10.8 ) system, do a:
$ mount

2. See what devices are in use *WITHOUT* the SD card inserted.

3. Insert the SD card, then do another:
$ mount

IMPORTANT: Using Disk Utility (Cmd-Space, type Disk Utility, press Enter), Unmount the partitions, if any, for the SD card. Do *NOT* eject the device, just *unmount only.*

4. Note the new device letter, as JinnKo mentions, without the sN, where N = 1, 2, 3, ... etc. IOW, if you see that your SD card is /dev/disk5s1, then what you want is without the 's1' at the end, meaning: /dev/disk5 (your number will likely be different than the '5'--be sure you get this number correct or you could destroy your hard drive/storage)!

5. 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:

Code: Select all

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:

Code: Select all

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 /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 /dev/disk5 ...
# If you are the owner, then all's good, nothing to do here, go to step 6.

# If you are not the owner (but 'root' is), then 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 their hard drive or flash storage drive *** CAUTION ***
*** CAUTION *** DO *NOT* DO THIS if you aren't sure you know what you're doing *** CAUTION ***

Code: Select all

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 *** CAUTION ***
*** CAUTION *** The above is only for those who want to RISK permanently destroying their hard drive or flash storage drive *** CAUTION ***

# 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 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)

6. Now (a) SHUTDOWN (don't just suspend, but fully shut down!) your Ubuntu VM, then (b) create a raw VMDK for that SD card, as so (again *SUBSTITUTE* the correct numbers/letters for your drive--don't just copy/paste this without changing it--and if you copy the carriage return <Enter> into your terminal it'll execute immediately--substitute for <your username> or home directory, the actual location/name of your VM for Ubuntu (instead of the 'Ubuntu 12.04' below), and substitute for the 'X' with '5' or whatever device number your SD card is, *when it's inserted*--double check this letter and don't do this if you aren't sure!!):

Code: Select all

$ VBoxManage internalcommands createrawvmdk -filename "/Users/<your username>/VirtualBox VMs/Ubuntu 12.04/sdcard.vmdk" -rawdisk /dev/diskX
7. Using Disk Utility (Cmd-Space, type Disk Utility, press Enter), Unmount the partitions, if any for the SD card.

8. Open up the VirtualBox UI, choose Storage | SATA or IDE (I used SATA, not sure if IDE will work too or not) Controller | click the icon to the right and choose Add Hard Disk | then choose "Use existing disk", then browse to the location of the sdcard.vmdk file specified in step 6. above. Choose it, voila. NOTE: If you can't choose Storage or the icon for the Add hard drive is grayed out, your VM is probably still running! Shut it down first!!

9. If you get errors when starting up your VM, try checking Disk Utility again to ensure that the partitions haven't been auto-remounted by Mtn Lion; if they have, just unmount them again (don't eject, just unmount--see steps 3 or 7 above), then try starting up your VM again.

Hope this helps someone else!

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

Re: Can't create SD card vmdk on guest: Ubuntu 12.04--2012 r

Posted: 30. Aug 2012, 00:33
by Y E T I
hahaha this post reminds me of all the pharmaceutical adds I see on TV. If you listen to everything that can happen including death why would you want to take the chance in the first place, and who in their right mind would ask their doctor to let them try it? Oh well if you absolutely need it there you are.

Re: Can't create SD card vmdk on guest: Ubuntu 12.04--2012 r

Posted: 30. Aug 2012, 00:36
by likethesky
I agree! It's a case of not wanting anyone to destroy data (I said 'permanently destroy your hard drive' which isn't really true--it'd only destroy the data on it).

CMA (cover my a**), for liability reaons ;-) ! A sign of the times that we need to do this. I also don't want some poor bloke who's never used a computer much to happen upon this via google and think sure, why not give it a try without thinking it through first!

I agree with @mpack that helping those who don't know what they're doing, is fraught with unintended consequences. Mostly for them!

Re: Can't create SD card vmdk on guest: Ubuntu 12.04--2012 r

Posted: 26. Jan 2013, 19:05
by nmiller
Thank you for posting these detailed instructions. I presume you're prepping cards for RPi or similar? I am in the same boat until I can work out the cross-compile tool chain for ARM on Mt. Lion.

Code: Select all

diskutil list
will also show you all of your disks and partitions on the Mac side. Rather than firing up the DiskUtil GUI, I use the terminal commands for it as well:

Code: Select all

diskutil unmountDisk /dev/diskX
to unmount all partitions of the disk.

Code: Select all

diskutil unmount /dev/diskXsY
will unmount a single partition.