Unable to flash SD card in guest OS

Discussions related to using VirtualBox on Windows hosts.
hvansia_thor
Posts: 12
Joined: 24. Sep 2021, 05:56

Unable to flash SD card in guest OS

Post by hvansia_thor »

Host OS: Windows 10 Professional
Guest OS: Ubuntu 20.04

Host OS:
I am able to add files, edit files and add folders.
Verified that SD card is read and write card

Guest OS:
I am able to mount and unmount the card
Able to read the changes in the text file.
Can add new files in the directory but the change is not reflected back to Host OS. Also changes are lost as soon as the drive is unmounted and mounted back again.
Besides that I cannot save the modifications made in the files. Gives me one form or another error depending upon whether host I/O cache is being used. Essentially it is read only access.

Virtual Box parameters:
The SD card is mounted as Controller: USB under Storage. Host I/O cache is being used
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Unable to flash SD card in guest OS

Post by scottgus1 »

Is your intent to use the USB controller as requirement for the project? If not and it's just something you settled on, there is an easier way: share a folder on the SD card from the host OS then access the shared folder in the VM over a Bridged or Host-Only network.

If the USB controller is a requirement, how did you point the USB controller's disk at the SD card? When I try to add a disk to a USB controller all I get is virtual disk files, not the physical disks that the host can use.
hvansia_thor
Posts: 12
Joined: 24. Sep 2021, 05:56

Re: Unable to flash SD card in guest OS

Post by hvansia_thor »

The use of USB controller is not the goal. The thing is I am trying to do is flash Raspberry OS on the SD card from guest OS. I have SD card reader/writer on the computer. I do not think I can flash an .img file on the SD card via shared folders? Can I?
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Unable to flash SD card in guest OS

Post by mpack »

Overwriting a host drive (not usually desirable from a VM) requires sector level access and appropriate host admin rights. Better to use the host for this.
hvansia_thor
Posts: 12
Joined: 24. Sep 2021, 05:56

Re: Unable to flash SD card in guest OS

Post by hvansia_thor »

This host drive is SD Card. I want to flash the SD Card with RaspPi OS. I would like that to be done via guest OS which is Ubuntu. If everything comes to nothing maybe I will use the host OS but I was under the impression this could be done via guest OS.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Unable to flash SD card in guest OS

Post by scottgus1 »

hvansia_thor wrote:I was under the impression this could be done via guest OS.
If you can get access to the host drive directly, without going through the host OS, then it ought to be possible.

You'd have to give the VM direct control of the SD card reader. See https://www.virtualbox.org/manual/ch08. ... cardreader. The host might require the Extension Pack to be installed.

If the SD card reader is a stand-alone USB device that plugs in with a USB cable, you might use a Virtualbox USB Filter. See USB basics and troubleshooting

One other possibility: a Linux LiveCD running on your host. No Virtualbox involved, Linux temporary OS directly driving the host hardware.

Also consider: https://www.raspberrypi.org/blog/raspbe ... g-utility/
hvansia_thor
Posts: 12
Joined: 24. Sep 2021, 05:56

Re: Unable to flash SD card in guest OS

Post by hvansia_thor »

Let me give you quick run down of what I have done:

1) Making sure that SD Card is read and write.
- Type DISKPART in windows search
- Run DISKPART.exe
- Type "LIST DISK"
- Note down the disk number I am interested in
- SELECT Disk <disk number>
- Type "ATTRIBUTES DISK"
-Current Read-only State : No
-Read Only: No
-OFFLINE DISK. This is where I get the error and I am not able to take the disk offline

2) Make sure Virtual Box is run as an administrator.

3) Create VMDK disk
-Followed the instructions over here: "scribles(dot)net/accessing-sd-card-from-linux-virtualbox-guest-on-windows-host"

4) Assign the VMDK disk and set it writethrough
-Followed steps 2 and 3 mentioned in the top answer over here "superuser(dot)com/questions/495025/use-physical-harddisk-in-virtual-box"
-Command line options:
-Type "C:\Program Files\Oracle\VirtualBox\VBoxManage" modifyhd "destn\path\sdcard.vmdk" settype writethrough
-Type "C:\Program Files\Oracle\VirtualBox\VBoxManage" storageattach <virtualMachineName> --storagectl SATA --device 0 --port 0 --type hdd --medium "destn\path\sdcard.vmdk"

I am still not able to save files on SD card in the guest OS. What am I missing?

