How to use an external HDD that's not permanently attached (eg PLEX movies drive)

Roberto24

New Member
Jul 23, 2024
9
0
1
Hi, I want to install a PLEX LXC for accessing movies and shows thtat are currently stored on a USB HDD.
I know how to passthrough a USB HDD, but I don't want to keep the USB drive attached to my homeserver all the time to watch a movie every now and then due to the energy consumption. Do I need to mount, unmount the USB drive each time or is there a simpler way to realize this?
What would happen if I keep the USB HDD mounted but simply detach it or power it off after exiting the Plex LXC and power it on again before opening Plex next time? Would this work fine or will it cause problems? The drive could be mounted read-only if that helps..

I read somewhere that AutoFS might be a good option, but I know nothing about it / how this needs to be set up.. Can anyone give me some advice?

Thank you !
 
Containers don't support hotplug (or unplug or replug) and your data might be written on the mountpoint instead of the drive by the container. Maybe write some (generic Linux) udev rules (on the Proxmox host) to detect your drive being added or removed and restart the container automatically? Or do some additional commands to it to inform the software inside?

EDIT: Here is an example rule that switches my display when a USB keyboard is unplugged: ACTION=="remove", ENV{ID_BUS}=="usb", ENV{ID_INPUT_KEYBOARD}=="1", RUN+="/usr/bin/ddcutil setvcp 60 x03"
 
Last edited:
I'm trying to create an automatic USB drive mount using udev rules.
I found the script and changed it a bit:
nano /usr/local/bin/auto-mount-usb.sh
Code:
#!/bin/bash

DEVICE="$1"

PARTITION_LABEL=$(lsblk -no LABEL "$DEVICE")
PARTITION_TYPE=$(lsblk -no FSTYPE "$DEVICE")

MOUNT_POINT="/mnt/usb/$PARTITION_LABEL"

ALLOWED_FS=("ext4" "ntfs" "xfs" "btrfs" "vfat")
SYSTEM_PARTITIONS=("boot" "root" "swap" "" "efi")
DISK_ID=("/dev/sda" "/dev/sda1" "/dev/sda2" "/dev/sda3" "/dev/sda4")

echo "$DEVICE $MOUNT_POINT $PARTITION_LABEL $PARTITION_TYPE"

if [[ " ${SYSTEM_PARTITIONS[@]} " =~ " ${PARTITION_LABEL,,} " ]] || \
   [[ " ${DISK_ID[@]} " =~ "$DEVICE" ]] || \
   [[ ! " ${ALLOWED_FS[@]} " =~ " ${PARTITION_TYPE} " ]]; then
    echo "Urządzenie $DEVICE jest prawdopodobnie partycją systemową lub ma nieobsługiwany system plików. Pominięto."
else
    mkdir -p "$MOUNT_POINT"
    mount "$DEVICE" "$MOUNT_POINT"
    chmod 777 "$MOUNT_POINT"

    echo "Urządzenie $DEVICE zamontowane w $MOUNT_POINT"
fi
chmod +x /usr/local/bin/auto-mount-usb.sh


udev rules: nano /etc/udev/rules.d/99-auto-mount-usb.rules

Code:
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z][0-9]", RUN+="/usr/local/bin/auto-mount-usb.sh /dev/% k"
udevadm control --reload-rule
udevadm trgged



I don't know why it doesn't work - it creates a directory but doesn't mount.
If I manage /usr/local/bin/auto-mount-usb.sh /dev/sdb3,
the disk is installed.
When replug USB, there is only a directory.
I don't know anything about this - can anyone help me?
 
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!