Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
udev rule for Home Assistant OS (hassio) to mount USB drives into the Supervisor Media directory
#
# udev rule
# Mount USB drive to the media directory using the partition name as mount point
#
# Description:
# Created for Home Assistant OS, this rule mounts any USB drives
# into the Hassio media directory (/mnt/data/supervisor/media).
# When a USB drive is connected to the board, the rule creates one directory
# per partition under the media directory. The newly created partition is named
# as the partition name. If the partition does not have a name, then the following
# name format is used: "usb-{block-name}" where the block name is sd[a-z][0-9].
#
# Note 1:
# The rule name is always prefixed with a number. In this case, the rule uses 80.
# This represents the order of the rule when multiple rules exists in udev.
# Low numbers run first, high numbers run last. However, low numbers do not have all
# the facilities than high numbers may have.
# For this rule to run properly, use numbers equal or greater than 80.
#
# Note 2:
# This rule will skip mounting the 'CONFIG' USB key.
# https://github.com/home-assistant/operating-system/blob/dev/Documentation/configuration.md
#
# Note 3:
# This rule will mount the OS partitions if the OS is sorted on a USB drive (i.e. USB booting).
# To prevent this issue from happening, update the rule to skip the booting USB drive.
# See the CAUTION message below.
#
# Source of inspiration:
# https://www.axllent.org/docs/auto-mounting-usb-storage/
#
# Useful links:
# https://wiki.archlinux.org/index.php/Udev
#
# udev commands:
# - Restart udev to reload new rules:
# udevadm control --reload-rules
# - List device attributes of sdb1:
# udevadm info --attribute-walk --name=/dev/sdb1
# - List environment variables of sdb1:
# udevadm info /dev/sdb1
# - Trigger add/remove event for sdb1:
# udevadm trigger --verbose --action=add --sysname-match=sdb1
# udevadm trigger --verbose --action=remove --sysname-match=sdb1
#
# Filter on block devices, exit otherwise
# CAUTION: Change to 'sd[b-z][0-9]' if booting from a USB drive (e.g.: sda)
KERNEL!="sd[a-z][0-9]", GOTO="abort_rule"
# Skip none USB devices (e.g.: internal SATA drive)
ENV{ID_PATH}!="*-usb-*", GOTO="abort_rule"
# Import the partition info into the environment variables
IMPORT{program}="/usr/sbin/blkid -o udev -p %N"
# Exit if partition is not a filesystem
ENV{ID_FS_USAGE}!="filesystem", GOTO="abort_rule"
# Exit if this is the 'CONFIG' USB key
ENV{ID_FS_LABEL}=="CONFIG", GOTO="abort_rule"
# Get the partition name if present, otherwise create one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usb-%k"
# Determine the mount point
ENV{mount_point}="/mnt/data/supervisor/media/%E{dir_name}"
# Mount the device on 'add' action (a.k.a. plug the USB drive)
ACTION=="add", RUN{program}+="/usr/bin/mkdir -p %E{mount_point}", RUN{program}+="/usr/bin/systemd-mount --no-block --automount=no --collect $devnode %E{mount_point}"
# Umount the device on 'remove' action (a.k.a unplug or eject the USB drive)
ACTION=="remove", ENV{dir_name}!="", RUN{program}+="/usr/bin/systemd-umount %E{mount_point}", RUN{program}+="/usr/bin/rmdir %E{mount_point}"
# Exit
LABEL="abort_rule"
@Sarelseekat
Copy link

Sarelseekat commented Dec 8, 2021

Hi Guys - I've got a 2Tb surveillance drive that I formated to ext4 and running internally of a SATA connection. The issue is don't have a /etc/udev directory. I tried rebooting HASS as well as reformating the drive, but still nothing.

When I use -> ls -la /dev/disk/by-uuid
I do see ../../sda1 in the list

Any advice?

@Moondevil-ha
Copy link

Moondevil-ha commented Dec 8, 2021

I guess you're doing this from the terminal of HA itself? You need to be on the actual console (ie plug a keyboard into your HA hardware and a monitor. Sorry if that's not the case?

@Sarelseekat
Copy link

Sarelseekat commented Dec 9, 2021

