12 February 2025

Ensuring USB DVD order

As my USB dvd drives were being detected into a seemingly random order, I wanted to be able to control what device each was being assigned.


Adding udev rules

  • Find serials to add
    • sudo udevadm info /dev/sr0 | grep ID_SERIAL_SHORT
    • sudo udevadm info /dev/sr1 | grep ID_SERIAL_SHORT
    • sudo udevadm info /dev/sr2 | grep ID_SERIAL_SHORT
  • Create /etc/udev/rules.d/99-dvd.rules
ACTION="add", KERNEL="sr[0-9]", ENV{ID_SERIAL_SHORT}="first drive serial", SYMLINK+="dvd0"

ACTION="add", KERNEL="sr[0-9]", ENV{ID_SERIAL_SHORT}="second drive serial", SYMLINK+="dvd1"

ACTION="add", KERNEL="sr[0-9]", ENV{ID_SERIAL_SHORT}="third drive serial", SYMLINK+="dvd2"

  • Reboot or force rerunning the rules
    • sudo udevadm control --reload
    • sudo udevadm trigger
  • However, this did not work
  • Edit /etc/udev/rules.d/99-dvd.rules and remove the ACTION
KERNEL="sr[0-9]", ENV{ID_SERIAL_SHORT}="first drive serial", SYMLINK+="dvd0"

KERNEL="sr[0-9]", ENV{ID_SERIAL_SHORT}="second drive serial", SYMLINK+="dvd1"

KERNEL="sr[0-9]", ENV{ID_SERIAL_SHORT}="third drive serial", SYMLINK+="dvd2"

  • Reboot or force rerunning the rules
    • sudo udevadm control --reload
    • sudo udevadm trigger


Outcome

Success, it now creates the /dev/dvd* in a consistent order. Unfortunately, Handbrake still tries to use the /dev/sr* labels.


Appendix

Sources


14 January 2025

Recursively Mount ZFS datasets

In order to simplify mounting and unmounting my encrypted volumes, I wanted some scripts.


Recursively Mount

#!/usr/bin/env sh
dataset=$1

zfs load-key "${dataset}"
zfs list -rH -o name "${dataset}"  | xargs -L 1 zfs mount


Unmount and unload key

#!/usr/bin/env sh
dataset=$1

zfs unmount "${dataset}"
zfs unload-key "${dataset}"


Usage

# mount example
sh mount.sh storage/encrypted
Passphrase:

# unmount example
sh unmount.sh storage/encrypted


Appendix

Sources