# kernel does not report to udev when cd inserted

## ripa

Hi,

Could you please help me: When a cd is inserted, I would like to send notification to an application via a script.

What I have now are some rules defined in /etc/udev/rules.d/, which work fine for usb devices, but not for cd's.

Just in case you want to know, the following is a list of rules defined:

```
ACTION=="add",SUBSYSTEM=="block",KERNEL=="sr[0-9]*",RUN+="/usr/bin/muc_cdrom $root/$kernel $number $devpath $name add"

ACTION=="remove",SUBSYSTEM=="block",KERNEL=="sr[0-9]*",RUN+="/usr/bin/muc_cdrom $root/$kernel $number $devpath $name remove"

ACTION=="change",SUBSYSTEM=="block",KERNEL=="sr[0-9]*",RUN+="/usr/bin/muc_cdrom $root/$kernel $number $devpath $name change"

ACTION=="add",SUBSYSTEM=="block", SUBSYSTEMS=="usb|ieee1394",RUN+="/usr/bin/muc_usb $root/$kernel $number $devpath $name add"

ACTION=="remove",SUBSYSTEM=="block", SUBSYSTEMS=="usb|ieee1394",RUN+="/usr/bin/muc_usb $root/$kernel $number $devpath $name remove"

ACTION=="change"SUBSYSTEM=="block", SUBSYSTEMS=="usb|ieee1394",RUN+="/usr/bin/muc_usb $root/$kernel $number $devpath $name change"

```

I used the following command to watch what is reported from the kernel to udev. 

```
udevadm  monitor --kernel
```

When usb's are inserted and removed, I get output like this: 

 *Quote:*   

> KERNEL[1298364116.192199] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-1 (usb)

 

But nothing comes when the cd is inserted.

Only when I mount the cd then the following is output by udevadm:

 *Quote:*   

> KERNEL[1298371144.226237] change   /devices/pci0000:00/0000:00:07.1/host1/target1:0:0/1:0:0:0 (scsi)
> 
> KERNEL[1298371144.226279] change   /devices/pci0000:00/0000:00:07.1/host1/target1:0:0/1:0:0:0/block/sr0 (block)
> 
> KERNEL[1298371144.246243] change   /devices/pci0000:00/0000:00:07.1/host1/target1:0:0/1:0:0:0 (scsi)
> ...

 

I have a similar (vmware) machine with ubuntu on it, but it behaves like I want, so

Is there something missing in my kernel?

Thank you.

Risto

----------

## depontius

I believe this may be a fundamental limitation in the kernel.  Keep in mind that there are settings on desktops like GNOME about polling the CD drive, that powertop will advise you to turn off.

Also, this situation may be chaning.  ISTR seeing something about getting media-change turned into an event in 2.6.38, but I'm pretty fuzzy on if it made it in, and if it will really be considered an "event" and passed to udev, etc.  But I do know that the situation is currently not good, but it sounds like it's going to get better.

----------

## ripa

As I said before, I have an ubuntu machine which behaves like I want. It does get a kernel event, when cd is inserted:

```
$ udevadm monitor --kernel

monitor will print the received events for:

KERNEL - the kernel uevent

KERNEL[1266845345.858161] change   /devices/pci0000:00/0000:00:07.1/host1/target1:0:0/1:0:0:0 (scsi)

KERNEL[1266845345.859717] change   /devices/pci0000:00/0000:00:07.1/host1/target1:0:0/1:0:0:0/block/sr0 (block)
```

The ubuntu machine has kernel: 2.6.32-24-generic

while the gentoo machine has kernel 2.6.34-gentoo-r6

So perhaps there is no limitation in the kernel, or can it be that there is something external in ubuntu that handles the cd detection?

I appreciate your knowledge and experience.

Many thanks for reading my questions, and even more thanks for help   :Smile: 

----------

## idella4

ripa,

I don't know offhand re kernel events, but to check the kernel state, take the kernel config from ubuntu and observe / copy its settings.

As a one off, just as well to use the whole config and compile.  You could do a diff to observe the difference, remembering a distro kernel will have almost everything turned on, so doing a diff will require much more cutting down of unrelated settings to get to the cd events that you're concerned with.

----------

## ripa

Thanks. Will try that over the next few weeks.

----------

## VoidMage

Most likely ubuntu has automount set up, so you're actually seeing both insert and automount there.

----------

## depontius

I didn't realize that automount would kick out a udev event.  I have always been under the impression that automount was handled by some daemon polling the drive - shutting down that polling is one of the recommendations made by PowerTop.

What events can the kernel recognize and throw for the cdrom?

I've always rather wished that pushing the button would simply open the drive door - assuming that there are no pending writes at the time.  It doesn't seem like that tough a thing - DVD players do it all the time.  Obviously if the drive were open for read, the next read would return a fail to the application - but that's what I should expect in such a case.

----------