Hi Moon - That was indeed the case. I couldn't let it go so got up in the night and did exactly that. Low and behold, there is the udev folder. What I did find was that I couldn't use nano or gedit to create the file. I've never been able to wrap my head around vi. Will create the file using nano in ssh and move it directly on the machine to the correct place. Hope all the permission will be correctly doing it this way. I will post again later if it all worked out.

@Sarelseekat
Copy link

Sarelseekat commented Dec 9, 2021

YES!!!
It's working
That was much less hassles than I usually have

@Moondevil-ha
Copy link

Moondevil-ha commented Dec 9, 2021

Excellent, happy to help.

@Tekno-man
Copy link

Tekno-man commented Jan 27, 2022

Hi all, just thinking of redundancy down the track. If using the UUID method and the hard drive fails. Would you just update the 80-mount-additional-storage.rules with the new UUID of the replacement hard drive, would there be any repercussions for HA? And what happens when the extra drive is unmounted does ha just go back to using the os drive when saving in media folders?

Cheers

@Moondevil-ha
Copy link

Moondevil-ha commented Jan 27, 2022

@Tekno-man
Copy link

Tekno-man commented Jan 28, 2022

@Moondevil-ha thanks for the fast reply about the replacement drive. Appreciate it.

@Tekno-man
Copy link

Tekno-man commented Feb 3, 2022

How can I check that the mount has worked?

i used the code in ha-build/ moondevil-ha with sdb instead of sda and my uuid

`KERNEL!="sdb[0-9]", GOTO="abort_rule"

ACTION=="add", RUN{program}+="/usr/bin/systemd-mount --no-block --automount=no --collect /dev/disk/by-uuid/36071622-61b5-4f69-bab3-27e03c46357d /mnt/data/supervisor/media" ACTION=="remove", RUN{program}+="/usr/bin/systemd-umount /mnt/data/supervisor/media"

LABEL="abort_rule"`

@Moondevil-ha
Copy link

Moondevil-ha commented Feb 3, 2022

@Tekno-man
Copy link

Tekno-man commented Feb 3, 2022

Thanks for the advice, this is really weird i dont have and media folder

