Hotplug support gives snaps the ability to integrate with Linux’s USB hotplugging and Udev device management subsystem. This enables snaps to recognise specific classes of device and create corresponding system slots when a device is connected.
Developers wishing to add hotplug functionality to their own interfaces should see Developing hotplug interfaces.
Initially, only USB serial port adapters using the serial-port interface are supported. Other types of device, such as USB cameras, will be added in the future.
In addition to creating a slot, snapd’s hotplug support also remembers connections. If the device is unplugged, its slot disappears from the system. When the device is reconnected, its slot and connections are restored.
Hotplug is currently an experimental feature under active development. It can be tested by installing snapd from its edge channel:
$ sudo snap refresh core --edge
And enabled with the following command:
$ sudo snap set core experimental.hotplug=true
You will need to either restart snapd (with
sudo systemctl restart snapd, for example), or reconnect USB devices to initiate hotplug processing for connected devices.
The name of a hotplug slot is typically derived from a device’s udev attributes, such as
ID_MODEL. If multiple devices of the same type are connected, a numeric suffix could be added to make their names unique.
For example, a USB serial adapter from Future Technology Devices International (FTDI) with a model name of FT232R_USB_UART, will create the following slot for the system snap when connected:
$ snap interface serial-port name: serial-port summary: allows accessing a specific serial port slots: - core:ft232rusbuart $ snap connections system Interface Plug Slot Notes [...] serial-port - :ft232rusbuart -
Along with only supporting USB serial port adapters, hotplug is restricted to devices that provide a specific set of udev attributes; name, vendor identifier and/or serial number.
These attributes are needed to identify and track devices. This isn’t normally a problem for branded devices, but it may cause issues with unbranded devices. Without the required attributes, a device cannot be supported and will be ignored when connected.
There is also no easy way to list connected devices and their corresponding slots. This limitation will be addressed in an upcoming snapd release.