Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Desktop for Mac OSCatalina Mount SD Card Volume in Container as loop device to flash SD Card with dd

I am using Docker Desktop for Mac Version 2.1.0.4. I have a Docker container that is an Ubuntu 18.04 Linux VM with the Yocto Build system inside of it. I use it to generate SD Cards for my NVIDIA Jetson Nano. At the end of the build process I have *.img file that I can "dd" directly to an SD Card and use to boot my Jetson Nano. I'd like the Docker container to mount the SD Card Volume from the MacBook so that it can dd directly to the SD Card from inside the container instead of manually copying and running "dd" from my Mac Terminal. I would usually do this by mounting the (unmounted) /dev/sdX device in Linux as a loop device with losetup, and then running "dd".

I can successfully mount the SD Card and view its contents inside the container by starting the container with the following commands:

MacBook-Pro:~ me$ docker run -it -v /Volumes/pkop:/opt/myvolume jetson-nano bash
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

root@c4102f7124d4:~/Desktop/jetson-yocto$ ls /opt/myvolume/
a.txt  b.xt  lost+found

I can write files from either the Mac or Container to this shared Volume and view the changes from both perspectives.

However, I cannot figure out ( or find on Google ) how to unmount the shared volume ( so it is not in use in the container ) and be able to "dd" directly to it.

How can I do this? Thanks.

enter image description here

enter image description here

NOTE: I tried the following and unfortunately it still did not work:

MacBook-Pro:~ me$ mount
...
/dev/disk2s2 on /Volumes/BOOT (msdos, local, nodev, nosuid, noowners)
MacBook-Pro:~ me$ sudo diskutil unmount /dev/disk2s2
Password:
Volume BOOT on disk2s2 unmounted
MacBook-Pro:~ me$ sudo mkdir -p /tmp/sd
MacBook-Pro:~ me$ sudo diskutil mount -mountPoint /tmp/sd /dev/disk2s2
Volume BOOT on /dev/disk2s2 mounted
MacBook-Pro:~ me$ docker images
REPOSITORY                                                   TAG                 IMAGE ID            CREATED             SIZE
vsc-jetsonnanobuildsystem-7dbcb92dddcd1879ee470cf5cbe42494   latest              661fca4aff22        10 hours ago        270GB
MacBook-Pro:~ me$ 
MacBook-Pro:~ me$ docker run -i -t -v /tmp/sd:/opt/usb vsc-jetsonnanobuildsystem-7dbcb92dddcd1879ee470cf5cbe42494 bash
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

user@9bcdaf6469be:~/Desktop/jetson-yocto$ ls /opt/usb/
a
user@9bcdaf6469be:~/Desktop/jetson-yocto$ dd if=/dev/random of=/opt/usb
dd: failed to open '/opt/usb': Is a directory

Furthermore, it seems I cannot share the /dev directory:

enter image description here

like image 645
PhilBot Avatar asked Nov 16 '19 18:11

PhilBot


1 Answers

I think this will work:

docker run -v /dev:/dev --privileged YOURIMAGE bash

then :

dd if=/dev/random of=/dev/disks2

you need also to share /dev in your docker configurations , and I think it is some how risky to share it beside using the --privileged parameters .....

you will get the following message if you do not share /dev:

docker: Error response from daemon: Mounts denied:
The path /dev/disk1s2
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.
like image 157
LinPy Avatar answered Oct 31 '22 19:10

LinPy