`Filesystem Size Used Available Use% Mounted on
/dev/root 181.3M 181.3M 0 100% /
devtmpfs 9.8G 0 9.8G 0% /dev
proc 0 0 0 0% /proc
sysfs 0 0 0 0% /sys
securityfs 0 0 0 0% /sys/kernel/security
tmpfs 9.8G 0 9.8G 0% /dev/shm
devpts 0 0 0 0% /dev/pts
tmpfs 3.9G 1.9M 3.9G 0% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
cgroup2 0 0 0 0% /sys/fs/cgroup/unified
cgroup 0 0 0 0% /sys/fs/cgroup/systemd
none 0 0 0 0% /sys/fs/bpf
cgroup 0 0 0 0% /sys/fs/cgroup/cpu,cpuacct
cgroup 0 0 0 0% /sys/fs/cgroup/hugetlb
cgroup 0 0 0 0% /sys/fs/cgroup/pids
cgroup 0 0 0 0% /sys/fs/cgroup/memory
cgroup 0 0 0 0% /sys/fs/cgroup/perf_event
cgroup 0 0 0 0% /sys/fs/cgroup/devices
cgroup 0 0 0 0% /sys/fs/cgroup/freezer
cgroup 0 0 0 0% /sys/fs/cgroup/net_cls,net_prio
cgroup 0 0 0 0% /sys/fs/cgroup/cpuset
cgroup 0 0 0 0% /sys/fs/cgroup/blkio
tmpfs 3.9G 1.9M 3.9G 0% /etc/machine-id
mqueue 0 0 0 0% /dev/mqueue
hugetlbfs 0 0 0 0% /dev/hugepages
debugfs 0 0 0 0% /sys/kernel/debug
tracefs 0 0 0 0% /sys/kernel/tracing
fusectl 0 0 0 0% /sys/fs/fuse/connections
/dev/sda1 31.9M 420.0K 31.5M 1% /mnt/boot
/dev/sda7 89.0M 1.7M 80.5M 2% /mnt/overlay
/dev/sda7 89.0M 1.7M 80.5M 2% /etc/docker
/dev/sda7 89.0M 1.7M 80.5M 2% /etc/dropbear
/dev/sda7 89.0M 1.7M 80.5M 2% /etc/modprobe.d
/dev/sda7 89.0M 1.7M 80.5M 2% /etc/modules-load.d
/dev/sda7 89.0M 1.7M 80.5M 2% /etc/udev/rules.d
/dev/sda7 89.0M 1.7M 80.5M 2% /root/.docker
/dev/sda7 89.0M 1.7M 80.5M 2% /root/.ssh
/dev/sda7 89.0M 1.7M 80.5M 2% /etc/NetworkManager/system-connections
/dev/sda7 89.0M 1.7M 80.5M 2% /etc/hostname
/dev/sda7 89.0M 1.7M 80.5M 2% /etc/hosts
/dev/sda7 89.0M 1.7M 80.5M 2% /etc/systemd/timesyncd.conf
/dev/sda8 251.3G 127.3G 113.8G 53% /mnt/data
/dev/zram1 30.0M 124.0K 27.6M 0% /var
/dev/zram2 15.0M 68.0K 13.8M 0% /tmp
/dev/sda7 89.0M 1.7M 80.5M 2% /var/lib/NetworkManager
/dev/sda7 89.0M 1.7M 80.5M 2% /var/lib/bluetooth
/dev/sda7 89.0M 1.7M 80.5M 2% /var/lib/systemd
/dev/sda8 251.3G 127.3G 113.8G 53% /var/log/journal
/dev/sda8 251.3G 127.3G 113.8G 53% /var/lib/docker
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/23d81875e6c8ceab5d10f0bc09bd6e004e768a7aeda775aba3feb2404ab2de4c/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/23d81875e6c8ceab5d10f0bc09bd6e004e768a7aeda775aba3feb2404ab2de4c/merged
nsfs 0 0 0 0% /run/docker/netns/ef9c06e9a4c6
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/8f99113676b8d332810c61277ef41f6d4ec4f2475c3c54eba395c10aa487c6a1/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/8f99113676b8d332810c61277ef41f6d4ec4f2475c3c54eba395c10aa487c6a1/merged
nsfs 0 0 0 0% /run/docker/netns/267a9f399d07
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/b5d39979d810acb1343436c6ef57744e2b9c05a56964f48e3358102f9e9e0e16/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/b5d39979d810acb1343436c6ef57744e2b9c05a56964f48e3358102f9e9e0e16/merged
nsfs 0 0 0 0% /run/docker/netns/9ad5ee317c93
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/2a6ba95b0e3286102a35e629f2dcf464f16d59094385e537e14c75b252097448/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/2a6ba95b0e3286102a35e629f2dcf464f16d59094385e537e14c75b252097448/merged
nsfs 0 0 0 0% /run/docker/netns/c1abaff9937a
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/b0112d293c141b88cfcc7cdd460f3e6f1411a4cdd7a0e71977c45032837d6fd6/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/b0112d293c141b88cfcc7cdd460f3e6f1411a4cdd7a0e71977c45032837d6fd6/merged
nsfs 0 0 0 0% /run/docker/netns/ebd9471f90a8
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/704f24b5602300316cfe02849b87ccc87ecd146cf50b0991e47ee2cca7e2c4be/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/704f24b5602300316cfe02849b87ccc87ecd146cf50b0991e47ee2cca7e2c4be/merged
nsfs 0 0 0 0% /run/docker/netns/default
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/97581aa5694f75a0587ad7b06937dbc236477e7496ad5a531313a47787caff65/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/97581aa5694f75a0587ad7b06937dbc236477e7496ad5a531313a47787caff65/merged
nsfs 0 0 0 0% /run/docker/netns/0c3ed912ba57
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/f39040f49ab69791e611ad86fe028581c0a2cfc6dc2bf41fb3c967476b12c84a/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/f39040f49ab69791e611ad86fe028581c0a2cfc6dc2bf41fb3c967476b12c84a/merged
nsfs 0 0 0 0% /run/docker/netns/6e959c6e84f3
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/fb61706b3d900db67186b80ed102f2a566d2397163235c5d60ec0003c4b91fee/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/fb61706b3d900db67186b80ed102f2a566d2397163235c5d60ec0003c4b91fee/merged
nsfs 0 0 0 0% /run/docker/netns/ecb4ab6ea716
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/708e5fabcf2df5467be727516f647188ef310dbfa0127b91b4c561ad3a043ed3/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/708e5fabcf2df5467be727516f647188ef310dbfa0127b91b4c561ad3a043ed3/merged
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/6ada3d30635654ffc622346d84853d43d003bcf5c7ce9eaf0c8b4f309bce5ac4/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/6ada3d30635654ffc622346d84853d43d003bcf5c7ce9eaf0c8b4f309bce5ac4/merged
nsfs 0 0 0 0% /run/docker/netns/da1ba11a2329
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/2f57c92b39c0ad55a5d3750cc1e49f9e8fc7ca640ac30c8d657b47e699a81d29/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/2f57c92b39c0ad55a5d3750cc1e49f9e8fc7ca640ac30c8d657b47e699a81d29/merged
nsfs 0 0 0 0% /run/docker/netns/d4ba98d849c6
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/a94b4c417aa332abc2c36627c68b2c5870dc846c1d5cf2fdc058333bfe3bb369/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/a94b4c417aa332abc2c36627c68b2c5870dc846c1d5cf2fdc058333bfe3bb369/merged
nsfs 0 0 0 0% /run/docker/netns/2c71135ac50f
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/4a3cc071a72d5ac92e863c0e0decafd8ccffa8d8364138eb2ea5a49f8ba70983/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/4a3cc071a72d5ac92e863c0e0decafd8ccffa8d8364138eb2ea5a49f8ba70983/merged
nsfs 0 0 0 0% /run/docker/netns/ca04940a1633
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/266d562f996dcc0b6c470928333db0c0e5de3d2c980dff7bc47832a19b8b95f1/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/266d562f996dcc0b6c470928333db0c0e5de3d2c980dff7bc47832a19b8b95f1/merged
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/daf3bb091e43f87c62259967f1d6f2e1be847cdfb98e30d4465a67481143465d/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/daf3bb091e43f87c62259967f1d6f2e1be847cdfb98e30d4465a67481143465d/merged
nsfs 0 0 0 0% /run/docker/netns/721be3281ad0
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/26417803517aaeb84c08482ec3fbc347b13fb5001754500d069907ac29f5f6b9/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/26417803517aaeb84c08482ec3fbc347b13fb5001754500d069907ac29f5f6b9/merged
nsfs 0 0 0 0% /run/docker/netns/ad23463b4b3a
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/e730ac8d4761301a854d183de8345d05eba8ff9eae049dfda40da672e0c30a85/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/e730ac8d4761301a854d183de8345d05eba8ff9eae049dfda40da672e0c30a85/merged
nsfs 0 0 0 0% /run/docker/netns/d8eb7c798fcc
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/e4caa0ab9c40358838784ce9712636ebadc855bbc31079c2b0aceae686e0f98f/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/e4caa0ab9c40358838784ce9712636ebadc855bbc31079c2b0aceae686e0f98f/merged
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/bc7a8b29e7c4adeefa03bd8b1063db8a04dd814bf4bf57ad1044381953067bd9/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/bc7a8b29e7c4adeefa03bd8b1063db8a04dd814bf4bf57ad1044381953067bd9/merged
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/07881f663ef7ef645512d9f692e7a318d5fb2e678b443a02b4cbcca695f1db03/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/07881f663ef7ef645512d9f692e7a318d5fb2e678b443a02b4cbcca695f1db03/merged
nsfs 0 0 0 0% /run/docker/netns/652eeba7af26
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/e7be20ed98f1568fb5ae9335eac331f57249269402f3aaafd4a5881372ba46cd/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/e7be20ed98f1568fb5ae9335eac331f57249269402f3aaafd4a5881372ba46cd/merged
nsfs 0 0 0 0% /run/docker/netns/2b8882e6c331
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/b5b9d54b9c7ebc68fd38993fc4d844985fa789d5c2c80832a4838b110215b63d/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/b5b9d54b9c7ebc68fd38993fc4d844985fa789d5c2c80832a4838b110215b63d/merged
nsfs 0 0 0 0% /run/docker/netns/960c72b4d84e
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/77d11f50636c161f95a0d99e451aaf8dec6b7e7e31a811f1c74385283d694ca2/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/77d11f50636c161f95a0d99e451aaf8dec6b7e7e31a811f1c74385283d694ca2/merged
nsfs 0 0 0 0% /run/docker/netns/f26663949454
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/7ae482f339ee12fe76461613e4e28ff3bca02bd2f3d1b79643253a1345790e07/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/7ae482f339ee12fe76461613e4e28ff3bca02bd2f3d1b79643253a1345790e07/merged
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/f976089030a917a556a44d4ea6866dfe872b31f8cd954b015d9999dbd1e658aa/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/f976089030a917a556a44d4ea6866dfe872b31f8cd954b015d9999dbd1e658aa/merged
nsfs 0 0 0 0% /run/docker/netns/43ba22782626
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/693ccacf225e13914671f08aaac8560860e9d450b89f32cdb12cc6004c70ddcc/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/693ccacf225e13914671f08aaac8560860e9d450b89f32cdb12cc6004c70ddcc/merged
nsfs 0 0 0 0% /run/docker/netns/0550ee7210bf
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/229c7a67a8f3e21e53aeaac206ed14d2f5419d9ef0e5ac60188ba021d7588eb4/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/229c7a67a8f3e21e53aeaac206ed14d2f5419d9ef0e5ac60188ba021d7588eb4/merged
nsfs 0 0 0 0% /run/docker/netns/bda5cd4f0aa0
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/e97b2a4ccfa471a785415ceb948e5a60ab6b8415c27cd24b57b4d5343b5b13d2/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/e97b2a4ccfa471a785415ceb948e5a60ab6b8415c27cd24b57b4d5343b5b13d2/merged
nsfs 0 0 0 0% /run/docker/netns/f6aef14b78f4
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/4da8845e5039a40ebd38f22572bc4765716e801e44cb695d1f58ad68f4c7db56/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/4da8845e5039a40ebd38f22572bc4765716e801e44cb695d1f58ad68f4c7db56/merged
nsfs 0 0 0 0% /run/docker/netns/9d5296656b0f
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/4f232156ea5b09854b0eff3a1d84123c265ee2990a35be3e75e52c23f776d87c/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/4f232156ea5b09854b0eff3a1d84123c265ee2990a35be3e75e52c23f776d87c/merged
nsfs 0 0 0 0% /run/docker/netns/ef664fd2cdee
overlay 251.3G 127.3G 113.8G 53% /mnt/data/docker/overlay2/903e5c58b9238dd159a334a88323b54b2080a0c7133247b2e063c8c3b4bf9e10/merged
overlay 251.3G 127.3G 113.8G 53% /var/lib/docker/overlay2/903e5c58b9238dd159a334a88323b54b2080a0c7133247b2e063c8c3b4bf9e10/merged

`

