# X11 hotplug USB

**URL:** <https://forums.balena.io/t/x11-hotplug-usb/7250>\
**Category:** Product support\
**Created:** [May 3, 2019, 12:52pm UTC](https://forums.balena.io/t/x11-hotplug-usb/7250 "2019-05-03T12:52:58Z")\
**Posts on this page:** 1\
**Showing post:** 36

<div class="post-metadata">

**Author:** ![kyleoptimotive](https://avatars.discourse-cdn.com/v4/letter/k/ac8455/32.png) [@kyleoptimotive](https://forums.balena.io/u/kyleoptimotive)\
**Post date:** [March 10, 2025, 8:25pm UTC](https://forums.balena.io/t/x11-hotplug-usb/7250/36 "2025-03-10T20:25:12Z")

</div>

I know this is an older post but I was having trouble with hot-plugging and wanted to share the solution that worked for me. It combines the `udevadm` commands from this post with the volume mounting from [another post](https://forums.balena.io/t/device-in-dev-does-not-appear-on-reboot/373510) (similar to what is seen in the Balena base image [here](https://github.com/balena-io-library/base-images/blob/master/balena-base-images/aarch64/ubuntu/jammy/run/entry.sh)). Note that someone in that post mentions there is a security risk with allowing hot-plugging for all devices. I also had to reorder the `udevadm` commands listed in this post.

This is the relevant part of my `Dockerfile` that allows hot-plugging for me.

```auto
ENV UDEV=on

# Create entrypoint script
RUN echo '#!/bin/bash\n\
newdev="/tmp/dev"\n\
mkdir -p "$newdev"\n\
mount -t devtmpfs none "$newdev"\n\
\n\
# Create mount points before moving\n\
mkdir -p "$newdev/shm"\n\
mkdir -p "$newdev/mqueue"\n\
mkdir -p "$newdev/pts"\n\
touch "$newdev/console"\n\
\n\
# Move existing mounts\n\
mount --move /dev/console "$newdev/console"\n\
mount --move /dev/mqueue "$newdev/mqueue"\n\
mount --move /dev/pts "$newdev/pts"\n\
mount --move /dev/shm "$newdev/shm"\n\
umount /dev || true\n\
mount --move "$newdev" /dev\n\
\n\
# Setup ptmx symlink\n\
ln -sf /dev/pts/ptmx /dev/ptmx\n\
\n\
# Setup debugfs if not already mounted\n\
sysfs_dir="/sys/kernel/debug"\n\
if ! mountpoint -q "$sysfs_dir"; then\n\
    mount -t debugfs nodev "$sysfs_dir"\n\
fi\n\
\n\
if which udevadm > /dev/null; then\n\
  set +e # Disable exit on error\n\
  unshare --net /lib/systemd/systemd-udevd --daemon\n\
  service udev restart\n\
  udevadm control --reload-rules\n\
  udevadm trigger\n\
  set -e # Re-enable exit on error\n\
fi\n\
exec "$@"' > /usr/local/bin/entrypoint.sh && \
chmod +x /usr/local/bin/entrypoint.sh

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

```

---

_[View the full topic](https://forums.balena.io/t/x11-hotplug-usb/7250)._
