[SOLVED] Mount USB drive in Hassio to be used on the Media Folder with udev customization

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

See this reply for how to do it.

@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

  1. 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.

20 Likes

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

2 Likes

@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.

1 Like

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…

1 Like

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.

1 Like

I tried it, but no additional folder in media sources.



Do I have to create a partiton on the USB HDD? HDD is ntfs formated under Windows.

You should use ext4 @FlyByWire

According to this instruction, it does not work for me and in HAOS core-2022.12.3 there is no Supervisor → System, and there in the box Host System, click on the kebab menu and there click on “Import from USB". I do the import via the ha os import console. Are you currently running core-2022.12.3 and supervisor-2022.11.2?

I only managed to do this, but I can’t get the USB flash drives to start automatically

First - THANK YOU for documenting this so thoroughly. I’m running HA on a thin client PC on an internal SSD, and wanted to add an external USB drive for storing dashcam video (download triggered by an HA automation).

Following these instructions, I was able to get a 1TB external drive attached and visible within my media folder inside HA. Upon seeing how easy it was, I decided to use a bigger external drive. I swapped an 8TB drive in place of the original 1TB.

The 8TB was recognized right away and mounted, and I’m able to write files to it. The problem is, HA doesn’t know that it’s a much bigger drive. It’s still being seen as a 1TB drive by running “df -h”.

I’ve Googled my brains out, but I can’t figure out how to make HA (or Linux perhaps) see this as an 8TB drive instead of the original 1TB drive.

Can anyone help?

Hi,

Which rule did you use as I got the same setup as you, but I can’t get it to work.

Did you change anything on the rule?

Did you formatted your drive as NTFS? You might want to try FAT?

There’s some more info on nfts over here: udev rule for Home Assistant OS (hassio) to mount USB drives into the Supervisor Media directory · GitHub

Thx,

Pim