@Tekno-man
Copy link

Tekno-man commented Feb 4, 2022

I realise i might be making a mistake, my harddrive is added to VM via USBpass through. I am detecting the UUID

lrwxrwxrwx 1 root root 10 Feb 3 23:05 36071622-61b5-4f69-bab3-27e03c46357d -> ../../sdb1
lrwxrwxrwx 1 root root 10 Feb 3 23:05 5d7db345-f084-4204-a905-999f5e35fdd6 -> ../../sda8
lrwxrwxrwx 1 root root 10 Feb 3 23:05 7cefb21e-124e-4280-ba29-34fc7a04d19b -> ../../sda7
lrwxrwxrwx 1 root root 10 Feb 3 23:05 FFF7-ADD4 -> ../../sda1

lrwxrwxrwx 1 root root 10 Feb 3 23:05 pci-0000:00:07.0-ata-1.0-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Feb 3 23:05 pci-0000:00:07.0-ata-1.0-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Feb 3 23:05 pci-0000:00:07.0-ata-1.0-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 Feb 3 23:05 pci-0000:00:07.0-ata-1.0-part4 -> ../../sda4
lrwxrwxrwx 1 root root 10 Feb 3 23:05 pci-0000:00:07.0-ata-1.0-part5 -> ../../sda5
lrwxrwxrwx 1 root root 10 Feb 3 23:06 pci-0000:00:07.0-ata-1.0-part6 -> ../../sda6
lrwxrwxrwx 1 root root 10 Feb 3 23:05 pci-0000:00:07.0-ata-1.0-part7 -> ../../sda7
lrwxrwxrwx 1 root root 10 Feb 3 23:05 pci-0000:00:07.0-ata-1.0-part8 -> ../../sda8
lrwxrwxrwx 1 root root 9 Feb 3 23:05 pci-0000:00:1d.7-usb-0:1:1.0-scsi-0:0:0:0 -> ../../sdb
lrwxrwxrwx 1 root root 10 Feb 3 23:05 pci-0000:00:1d.7-usb-0:1:1.0-scsi-0:0:0:0-part1 -> ../../sdb1

