site  contact  subhomenews

Cannot write to optical drive

August 22, 2019 — BarryK

Yet another serious problem with Easy Buster. I thought that I would burn radky's Busterpup ISO to a CD, to have a look at his implementation of video playing.

I used 'burniso2cd', but the burn failed. Running the actual execution line directly in a terminal:

# xorrecord -dao -data -eject -v speed=10 dev=/dev/sr0 /mnt/sdc1/downloads2/input532/0-busterpup/buster-8.0-uefi-k4.19.56.iso
xorriso 1.5.0 : RockRidge filesystem manipulator, libburnia project.

libburn : SORRY : Cannot open busy device '/dev/sr0' : Device or resource busy
libburn : FAILURE : Cannot access '/dev/sr0' as SG_IO CDROM drive
xorriso : FAILURE : Cannot acquire drive '/dev/sr0'
xorriso : NOTE : Giving up for -eject whole -dev ''
xorriso : FAILURE : -as cdrskin: Job could not be performed properly.
xorriso : aborting : -abort_on 'FAILURE' encountered 'FAILURE'

I found it works if the CD-R is plugged in before powering-on. However, if plug in the CD after bootup, something is making it "busy". I can't see any process that has claimed it. Weird.

Hmmm, I wonder if udev has something to do with this? 

EDIT 2019-08-22:
Yes, it seemed like a udev rule is the cause. When I plug in a CD, pressing the eject button does nothing, it is locked in. The udev rule /lib/udev/rules.d/60-cdrom_id.rules is responsible. I have renamed that file to '60-cdrom_id.rules-disabled', so it will be ignored, then rebooted, and now the optical drive works properly.

Back in the early days when I introduced the 'udev' package to Puppy, I deleted most of the rules, as most were trivial or useless. This has continued right up to now, only a small subset of the 'eudev' rules are kept.

That '60cdrom_id.rules' is one of the kept rules files. It is in Pyro, and I see also in Radky's BusterPup. However, it is doing something wrong in Easy Buster. It calls the 'cdrom_id' utility, and perhaps that utility is misbehaving in Easy -- well, that is the most likely situation.

Anyway, '60-cdrom_id.rules' doesn't seem to do anything that we really need, so seems OK for it to be disabled. 

EDIT 2019-08-23:
The Linux kernel is to blame! This is the content of /lib/udev/rules.d/60-cdrom_id.rules:

ACTION=="remove", GOTO="cdrom_end"
SUBSYSTEM!="block", GOTO="cdrom_end"
KERNEL!="sr[0-9]*|xvd*", GOTO="cdrom_end"
ENV{DEVTYPE}!="disk", GOTO="cdrom_end"

# unconditionally tag device as CDROM
KERNEL=="sr[0-9]*", ENV{ID_CDROM}="1"

# media eject button pressed
ENV{DISK_EJECT_REQUEST}=="?*", RUN+="cdrom_id --eject-media $devnode", GOTO="cdrom_end"

# import device and media properties and lock tray to
# enable the receiving of media eject button events
IMPORT{program}="cdrom_id --lock-media $devnode"

KERNEL=="sr0", SYMLINK+="cdrom", OPTIONS+="link_priority=-100"


Back in the pre-udev days, we had to probe the optical drive to detect if a media has been removed. This was done every 4 seconds, in the /usr/local/pup_event/frontend-timeout script. This had to be done, because the kernel is not informed when an optical media is removed.

When I disabled '60-cdrom_id.rules', fine, xorriso worked, however, when the CD was ejected, the desktop icon remained there. There was no information provided to cause it to be removed.

The above udev rule takes care of that. The cdrom_id utility does something to pickup pressing of the eject button on the optical drive. Unfortunately, the 5.2.7 kernel as used in latest Easy Buster, now thinks that the optical drive is busy, and won't let any other app access it.

I verified this by restoring '60-cdrom_id.rules' and booting up with the 5.2.4 kernel, that I was using for earlier builds of Easy Buster. The problem has gone away!

I need to examine the kernel source changes since 5.2.4. If this issue is not identified, I will stay with 5.2.4. 

EDIT 2019-08-23:
I compiled the 5.2.9 kernel, same configure as for 5.2.4 and 5.2.7, this time left out the "cap_sys_mount" patch, just in case that is the cause.

I am able to manually eject a DVD, but gnome-mpv fails to play it, reports lots of read errors. I changed to the 5.2.4 kernel, rebooted, ran gnome-mpv again. it plays the same DVD perfectly.

Something has gone wrong with the kernel. I want to get Easy 2.1 out, so will stay with the 5.2.4 kernel.

Oh, there is one difference between compiling of the 5.2.4 and 5.2.9 kernels. For the former, used Debian's gcc version 7, for the latter used version 8 -- Debian has both in the Buster repos. 

EDIT 2019-08-24:
The saga continues. I compiled the 5.2.9 kernel in Easy Pyro 1.1.1, and CD ejection and playing works fine. I then used the same kernel and modules in easy Buster 2.1pre, and there was trouble -- eject button worked OK, though there is some inconsistency, but gnome-mpv gave read errors when tried to play a DVD movie.

So, the cause of the problem is not the kernel. The actual line in the above udev file that causes the problems:

KERNEL=="sr[0-9]*", ENV{ID_CDROM}="1"

So, I am thinking that this line triggers something else, perhaps another udev rule, that is interfering with usage of the optical drive.  A udev rule that is in Buster, not in Pyro.  

EDIT 2019-08-24:
Bingo! Yes, after going on a meandering path trying to think what the cause of the optical misbehaviour was, I came to think that it was likely to be another udev rule that is conflicting with my intended usage.

So I did a search for the string "cdrom" or "CDROM" in the udev rules, and came up with a few hits. Then realised the likely culprit is /lib/udev/rules.d/80-pktsetup.rules:

# Create and remove packet writing device for each optical block device
ACTION=="add", SUBSYSTEM=="block", ENV{ID_CDROM}=="1", RUN+="/usr/sbin/pktsetup %E{MAJOR}:%E{MINOR}"
ACTION=="remove", SUBSYSTEM=="block", ENV{ID_CDROM}=="1", RUN+="/usr/sbin/pktsetup -d %E{MAJOR}:%E{MINOR}"

Disabled that file, and optical media ejection and DVD movie playing work. Previously, I was getting inconsistent results, sometimes able to eject a CD sometimes not, sometimes able to play a movie sometimes not. There was a fight going on. The above rules caused a process to launch, that did not terminate, 'pktcdvd0', which was doing the fighting.

This rules file is in the 'udftools' DEB, which is described as "tools for UDF filesystems and DVD/CD-RW drives". I only included it in the build as it looked interesting. Well it is now out. 

EDIT 2019-09-03:
Thomas Schmitt, the author of Xorriso, contacted me about this problem, and he requested certain tests. This pretty much nailed it down:

# cdrskin dev=/dev/sr0 -toc
cdrskin: SORRY : Cannot open busy device '/dev/sr0'
cdrskin: ( Most recent system error: 16  'Device or resource busy' )
# cdrskin --drive_not_o_excl dev=/dev/sr0 -toc
cdrskin: status 4 burn_disc_full "There is a disc with data on it in the

Quoting Thomas:

The second attempt to access the drive succeeded.
So it is indeed the Linux specific locking protocol for device files
by flag O_EXCL, which causes the EBUSY error on open(2).

Thomas has analysed the kernel source, and thinks that this exclusive locking behaviour is in recent kernels. He has informed one of the kernel developers, Pali Rohar. 

Tags: easy