5) I followed instructions over "virtualbox(dot)org/manual/ch08(dot)html#vboxmanage-usbcardreader". But I do not see any change in the way the SD card is exposed in guest OS.

6) I have downloaded extension pack but the SD card reader is not populated in the USB filters.

That is what I am trying to run on guest OS.

What am I missing?

PS: All the urls are missing "h**ps" in the beginning because forum would not allow me to post urls
hvansia_thor
Posts: 12
Joined: 24. Sep 2021, 05:56

Re: Unable to flash SD card in guest OS

Post by hvansia_thor »

If somebody is interested in solving the problem I have also attached Vlog file from virtual box.

I have been testing SD card with other old laptop I have. Over there I found out that since the SD card reader/writer is on the USB I can forward it as a USB device and I was able to read and write to it. However, when I forwarded the SD card as USB device, I was not able to access the SD Card on the host. So, if I understand correctly, any external hardware can be accessed by either host or guest OS but not simultaneously.

In my original laptop, I see that SD card is accessed simultaneously by host OS and guest OS. Is this normal?

I am almost but not 100% sure that Windows is preventing guest OS to access the SD card. I simply do not know the mechanism by which it is doing it. I am really curious about it. Can somebody shed light on this.

Thanks in advance!
Attachments
VirtualUbuntu-2021-09-26-12-00-37_0.log
This is the first half
(57.56 KiB) Downloaded 9 times
VirtualUbuntu-2021-09-26-12-00-37.log
This is the second
(114.4 KiB) Downloaded 4 times
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Unable to flash SD card in guest OS

Post by scottgus1 »

hvansia_thor wrote: when I forwarded the SD card as USB device, I was not able to access the SD Card on the host. So, if I understand correctly, any USB external hardware can be accessed by either host or guest OS but not simultaneously.
FTFY. Yes, hardware passed via USB cannot be shared between multiple PCs. Other hardware may, such as CD drives, shared folders, etc if they are not being passed via USB.
hvansia_thor
Posts: 12
Joined: 24. Sep 2021, 05:56

Re: Unable to flash SD card in guest OS

Post by hvansia_thor »

Thanks scottgus1!

Do you have any idea how windows is preventing guest OS to access SD card? It is not connected to the USB bus but PCIe bus.
Also, I can see the SD card simultaneously on Windows and guest OS.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Unable to flash SD card in guest OS

Post by scottgus1 »

That will take some looking into. But, lest we lose sight of the forest for the trees, RaspBerry has released a Windows-based SD card flasher.

Also, since Windows is the host not the guest, going to move this to Windows Hosts.
hvansia_thor
Posts: 12
Joined: 24. Sep 2021, 05:56

Re: Unable to flash SD card in guest OS

Post by hvansia_thor »

Yes, that is true. I am using it to flash on Windows. This is one of those things, I am curious about and cannot let go.

Thanks for that!
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Unable to flash SD card in guest OS

Post by mpack »

hvansia_thor wrote:It is not connected to the USB bus but PCIe bus.
I very much doubt that. SDcards have absolutely no use for PCIe speeds. It will be attached as USB mass storage, as a USB3 device in fact. It would be ridiculous design to do anything else.

My own PC has a USB reader slot on the front bezel: if I plug in a card and then get properties, it certainly seems to me that Windows thinks it's a USB device.
Attachments
sdcard.png
sdcard.png (30.78 KiB) Viewed 7266 times
hvansia_thor
Posts: 12
Joined: 24. Sep 2021, 05:56

Re: Unable to flash SD card in guest OS

Post by hvansia_thor »

SD Card.PNG
SD Card.PNG (23.78 KiB) Viewed 7237 times
For me, it shows up as removable disk. When I was looking for class UIDs register keys and matching with the container ID register key of the SD card, I found out that it is implemented as PCI storage.
SD Card_2.PNG
SD Card_2.PNG (113.47 KiB) Viewed 7237 times
I think it depends on hardware implementation. On my other laptop it shows up as USB device and there I have no problem writing on SD card. I have problem with this laptop where the SD card is not mounted on the USB hub.
hvansia_thor
Posts: 12
Joined: 24. Sep 2021, 05:56

Re: Unable to flash SD card in guest OS

Post by hvansia_thor »

SD Card_3.PNG
SD Card_3.PNG (79.39 KiB) Viewed 7224 times
Another link that shows that SD card is PCI storage.
Post Reply