But i don't know enough about the script to know if it discriminates to only use sata as per the original intent
`KERNEL!="sdb[0-9]", GOTO="abort_rule"

ACTION=="add", RUN{program}+="/usr/bin/systemd-mount --no-block --automount=no --collect /dev/disk/by-uuid/36071622-61b5-4f69-bab3-27e03c46357d /mnt/data/supervisor/media" ACTION=="remove", RUN{program}+="/usr/bin/systemd-umount /mnt/data/supervisor/media"

LABEL="abort_rule"

also after saving this script, do i just need to restart the system or do i need to update some reference?

any help would be great thanks

@Moondevil-ha
Copy link

Moondevil-ha commented Feb 4, 2022

@G2G2G2G
Copy link

G2G2G2G commented Feb 4, 2022

Is this what is supposed to be used for internal drives? I run motioneye and the "root storage path" isn't actually the root storage path, it's somewhere in /var/lib/docker/overlay2/randomGeneratedStringThatIsChangedEveryBoot/rootpathhere

@Tekno-man
Copy link

Tekno-man commented Feb 4, 2022

thanks @Moondevil-ha I'm running Hassio in a VM on proxmox. I will have a dig around then as to why it looks different and why i cant find the media folder.

@Tekno-man
Copy link

Tekno-man commented Feb 4, 2022

@Moondevil-ha also I am definately getting this from the hassio machine itself as i am opening up a terminal from proxmox.

@Tekno-man
Copy link

Tekno-man commented Feb 4, 2022

@Tekno-man
Copy link

Tekno-man commented Feb 5, 2022

i found that media is mounted on sda8 at /mnt/data/supervisor/media. I just modified the original USB script and now it works, must be some issue with my set up and the UUID. Thanks

@Moondevil-ha
Copy link

Moondevil-ha commented Feb 5, 2022

@Lachfrosch
Copy link

Lachfrosch commented Feb 6, 2022

I am having some Problems with my ConBee II USB Stick after using this. I am running HomeAssistant on a Pi 4, using a ConBee Stick fpr Zigbee connectivity. All my Lights are no longer controlable since I used this configuration. In terms of mounting my HDD everything worked fine.
Anyone esle having this Problem or Tips on how to fix it?

@goxofy
Copy link

goxofy commented Mar 16, 2022

hello,I have a question about automount, so why use the automount=no parameter?

If I want to auto mount the usb stick( always plug on my device ) every time the haasos boot, does I only need to do is set the automount=yes?

@Noob25930
Copy link

Noob25930 commented Mar 20, 2022

I mounted my usb and was able to see it in the media folder but unable to see content. Restarted HA restarted host. Running HA in baremetal (dell optiplex). Can anyone guide to what went wrong? Format is exfat of the usb drive.

@paoloantinori
Copy link

paoloantinori commented Mar 28, 2022

what happens if you mount the partitions manually from root shell? Is the partition seen correctly in that case?

@justfly1111
Copy link

justfly1111 commented Apr 2, 2022

what happens if you mount the partitions manually from root shell? Is the partition seen correctly in that case?

paoloantinori nothing happens i been trying to mount a usb all day it says you dont have permission are you root which of course so i tried sudo mount -f /dev/sda4 ~/mnt/ and using the force flag it returns no errors and you would think the partition shoul;d be mirrored but that too ended up fruitless with an empty mountpoint so i been trying to figure it out all day today hopefully the code supplied here works else i have alot of catch up to get back to where i was prior to migrating from my microsd instance to a 64g emmc and made a full backup of homE assistant via the backups settings integrations sectionmoointr and because am actively migrating it over i made sure to make a backup tar of everything new and all my newest updates... sadly I forgot to download it so unless i can get the sd card mounted somewhere some how then Im going to have reconfigure and redownload all my custom configs themes hacs and yamls addons and integrations along side their current and correct certs from acme because i neglected to rembember to download the backup to my personal computer after creating it on the sd card so theres about a week worth of integrations hacs repositories configurations and settings and addons that im going to have to reconfigure and im dreading to do so i hope that this suggestions do in fact work itll save me se to a week and a half of work that i really would love not having to redo so wish me luck my fingers are sure as hell crossed

@jb773
Copy link

jb773 commented Apr 15, 2022

These were awesome instructions, thank you @eklex for posting them.

I wanted to share a slight modification to these instructions that was useful for my specific use case that may benefit others. I have Home Assistant OS running on a Proxmox VM and I wanted to add a second VirtIO disk for Frigate to use.

This really does give the best of both worlds - if you want to keep the fully managed Home Assistant OS (and retain supported installation status!) but you want to mount a second disk.

Here is what I did and what you can do if you want to get this working:

HOW TO ADD A SECOND VIRTUAL DISK TO HOME ASSISTANT OS RUNNING AS A VIRTUAL MACHINE:

  1. Shut down the VM and add a VirtIO disk in Proxmox (or your prefered virtualization software) of your desired size
  2. Start up the VM and login to the core OS. On Proxmox you can use NoVNC to get to the shell and then type "login" at the prompt which then gets you into the OS. **Another path is to SSH to port 22222 if you have the Port 22222 add-on installed - ** I did this since I already had it configured and it was just easier than messing with NoVNC as you can copy/paste/SCH in/etc.
  3. fdisk /dev/vdb (mine appeared as vdb. To verify, do fdisk --list and look for your new disk)
  4. type "n" to add a new partition. All default options are fine. Make sure to use "w" at the end to commit your changes
  5. mkfs.ext4 /dev/vdb1 to format the new partition
  6. lsblk -f and write down the UUID
  7. vi /etc/udev/rules.d/80-mount-additional-storage.rules (if you're not comfortable with vi and if you have port 22222 access, use your favorite SCP client to log in and edit the file locally, then upload. I prefer Nano but it doesn't come with Home Assistant OS)
  8. Insert the following. Note that I changed my mount directory to be Frigate since this is where Frigate saves its media files. In any case, if you have an existing folder here, please delete or rename it to something else.
KERNEL!="vdb[0-9]", GOTO="abort_rule"

ACTION=="add", RUN{program}+="/usr/bin/mkdir -p /mnt/data/supervisor/media/frigate", RUN{program}+="/usr/bin/systemd-mount --no-block --automount=no --collect /dev/disk/by-uuid/<your UUID goes here>	/mnt/data/supervisor/media/frigate"
ACTION=="remove", RUN{program}+="/usr/bin/systemd-umount /mnt/data/supervisor/media/frigate", RUN{program}+="/usr/bin/rmdir /mnt/data/supervisor/media/frigate"

LABEL="abort_rule"
  1. Reboot your system
  2. Browse to the path within /media that you designated, keeping in mind that your Docker path will be slightly different from the path at the supervisor level. For example /mnt/data/supervisor/media/frigate will appear as /media/frigate. Make sure you see the folder.
  3. Run df -h and look for that same folder. You should see it now attached to a new disk with a different size/different free space from your boot drive.
  4. Now try copying some files in there and do df -h again, you should see the space on the new drive shrinking and space on the boot drive freeing up.

Hope this helps someone.

@goxofy
Copy link

goxofy commented Apr 15, 2022

@jb773 Thank you very much! You sovled my problem!

@RaulVKoNe
Copy link

RaulVKoNe commented Apr 23, 2022

Tengo algunos problemas con mi memoria USB ConBee II después de usar esto. Estoy ejecutando HomeAssistant en un Pi 4, usando una conectividad ConBee Stick fpr Zigbee. Todas mis luces ya no son controlables desde que usé esta configuración. En cuanto al montaje de mi disco duro, todo funcionó bien. ¿Alguien tiene este problema o consejos sobre cómo solucionarlo?

Put a USB extension cable for the Conbee. If you don't interfere

@AlRiachi
Copy link

AlRiachi commented May 4, 2022

It worked with me, but the driver does not have write permission I tried chmod 777 command but the result is Read-only file system
can anyone help me with it?

Thanks

@jb773
Copy link

jb773 commented May 4, 2022

It worked with me, but the driver does not have write permission I tried chmod 777 command but the result is Read-only file system can anyone help me with it?

Thanks

Not sure I know the answer but could you share where you are mounting to? I believe most of the filesystem is marked read-only so you'd want to mount to one of the locations that isn't. I'm in /mnt/data/supervisor/media/frigate since that suits my use case - not sure what yours is. Are you seeing read-only within the "master" terminal (port 22222 or type login at the console), within HA itself (port 22) or both?

@zeehio
Copy link

zeehio commented May 15, 2022

Here is a possible explanation and a solution for those of you who can't write to the mounted disks (@AlRiachi). I guess you are using NTFS partitions. I had the same problem as you have and this solution worked for me.

There are three NTFS drivers:

  • One is named "ntfs", it exists since ~2001 and it provides read only support. This is the driver you are probably using. You can verify this by looking at the output of the mount | grep ntfs command when your usb drive is mounted, you should see at least one line that includes type ntfs.
  • Another driver is named "ntfs-3g", it is implemented as a "filesystem in user space" or "fuse". It provides read and write support, but since it is fuse it has larger overhead than other filesystem drivers AND it is not always installed (for instance it is not available on Home Assistant OS).
  • There is a third driver, named "ntfs3", implemented in the kernel (not as fuse) and introduced far more recently, in Linux 5.15. If you have the upcoming Home Assistant OS 8.0 or later, then you will have Linux 5.15 and this driver installed. I had to enable the beta channel to get it installed today, but it's becoming available soon for everyone I guess. This driver provides read and write support for NTFS partitions!

Since ntfs filesystems now have two drivers in the kernel (ntfs and ntfs3) the autodetection has to choose one. By default they all still use ntfs, but I guess they tools will update and change to the other driver, or maybe in the future the ntfs3 driver will replace the older ntfs driver. We'll see.

So, if you are using Home Assistant OS 8.0 or later, which includes the linux kernel 5.15, then you can modify the udev rules above to use the newer ntfs3 driver. Here are the changes I made to the file above:

# Determine the mount point
ENV{mount_point}="/mnt/data/supervisor/media/%E{dir_name}"

# If filesystem is ntfs, use the ntfs3 driver, so we get rw support
# Home Assistant Operating System 8.0 or later required (linux kernel 5.15)
ENV{ID_FS_TYPE}=="ntfs", ENV{fstype}="-t ntfs3"
ENV{ID_FS_TYPE}!="ntfs", ENV{fstype}="-t auto"

# Mount the device on 'add' action (a.k.a. plug the USB drive)
ACTION=="add", RUN{program}+="/usr/bin/mkdir -p %E{mount_point}", RUN{program}+="/usr/bin/systemd-mount %E{fstype} --no-block --automount=no --collect $devnode %E{mount_point}"

As you can see, I first define an environment variable that specifies that if the filesystem is ntfs then the environment variable contains "-t ntfs", otherwise it uses "-t auto". Afterwards, in the action line, I pass the value of that environment variable as an argument to the systemd-mount command (using %E{fstype}), so it will use the autodetection by default unless the partition is ntfs, where it will use the ntfs3 driver I explicitly gave above.

The main caveat of this change is that it only works on linux kernels >= 5.15, and to be precise we would need to check that modinfo ntfs3 does not return an error to ensure that the driver is installed. (I just confirmed the driver is available on Home Assistant OS 8.0)

I put my changes here https://gist.github.com/zeehio/7c67d531236e39496c39b3c5c3b3f268 but once Home Assistant OS 8.0 becomes available and a large fraction of users have updated to it I would suggest @eklex to merge my suggestion here, if he likes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment