In particular, how to catch it for the purposes of automounting the DVD filesystem?
Update in response to Oli's answer:
udev
seems to be able to detect the insertion of DVD, as demonstrated by changes in udevadm
's output before and after the event:
% udevadm info -q env -n /dev/cdrom
which results in additional environment variables as follows:
ID_CDROM_MEDIA=1
ID_CDROM_MEDIA_DVD=1
ID_CDROM_MEDIA_SESSION_COUNT=1
ID_CDROM_MEDIA_STATE=complete
ID_CDROM_MEDIA_TRACK_COUNT=1
ID_CDROM_MEDIA_TRACK_COUNT_DATA=1
ID_FS_LABEL=20130926_Backup
ID_FS_LABEL_ENC=20130926_Backup
ID_FS_TYPE=udf
ID_FS_USAGE=filesystem
However, when I tried the following udev rule (which tries to detect ID_FS_TYPE=="udf"),
SUBSYSTEM=="block", ENV{ID_CDROM}=="?*", ENV{ID_FS_TYPE}=="udf", ENV{ID_PATH}=="pci-0000:00:1f.2-scsi-0:0:0:0", ACTION=="add", RUN+="/bin/mount -t udf -o ro /dev/cdrom /var/run/usbmount/dvdrom"
it doesn't work. What could be the problem?
Solution
Was finally able to solve this thanks to Oli's suggestions:
/etc/udev/rules.d/autodvd.rules:
SUBSYSTEM=="block", ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="pci-0000:00:1f.2-scsi-0:0:0:0", ACTION=="change", RUN+="/usr/local/bin/autodvd"
/usr/local/bin/autodvd:
#!/bin/bash
{
if [ $ID_CDROM_MEDIA -eq 1 ]; then
mkdir -p /var/run/usbmount/dvdrom
mount -t $ID_FS_TYPE -o ro /dev/cdrom /var/run/usbmount/dvdrom
else
umount -l /var/run/usbmount/dvdrom
rm -rf /var/run/usbmount/dvdrom
fi
} &>> "/var/log/autodvd.log" &
Apparently ACTION=="add"
isn't triggered when DVD disc is inserted. So instead, we use ACTION=="change"
and then detect the insert or eject event via scripting.