Quick question, are there any guides for how to use a second drive on a balena device? I want to boot off an SD card and I will have an NVMe plugged in to the device. I would like one of my containers to access that drive to store its data.
TY
Quick question, are there any guides for how to use a second drive on a balena device? I want to boot off an SD card and I will have an NVMe plugged in to the device. I would like one of my containers to access that drive to store its data.
TY
There is some information about this in the docs: Communicate outside the container | balena docs
Note that some examples may use udev from the balenalib base images - those have been deprecated in favor of official base images. If you don’t have your own udev replacement, you can use the script from our old base images: base-images/balena-base-images/aarch64/debian/buster/build/entry.sh at master · balena-io-library/base-images · GitHub
FWIW, the page referenced says:
Note that currently it’s not possible to share a mounted device across multiple containers.
However, I was able to mount an NVMe drive using a UDEV rule injected into the balena image and then use that mount in multiple containers. Adding the UDEV rule looks like roughly:
UDEV_RULE="ACTION==\"add\", SUBSYSTEMS==\"nvme\", KERNEL==\"nvme[0-9]n[0-9]p1\", ENV{ID_FS_USAGE}==\"filesystem\", RUN{program}+=\"/usr/bin/systemd-mount --no-block --automount=yes --bind-device --options=noexec,nosuid,nodev,sync --collect \$devnode /run/mount/nvme\""
jq --arg r "$UDEV_RULE" '.os.udevRules["80-myapp-nvme"] = $r' $IMAGE_CONFIG > ${IMAGE_CONFIG}.new && mv ${IMAGE_CONFIG}.new ${IMAGE_CONFIG}
$BALENA_CMD config inject --drive "$IMAGE" $IMAGE_CONFIG
Then, in my docker-compose.yml, I have:
volumes:
nvme-shared:
driver: local
driver_opts:
type: none
o: bind,rshared
device: /run/mount
So far that seems to work well to allow the same volume to be used in multiple containers.
-mike