how the hell isn’t this supported?!
I have no idea… would be nice.
A little dumb story I want to share in case it could save someone else some time.
I 've been using this solution with a FAT drive successfully for a while. I’m using it mostly to store media files, have Jellyfin as mediacenter, and having it connect with a Torrent downloader and all the related services.
It was working fine.
Until a certain day I’ve noticed that my Media center library was empty.
I then connected via ssh to see if the drive was still there or if it was an hw failure, but actually the filesystem was there. Although something odd happened: only the metadata files were there, and not the multimedia files.
I considered multiple options: some security breach that had deleted my media files, me configuring something wrong on the 2 or 3 sw that access the same files or anything. I was annoyed, but it could have been my fault.
Then I tried the drive on my main laptop and all the multimedia files were there, next to the metadata. Interesting.
I’ve then started speculating. Was the underlying linux or even Hassio doing some trick to prevent specific file extensions? Was I facing some oddity at container overalyfs level?
After a while I’ve realized what happened:
I must have restarted my rpi4 with the drive unplugged. That prevented the drive to be mounted. But all the addons that are configured to use those folders, have recreated the directory structure (mounted probably on the main SD). This has triggered the generation of the metadata and descriptors, with the result of letting me believe the media files had been deleted, while I was instead looking at a totally independent filesystem.
For some reason, the udev rules, were not doing their job if the mount point already contained a folder structure!
The solution was to stop all the addon that were using that folder, manually delete the mount point, trigger udev to do his job (either with the command commented in the example or physically unplugging and replugging). This fixed the problem, and the files were now visible again.
I suspect that in the official examples we have all been using, there could be room for a flag that could force to mount even if the destination mount point is already attached to something. I will try to investigate this, but be aware of this risk.
This would explain exactly the weird behavior i had! Nice job
Yes, you probably configured those addons to use the conbee via /dev/usbXXX
But now the other usb device uses it. Try specific hardware name in the Z2Mqtt config
@paoloantinori Apparently, I’m too dumb to make this work even with such extensive documentation. Here are the steps i followed.
- Created the 80-rules files. Imported them into the configuration by rooting into HA CLI (Connected Monitor & keyboard to HA Blue)
- The file has been imported successfully and I’m able to find them in /etc/udev/ folder.
But I don’t see the /dev/sda2 drive mounted to /mnt/…/media folder. Have restarted, rebooted the host with no luck!
Running HA Core: 2022.8.2
Can someone help me out please?
I have the same problem. Tried with both version 2022.8.2 and earlier version 2022.6.7. The configuration file does not load. However, if I try to manually mount /dev/sdb1 in /mnt/…media/ I see it. But in any case at each reboot I lose this configuration.
I have another problem when I try to write via samba to the manually mounted drive it does not allow me to do so because of insufficient permissions. I tried doing chmod 777 on the /mnt/…media folder but it doesn’t change.
Does anyone have any solutions?
Thank you
Hi folks - I’ve been tinkering and got this working with NTFS formatted drive, so thought I’d do a quick ‘how-to’ in the simplest terms I can - mostly so I have something to come back to if I need it!
Working on:
Home Assistant 2022.9.0
Supervisor 2022.08.6
Operating System 8.5
Frontend 20220907.0 - latest
- Format a USB and call it CONFIG. Create a folder inside called udev. Create a text file and call it:
80-mount-usb-to-media-by-label.rules
Make sure you overwrite the .txt file extension. Open this with notepad, and paste the following in
This version is if you are booting from an SD Card
#
# 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/a6445af71282045c2ea92f1dea8d2f9e518bd008/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[a-z][0-9]' if booting from a USB drive (e.g.: sda)
KERNEL!="sd[b-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}"
# 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}"
# 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"
This version is if you are booting from an SSD via USB
#
# 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/a6445af71282045c2ea92f1dea8d2f9e518bd008/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[b-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}"
# 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}"
# 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"
Plug your USB in, and navigate to:
yourHAIPaddress:8123/hassio/system/info
This will take you to the Supervisor menu that’s disappeared from the left bar in current HA versions.
In the Host box, look at the bottom for Reboot Host & Shutdown Host buttons - to the right is a burger menu, click this and ‘Import for USB’
Refresh the log below and you should see:
22-09-08 13:46:38 INFO (MainThread) [supervisor.os.manager] Synchronizing configuration from USB with Home Assistant Operating System.
22-09-08 13:46:38 INFO (MainThread) [supervisor.host.services] Restarting local service hassos-config.service
You can now unplug the USB stick and insert your drive. Give it 30 seconds then check the Media menu on the left bar - you should see your drive. You will not see any contents - Reboot HA and when it comes back up, everything will populate.
You can import these folders to the HA version of Plex Media Server. If you have Samba Share, you can access the HDD in the media folder and write files in.
this solution only showed my drive on file explorer, but even when i restart HA my files is not found, i tested write a file and apperars to work, i use a USB drive on u59 beelink and HA via proxmox
@promithius What happens when you upgrade HA to say 2022.9.2?
If I remember correctly others have added udev rules, but you have to do it on both disk partitions and then I am not sure it survives upgrades.
I updated to a new core version last night and everything remained in place and accessible.
Is this also working if used on x86 and booting from SATA SSD? Or do I have to change something in the rules?
Also, I join the question of whether it will run on a machine where Home Assistant Supervised is running Debian?
I use this on deb/docker/supervisor on my rpi4
This is where the file goes
cat /etc/udev/rules.d/80-mount-docker-additional-storage.rules
This is changed.
This directory is different in docker/supervisor compared to Home Assistant OS
ENV{mount_point}="/usr/share/hassio/media/%E{dir_name}"
The entire file I use, it is possibly out of date, although still works.
#
# 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/b2925966a880002793ed3068d97811b9f0cc87af/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[b-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}="/usr/share/hassio/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
Where can I find the file and revert the rule?
did u got it to work?
i’m also in a x86 and 1st Sata ssd is for the HA system etc, and now i want to get my 2nd sata ssd automaticly get mounted in boot up…
with the above i get USB drives into my local media dir, but no content is showing.
banging my head against the wall for 2 days now…
edit*:
more stupid: it did not mount the usb as above in my post, it makes a new DIR in the media dir named as the usbstick…
how difficult can it be… #$%#$@ zucht…
I’m also trying to understand and implement @promithius’s solution, but what is confusing to me is the lack of distinction between a USB stick and a HDD external drive. What made me realize there is a distinction is the last paragraph, where OP mentiones:“You can now unplug the USB stick and insert your drive”. With this in mind, I’m also confused with the two rules version, as there are 3 storages involved: the SD card where the OS boots from, the USB stick in this post and the HDD External Drive what I’m looking to actually mount for media.
Can someone clarify all this? Maybe @promithius?
Did you remove your USB drive that has the udev folder and rules file? I suspect, the file is being overwritten everytime you boot with the USDB drive with udev file/folder.