Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 16865  / 3 Years ago, thu, august 5, 2021, 2:39:23

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.


More From » dvd

 Answers
7

UDEV sends out events for CD/DVD drives (I've just tested it with udevadm) so you should be able to either write a UDEV script or write an upstart script like so:



start on block-device-added

task

script
if [ `$DEV` -eq "/dev/sr0" ]; then
# do something
fi
end script


You might have to be careful about checking its mount status. I'm pillaging this from a similar answer of mine which is a bit more explanatory.






When running udevadm monitor --property --udev, here is the output I got when putting in a DVD (--property makes this quite verbose but it lets you know exactly what you're dealing with):



UDEV  [2251414.166711] change   /devices/pci0000:00/0000:00:1c.1/0000:07:00.0/ata17/host16/target16:0:0/16:0:0:0/block/sr0 (block)
ACTION=change
DEVLINKS=/dev/cdrom /dev/cdrw /dev/disk/by-id/ata-Optiarc_DVD_RW_AD-7240S /dev/disk/by-label/UT2004_DVD /dev/disk/by-path/pci-0000:07:00.0-scsi-0:0:0:0 /dev/dvd /dev/dvdrw
DEVNAME=/dev/sr0
DEVPATH=/devices/pci0000:00/0000:00:1c.1/0000:07:00.0/ata17/host16/target16:0:0/16:0:0:0/block/sr0
DEVTYPE=disk
DISK_MEDIA_CHANGE=1
GENERATED=1
ID_ATA=1
ID_ATA_SATA=1
ID_ATA_SATA_SIGNAL_RATE_GEN1=1
ID_BUS=ata
ID_CDROM=1
ID_CDROM_CD=1
ID_CDROM_CD_R=1
ID_CDROM_CD_RW=1
ID_CDROM_DVD=1
ID_CDROM_DVD_PLUS_R=1
ID_CDROM_DVD_PLUS_RW=1
ID_CDROM_DVD_PLUS_R_DL=1
ID_CDROM_DVD_R=1
ID_CDROM_DVD_RAM=1
ID_CDROM_DVD_RW=1
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_CDROM_MRW=1
ID_CDROM_MRW_W=1
ID_FS_LABEL=UT2004_DVD
ID_FS_LABEL_ENC=UT2004_DVD
ID_FS_TYPE=iso9660
ID_FS_USAGE=filesystem
ID_FS_VERSION=Jolietx20Extension
ID_MODEL=Optiarc_DVD_RW_AD-7240S
ID_MODEL_ENC=Optiarcx20DVDx20RWx20AD-7240Sx20x20x20x20x20x20x20x20x20x20x20x20x20x20x20x20x20
ID_PATH=pci-0000:07:00.0-scsi-0:0:0:0
ID_PATH_TAG=pci-0000_07_00_0-scsi-0_0_0_0
ID_REVISION=1.00
ID_SERIAL=Optiarc_DVD_RW_AD-7240S
ID_TYPE=cd
MAJOR=11
MINOR=0
SEQNUM=4400
SUBSYSTEM=block
TAGS=:udev-acl:
UDEV_LOG=3
UDISKS_PRESENTATION_NOPOLICY=0
USEC_INITIALIZED=10393360

[#28994] Friday, August 6, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hical

Total Points: 498
Total Questions: 106
Total Answers: 117

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
hical questions
Sun, May 9, 21, 00:59, 3 Years ago
Fri, Jun 25, 21, 03:06, 3 Years ago
Thu, May 19, 22, 15:32, 2 Years ago
;