This repository demonstrates how setup_devtmpfs in a privileged container makes hotplugged devices easier to handle at runtime.
Containers are not primarily designed for dynamic hardware enumeration. In many deployments, the device namespace visible in a container is effectively fixed at container start. That can make runtime attach/detach events hard to handle cleanly.
This project uses a dedicated devtmpfs mount and runs udevd inside the container so device nodes and udev event handling are managed in a way that is much closer to host behavior.
devtmpfs (device temporary filesystem) is a Linux virtual filesystem in RAM that the kernel automatically manages to create and maintain device nodes under /dev.
In practice, this means device node creation/removal can track hardware events as they happen, instead of relying on a static /dev layout from container startup. The kernel provides the base device nodes through devtmpfs, and udev applies policy on top (permissions, ownership, symlinks, and event-driven actions). Together, that makes runtime hotplug behavior more predictable for containerized applications.
The function in entrypoint.sh:
- mounts a fresh
devtmpfsat/tmp/dev - moves required mounts (
/dev/console,/dev/pts,/dev/shm, etc.) into it - replaces
/devwith that new mount - restores
/dev/ptmxsymlink
After that, udevd --daemon is started and your main command runs. This setup improves handling of hardware that appears/disappears while the container is already running.
entrypoint.shconfigures/devwithsetup_devtmpfs, startsudevd, then executes the container command.idle.shreloadsudevrules, triggers initial events, and keeps the container alive.48-usb-hid.rulesis the active demo rule installed into/etc/udev/rules.d/by the Docker image.
- Primary target: balenaOS and native Linux environments where privileged containers and host device/sysfs integration are expected.
- macOS/Docker Desktop caveat: Docker Desktop runs Linux in a VM, so host USB hotplug and
udevbehavior can differ from native Linux. Treat local macOS runs as partial validation only.
The repository includes more rule examples under additional_examples/, organized by device type:
usb-devicecamerascreen-drmusb-serialinput-touch
Each directory includes commented .rules files showing matching patterns and common actions for that device class.
These examples are not active by default. To use one, copy the selected .rules file into /etc/udev/rules.d/, then reload rules:
udevadm control --reload-rules
udevadm triggerFrom the repository root, where myFleet is your balenaCloud fleet name:
balena push myFleet