[clug] Figuring out the optical disk type

Simon Oxwell soxwell at gmail.com
Fri Sep 16 13:39:40 UTC 2016


Ah-ha!

So, whilst idly wondering how udev figured stuff out, I've found the secret
magic is:

/lib/udev/cdrom_id /dev/sr0

Neat.


Simon

On 16 September 2016 at 22:51, Simon Oxwell <soxwell at gmail.com> wrote:

>
> I'm finally getting around to a project to get my home server
> automatically rip audio cds.
>
> As is my want, I'm trying to do this within a Linux container and an
> external DVD drive in a USB enclosure.
>
> It's been pretty easy to pass the drive into the container with these
> config lines:
>
> lxc.aa_profile = lxc-container-default-with-mounting
>
> # usb
> lxc.cgroup.devices.allow = c 189:* rwm
> lxc.mount.entry = /dev/bus/usb dev/bus/usb none bind,optional,create=dir
>
> # cdrom
> lxc.cgroup.devices.allow = b 11:* rwm
> lxc.mount.entry = /dev dev none bind,optional,create=dir
>
> And lo, there's a /dev/sr0 and a /dev/cdrom symlinked to it when the drive
> is plugged in.
>
> udev events aren't available, so a udev rule to kick off the cd rip isn't
> an option, but doing an inotifywait on /dev/sr0 looking for attribute
> changes can tell me when a cd is put into the drive.
>
> All good.
>
> My sticking point is trying to figure out the type of optical disk in the
> drive is.
>
> udevadm info /dev/sr0 in the host instance give me very useful info and
> more environment variables than I can shake a stick at:
>
> root at xoanon:~# udevadm  info /dev/sr0
> P: /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.6/2-1.6:1.0/
> host6/target6:0:0/6:0:0:0/block/sr0
> N: sr0
> L: -100
> S: cdrom
> S: cdrw
> S: disk/by-id/usb-PIONEER_BD-ROM_BDC-207D_PROLIFICMP000000002-0:0
> S: disk/by-path/pci-0000:00:1d.0-usb-0:1.6:1.0-scsi-0:0:0:0
> S: dvd
> S: dvdrw
> E: DEVLINKS=/dev/cdrom /dev/cdrw /dev/disk/by-id/usb-PIONEER_
> BD-ROM_BDC-207D_PROLIFICMP000000002-0:0 /dev/disk/by-path/pci-0000:00:
> 1d.0-usb-0:1.6:1.0-scsi-0:0:0:0 /dev/dvd /dev/dvdrw
> E: DEVNAME=/dev/sr0
> E: DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.6/2-
> 1.6:1.0/host6/target6:0:0/6:0:0:0/block/sr0
> E: DEVTYPE=disk
> E: ID_BUS=usb
> E: ID_CDROM=1
> E: ID_CDROM_BD=1
> E: ID_CDROM_CD=1
> E: ID_CDROM_CD_R=1
> E: ID_CDROM_CD_RW=1
> E: ID_CDROM_DVD=1
> E: ID_CDROM_DVD_PLUS_R=1
> E: ID_CDROM_DVD_PLUS_RW=1
> E: ID_CDROM_DVD_PLUS_R_DL=1
> E: ID_CDROM_DVD_R=1
> E: ID_CDROM_DVD_RW=1
> E: ID_CDROM_MEDIA=1
> E: ID_CDROM_MEDIA_CD=1
> E: ID_CDROM_MEDIA_SESSION_COUNT=1
> E: ID_CDROM_MEDIA_TRACK_COUNT=15
> E: ID_CDROM_MEDIA_TRACK_COUNT_AUDIO=15
> E: ID_CDROM_MRW=1
> E: ID_CDROM_MRW_W=1
> E: ID_FOR_SEAT=block-pci-0000_00_1d_0-usb-0_1_6_1_0-scsi-0_0_0_0
> E: ID_INSTANCE=0:0
> E: ID_MODEL=BD-ROM_BDC-207D
> E: ID_MODEL_ENC=BD-ROM\x20\x20BDC-207D
> E: ID_MODEL_ID=2773
> E: ID_PATH=pci-0000:00:1d.0-usb-0:1.6:1.0-scsi-0:0:0:0
> E: ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_6_1_0-scsi-0_0_0_0
> E: ID_REVISION=1.00
> E: ID_SERIAL=PIONEER_BD-ROM_BDC-207D_PROLIFICMP000000002-0:0
> E: ID_SERIAL_SHORT=PROLIFICMP000000002
> E: ID_TYPE=cd
> E: ID_USB_DRIVER=usb-storage
> E: ID_USB_INTERFACES=:080650:
> E: ID_USB_INTERFACE_NUM=00
> E: ID_VENDOR=PIONEER
> E: ID_VENDOR_ENC=PIONEER\x20
> E: ID_VENDOR_ID=067b
> E: MAJOR=11
> E: MINOR=0
> E: SUBSYSTEM=block
> E: TAGS=:seat:systemd:uaccess:
> E: USEC_INITIALIZED=337603030547
>
> but in the container, I have a smaller set:
>
> root at test06:~# udevadm info /dev/sr0
> P: /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.6/2-1.6:1.0/
> host6/target6:0:0/6:0:0:0/block/sr0
> N: sr0
> E: DEVNAME=/dev/sr0
> E: DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.6/2-
> 1.6:1.0/host6/target6:0:0/6:0:0:0/block/sr0
> E: DEVTYPE=disk
> E: MAJOR=11
> E: MINOR=0
> E: SUBSYSTEM=block
>
> My google-fu hasn't been able turn up anything useful as to what I'm
> missng or even why udevadm info isn't as forthcoming with information.
>
> Anyone have any ideas or any suggestions  as to what secret sauce I might
> be missing, or alternatively any suggestions for other command line tools
> that can identify the media type? Google searching has really only turned
> up the udevadm info command
>
> Cheers,
>
>
> Simon
>


More information about the linux mailing list