Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lpt2007/d51621dbc2657cf3d6a99e6a85bcd699 to your computer and use it in GitHub Desktop.
Save lpt2007/d51621dbc2657cf3d6a99e6a85bcd699 to your computer and use it in GitHub Desktop.
# udev rule
# Auto Mount passtrough drive in proxmox guest Home Assistant OS
#
# Script cen be used to add data of software to separate drive
# Example: frigate addon configuration
#
# mkdir /media/label-from-this-script/data
# mkdir /media/label-from-this-script/data/frigate
# ln -s /media/label-from-this-script/data/frigate /media/frigate
#
#
# Filter block devices, ignore sda (OS disk)
KERNEL=="sda[0-9]", GOTO="abort_rule"
KERNEL!="sd[a-z][0-9]", GOTO="abort_rule"
# Import the partition info into the environment variables
IMPORT{program}="/usr/sbin/blkid -o udev -p %N"
# Skip if partition is not a filesystem
ENV{ID_FS_USAGE}!="filesystem", GOTO="abort_rule"
# Skip CONFIG key (Home Assistant specific)
ENV{ID_FS_LABEL}=="CONFIG", GOTO="abort_rule"
# Skip devices without label
ENV{ID_FS_LABEL}=="", GOTO="abort_rule"
# Use label as dir_name
ENV{dir_name}="%E{ID_FS_LABEL}"
# Set mount point
ENV{mount_point}="/mnt/data/supervisor/media/%E{dir_name}"
# Mount on add
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}"
# Unmount on remove
ACTION=="remove", RUN{program}+="/usr/bin/systemd-umount %E{mount_point}", RUN{program}+="/usr/bin/rmdir %E{mount_point}"
LABEL="abort_rule"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment