diff --git a/data/templates/system/40_usb_autosuspend.j2 b/data/templates/system/40_usb_autosuspend.j2
new file mode 100644
index 00000000000..f001634e4b3
--- /dev/null
+++ b/data/templates/system/40_usb_autosuspend.j2
@@ -0,0 +1,5 @@
+{% set autosuspend = "-1" %}
+{% if enable_usb_autosuspend is vyos_defined %}
+{% set autosuspend = "auto" %}
+{% endif %}
+ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="{{ autosuspend }}"
diff --git a/interface-definitions/system_option.xml.in b/interface-definitions/system_option.xml.in
index fe517d17d76..95614edecc4 100644
--- a/interface-definitions/system_option.xml.in
+++ b/interface-definitions/system_option.xml.in
@@ -183,6 +183,12 @@
12-hour
+
+
+ Enable autosuspend for all USB devices
+
+
+
diff --git a/src/conf_mode/system_option.py b/src/conf_mode/system_option.py
index a2e5db57530..2c31703e960 100755
--- a/src/conf_mode/system_option.py
+++ b/src/conf_mode/system_option.py
@@ -35,6 +35,7 @@
curlrc_config = r'/etc/curlrc'
ssh_config = r'/etc/ssh/ssh_config.d/91-vyos-ssh-client-options.conf'
systemd_action_file = '/lib/systemd/system/ctrl-alt-del.target'
+usb_autosuspend = r'/etc/udev/rules.d/40-usb-autosuspend.rules'
time_format_to_locale = {
'12-hour': 'en_US.UTF-8',
'24-hour': 'en_GB.UTF-8'
@@ -85,6 +86,7 @@ def verify(options):
def generate(options):
render(curlrc_config, 'system/curlrc.j2', options)
render(ssh_config, 'system/ssh_config.j2', options)
+ render(usb_autosuspend, 'system/40_usb_autosuspend.j2', options)
cmdline_options = []
if 'kernel' in options:
@@ -155,6 +157,9 @@ def apply(options):
time_format = time_format_to_locale.get(options['time_format'])
cmd(f'localectl set-locale LC_TIME={time_format}')
+ cmd('udevadm control --reload-rules')
+
+
if __name__ == '__main__':
try:
c = get_config()
diff --git a/src/etc/udev/rules.d/40-usb-autosuspend.rules b/src/etc/udev/rules.d/40-usb-autosuspend.rules
new file mode 100644
index 00000000000..29f457f7ca5
--- /dev/null
+++ b/src/etc/udev/rules.d/40-usb-autosuspend.rules
@@ -0,0 +1 @@
+ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="-1"