[udev] Disks are not unmounted when physical eject button is used

Bug #1168742 reported by Christopher Rogers
66
This bug affects 11 people
Affects Status Importance Assigned to Milestone
systemd
Confirmed
Medium
systemd (Ubuntu)
Fix Released
Medium
Martin Pitt

Bug Description

In 13.04, disks (DVDs, CDS) are not unmounted when ejected via the hardware button on the drive. After ejecting disks via the hardware button, an entry for the disk still shows up in the file manager, and shows when I run df. If I do a soft eject (ie from the right click menu from the icon on the launcher), however, everything works properly.

Just as a note, as per https://wiki.ubuntu.com/Bugs/FindRightPackage#Hardware_Malfunctions, I attempted to report this using ubuntu-bug storage, however there is not an option dealing with unmounting devices, and clicking other tells you that you should run ubuntu-bug again with a specific package name. In an attempt to get this to a semi-relevant audience, I ended up just saying that a disk wasn't auto-mounted, clicking through the next few popups, and ended up here. If this isn't the right place to report this bug, I apologize.

ProblemType: Bug
DistroRelease: Ubuntu 13.04
Package: linux-image-3.8.0-17-generic 3.8.0-17.27
ProcVersionSignature: Ubuntu 3.8.0-17.27-generic 3.8.6
Uname: Linux 3.8.0-17-generic x86_64
NonfreeKernelModules: nvidia
ApportVersion: 2.9.2-0ubuntu8
Architecture: amd64
AudioDevicesInUse:
 USER PID ACCESS COMMAND
 /dev/snd/controlC1: chris 1590 F.... pulseaudio
 /dev/snd/controlC0: chris 1590 F.... pulseaudio
Date: Sat Apr 13 12:54:33 2013
GvfsMonitorLog: Monitoring events. Press Ctrl+C to quit.
HibernationDevice: RESUME=UUID=bd2c881c-7bf8-4996-8b05-7efbd9852333
HotplugNewDevices:

HotplugNewMounts:

InstallationDate: Installed on 2013-03-26 (18 days ago)
InstallationMedia: Ubuntu 13.04 "Raring Ringtail" - Alpha amd64 (20130325)
MachineType: ASUSTeK COMPUTER INC. G55VW
MarkForUpload: True
ProcEnviron:
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=en_US.UTF-8
 SHELL=/bin/bash
ProcFB:

ProcKernelCmdLine: BOOT_IMAGE=/boot/vmlinuz-3.8.0-17-generic root=UUID=f44b6481-8a06-4cf1-a494-0e4c233720c8 ro quiet splash
RelatedPackageVersions:
 linux-restricted-modules-3.8.0-17-generic N/A
 linux-backports-modules-3.8.0-17-generic N/A
 linux-firmware 1.105
SourcePackage: linux
Symptom: storage
UdevMonitorLog:
 monitor will print the received events for:
 UDEV - the event which udev sends out after rule processing
UdisksMonitorLog:
 Monitoring the udisks daemon. Press Ctrl+C to exit.
 12:54:42.343: The udisks-daemon is running (name-owner :1.39).
UpgradeStatus: No upgrade log present (probably fresh install)
dmi.bios.date: 04/05/2012
dmi.bios.vendor: American Megatrends Inc.
dmi.bios.version: G55VW.206
dmi.board.asset.tag: ATN12345678901234567
dmi.board.name: G55VW
dmi.board.vendor: ASUSTeK COMPUTER INC.
dmi.board.version: 1.0
dmi.chassis.asset.tag: No Asset Tag
dmi.chassis.type: 10
dmi.chassis.vendor: ASUSTeK COMPUTER INC.
dmi.chassis.version: 1.0
dmi.modalias: dmi:bvnAmericanMegatrendsInc.:bvrG55VW.206:bd04/05/2012:svnASUSTeKCOMPUTERINC.:pnG55VW:pvr1.0:rvnASUSTeKCOMPUTERINC.:rnG55VW:rvr1.0:cvnASUSTeKCOMPUTERINC.:ct10:cvr1.0:
dmi.product.name: G55VW
dmi.product.version: 1.0
dmi.sys.vendor: ASUSTeK COMPUTER INC.

Revision history for this message
Christopher Rogers (christopherrogers1991) wrote :
description: updated
Revision history for this message
Brad Figg (brad-figg) wrote : Status changed to Confirmed

This change was made by a bot.

Changed in linux (Ubuntu):
status: New → Confirmed
Revision history for this message
Joseph Salisbury (jsalisbury) wrote : Re: Disks are not unmounted when physical eject button is used

Would it be possible for you to test the latest upstream kernel? Refer to https://wiki.ubuntu.com/KernelMainlineBuilds . Please test the latest v3.9 kernel[0]. You will need to install both the linux-image and linux-image-extra .deb packages.

If this bug is fixed in the mainline kernel, please add the following tag 'kernel-fixed-upstream'.

If the mainline kernel does not fix this bug, please add the tag: 'kernel-bug-exists-upstream'.

If you are unable to test the mainline kernel, for example it will not boot, please add the tag: 'kernel-unable-to-test-upstream'.
Once testing of the upstream kernel is complete, please mark this bug as "Confirmed".

Thanks in advance.

[0] http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.9-rc7-raring/

Changed in linux (Ubuntu):
importance: Undecided → Medium
status: Confirmed → Incomplete
Revision history for this message
Christopher Rogers (christopherrogers1991) wrote :

Tested it with the daily build of the 3.9 kernel, and the bug still exists. I've added the kernel-bug-exists-upstream tag and changed the status.

tags: added: kernel-bug-exists-upstream
Changed in linux (Ubuntu):
status: Incomplete → Confirmed
Phillip Susi (psusi)
affects: linux (Ubuntu) → udisks2 (Ubuntu)
Changed in udisks2 (Ubuntu):
status: Confirmed → New
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in udisks2 (Ubuntu):
status: New → Confirmed
Revision history for this message
Rüdiger Kupper (ruediger.kupper) wrote :

I confirm this problem

Revision history for this message
andrew (ham-m) wrote :

Confirmed on Ubuntu Gnome 13.04 64-bit (3.8.0-32-generic)

It causes all kinds of DVD playback problems see

https://bugs.launchpad.net/ubuntu/+source/linux/+bug/404472?comments=all

Revision history for this message
SergeiS (sergei-redleafsoft) wrote :

Confirmed on Ubuntu 13.04 64bit (3.8.0-33-generic).

What a PITA bug, I was backing up my family video dvds using dd command and noticed that the size of the images is always the same. I eventually tried playing and iso file and of course some of the chapters weren't playing.

No workaround yet other than using "eject" button in Nautilus?

Revision history for this message
In , Yyz82 (yyz82) wrote :

I have a problem with some media types: DVD+R DL, DVD-R, DVD+RW and CD-R. Only audio CD works fine. I will explain...

audio cd (I think this is the correct behavior):
Insert the media in optical drive
the media is mounted and read without any problem
Press the optical device button to eject the audio cd
Nautilus automatically goes to home folder and the optical device icon disappears from nautilus left side and gnome-shell tray
insert other media type
the media is mounted and read without any problem again

DVD+R DL, DVD-R, DVD+RW and CD-R (annoying behavior)
insert the media
the media is mounted and read without any problem
press optical device button to eject the media
nautilus keeps showing the media content (???) and device icon on nautilus left side changes to "CD/DVD Drive"
insert other media immediately (except audio cd)
the system recognize the media because device icon name on nautilus changes to the media label (on gnome-shell tray is still "CD/DVD Drive"), but nautilus shows no file (???)
if I eject and reinsert the media using the optical device button I have the same result
I need eject the media using nautilus or gnome-shell icon to access the new media files

After eject problematic media I run below command

mount|grep sr0

My system says that the media is still mounted.
I insert other media and run the command again and it says that the previous media is mounted.
My system is not umount/mount media correctly.

My optical device: BenQ DW1640 (IDE) with latest firmware (BSRB)
Thanks.

Revision history for this message
In , Tbzatek (tbzatek) wrote :

Created attachment 92238
[PATCH] Check if cdrom drive has media on cleanup

When cleanup is run, it is supposed to remove lingering mounts.
That probably works fine for card readers etc. since there's
a partition exposed for the drive but fails for optical media.
As a result, when mounted and user presses the drive eject
button, tray is ejected but mounts lives on.

This patch adds a special check for CDROM drives and looks for
active media.

--

The test is highly cdrom-specific and should not break anything else. On the other hand, not sure if there are e.g. card readers not exposing the "partition" device type, only presenting itself as a "disk". Haven't tested that, my concern was a flash medium having no partition table, used directly. Or, a ZIP drive (ATAPI vs. floppy mode) and such...

Revision history for this message
In , Zeuthen (zeuthen) wrote :

Hmm, I'm not sure this is the right fix so please don't commit it. I'll try to reproduce this...

Revision history for this message
In , Tbzatek (tbzatek) wrote :

(In reply to comment #2)
> Hmm, I'm not sure this is the right fix so please don't commit it. I'll try
> to reproduce this...

Reproducing this is easy:
1. Insert CD/DVD media
2. Let Gnome/gvfs automount it (clean system, defaults)
3. Press the eject button on the drive
4. Watch the mount staying alive

Note that udisks cleanup routine properly registers the event, it's all about matching the cleanup conditions.

Revision history for this message
In , Lodgerz (lodgerz) wrote :

I have the same problem. Can you solve please? Thanks.

Revision history for this message
Phil Wright (jozubiso) wrote :

This bug is still present in Ubuntu 14.04 3.13.0-32-generic (both 32bit and 64bit).

This makes Ubuntu and derivatives problematic for newbie users who expect cd/dvd ejection to just work as it does in Windows. Having to manually unmount the drive before inserting another disc is a poor solution.

Revision history for this message
Phil Wright (jozubiso) wrote :

After trawling the internet for possible solutions, I have put together a kludgey script workaround to automatically unmount a dvd when it's ejected via the dvd drive eject button.

This kludge assumes the dvd drive is /dev/sr0 and the shell script uses /bin/sh; customise according to your system configuration. It uses the utility 'dvd+rw-mediainfo'.

1. Create a udev rules file '/etc/udev/rules.d/61-sr0-change.rules' and add the line:

KERNEL=="sr0", ACTION=="change", RUN+="/usr/local/bin/sr0_change.sh"

and save the file.

2. Create a shell script '/usr/local/bin/sr0_change.sh'. Add the following lines:

#!/bin/sh
dvd+rw-mediainfo /dev/sr0 > /dev/null
n=$?
if [ "$n" -ne '0' ];then eject /dev/sr0;fi

3. Save the shell script file and change the file permissions to make it executable.

That's it. It's ugly, but it works on my system. I hope it helps.

Revision history for this message
Phil Wright (jozubiso) wrote :

Further to my #10 comment, I forgot to point out that the utility 'dvd+rw-mediainfo' is in the package 'dvd+rw-tools' in the Ubuntu repositories.

Revision history for this message
Phil Wright (jozubiso) wrote :

Further again to my #10 comment:

My apologies, the shell script '/usr/local/bin/sr0_change.sh' above posted only works for dvd media.

The following should (?) work for other media (eg. audio CDs) as well:

#!/bin/sh
dvd+rw-mediainfo /dev/sr0 > /dev/null
n=$?
if [ "$n" -eq '251' ];then eject /dev/sr0;fi

Revision history for this message
In , Lynx-light0 (lynx-light0) wrote :

Yes. This needs to be fixed.

See:

https://bugs.archlinux.org/task/42071

Revision history for this message
In , Tbzatek (tbzatek) wrote :

*** Bug 84374 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Lynx-light0 (lynx-light0) wrote :

(In reply to Tomas Bzatek from comment #3)
> (In reply to comment #2)
> > Hmm, I'm not sure this is the right fix so please don't commit it. I'll try
> > to reproduce this...
>
> Reproducing this is easy:
> 1. Insert CD/DVD media
> 2. Let Gnome/gvfs automount it (clean system, defaults)
> 3. Press the eject button on the drive
> 4. Watch the mount staying alive
>
> Note that udisks cleanup routine properly registers the event, it's all
> about matching the cleanup conditions.

Thomas: can you not commit your patch? This is a much needed fix, and, even if your fix is not perfect, there has been no movement towards improvement in over 6 months.

Revision history for this message
rogue-spectre (rogue-spectre) wrote :

Update to Phil Wright solution, for a more general context

1 - Create a udev rules file '/etc/udev/rules.d/61-sr-change.rules' and add the line :

KERNEL=="sr*", ACTION=="change", RUN+="/usr/local/bin/sr_change.sh %n"

2 - And create the script '/usr/local/bin/sr_change.sh' :

#!/bin/sh

if [ $# -eq 1 ]
then
        source=/dev/sr$1
else
        source=/dev/sr0
fi

dvd+rw-mediainfo $source > /dev/null
n=$?

 if [ "$n" -eq '251' ] then
        umount $source
 fi
exit 0

tags: added: trusty
Revision history for this message
Martin Pitt (pitti) wrote :

There is no robust way how udisks could do this, but on the upstream systemd list we discussed how to do this cleanup under systemd. For udev under upstart there is a hack to call "eject" instead of "cdrom_id --eject" in the udev rule for the eject request, but this relies on udev not running under an unshared mount namespace (i. e. a patch we have in Debian/Ubuntu). I'll look into fixing this the proper way.

affects: udisks2 (Ubuntu) → systemd (Ubuntu)
Changed in systemd (Ubuntu):
status: Confirmed → Triaged
summary: - Disks are not unmounted when physical eject button is used
+ [udev] Disks are not unmounted when physical eject button is used
Revision history for this message
In , Martin Pitt (pitti) wrote :

This was discussed recently on the systemd (udev) mailing list:

http://lists.freedesktop.org/archives/systemd-devel/2015-January/026948.html
http://lists.freedesktop.org/archives/systemd-devel/2015-January/027403.html

After a lot of back and forth, it was decided that the most robust fix under systemd is

http://lists.freedesktop.org/archives/systemd-devel/2015-January/027577.html

For the record, for distros without systemd it is easiest to adjust /lib/udev/rules.d/60-cdrom_id.rules like this:

-ENV{DISK_EJECT_REQUEST}=="?*", RUN+="cdrom_id --eject-media $devnode", GOTO="cdrom_end"
+ENV{DISK_EJECT_REQUEST}=="?*", RUN+="/usr/bin/eject $devnode", GOTO="cdrom_end"

Changed in systemd (Ubuntu):
assignee: nobody → Martin Pitt (pitti)
status: Triaged → In Progress
Changed in systemd:
importance: Unknown → Medium
status: Unknown → Confirmed
Revision history for this message
Martin Pitt (pitti) wrote :
Changed in systemd (Ubuntu):
status: In Progress → Fix Committed
Revision history for this message
In , Martin Pitt (pitti) wrote :
Changed in systemd:
status: Confirmed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :
Download full text (7.6 KiB)

This bug was fixed in the package systemd - 218-10ubuntu1

---------------
systemd (218-10ubuntu1) vivid; urgency=medium

  [ Martin Pitt ]
  * Merge with Debian unstable. Remaining Ubuntu changes:
    - Hack to support system-image read-only /etc, and modify files in
      /etc/writable/ instead.
    - Keep our much simpler udev maintainer scripts (all platforms must
      support udev, no debconf).
    - initramfs init-top: Drop $ROOTDELAY, we do that in a more sensible way
      with wait-for-root. Will get applicable to Debian once Debian gets
      wait-for-root in initramfs-tools.
    - initramfs init-bottom: If LVM is installed, settle udev,
      otherwise we get missing LV symlinks. Workaround for LP #1185394.
    - Add debian/udev.lvm2.init: Dummy SysV init script to satisfy insserv
      dependencies to "lvm2" which is handled with udev rules in Ubuntu.
    - Provide shutdown fallback for upstart. (LP: #1370329)
    - debian/extra/ifup@.service: Additionally run for "auto" class. We don't
      really support "allow-hotplug" in Ubuntu at the moment, so we need to
      deal with "auto" devices appearing after "/etc/init.d/networking start"
      already ran. (LP: #1374521) Also, check if devices are actually defined
      in /etc/network/interfaces as we don't use Debian's net.agent.
    - ifup@.service: Drop dependency on networking.service (i. e.
      /etc/init.d/networking), and merely ensure that /run/network exists.
      This avoids unnecessary dependencies/waiting during boot and dependency
      cycles if hooks wait for other interfaces to come up (like ifenslave
      with bonding interfaces). (LP: #1414544)
    - Add Get-RTC-is-in-local-time-setting-from-etc-default-rc.patch: In
      Ubuntu we currently keep the setting whether the RTC is in local or UTC
      time in /etc/default/rcS "UTC=yes|no", instead of /etc/adjtime.
      (LP: #1377258)
    - Put session scopes into all cgroup controllers. This makes unprivileged
      user LXC containers work under systemd. (LP: #1346734)
    - Lower Breaks: to plymouth version which has the udev inotify fix in
      Ubuntu.
    - Lower libappamor1 dep to the Ubuntu version where it moved to /lib.
    - Make failure of boot-and-services NSpawn.test_boot non-fatal for now.
      This currently fails when being triggered by Jenkins, but is totally
      unreproducible when running this manually on the exact same machine.

    Upgrade fixes, keep until 16.04 LTS release:
    - systemd Conflicts/Replaces/Provides systemd-services.
    - Remove obsolete systemd-logind upstart job.
    - Clean up obsolete /etc/udev/rules.d/README.

  * ifup@.service: Fix syntax error. (LP: #1421556, #1420601)

  [ Didier Roche ]
  * Add systemd-fsckd multiplexer and feed its output to plymouth. This
    provides an aggregate progress report of running file system checks and
    also allows cancelling them with ^C.
    (LP: #1316796; Closes: #775093, #758902)

systemd (218-10) experimental; urgency=medium

  * Pull latest keymaps from upstream git. (LP: #1334968, #1409721)
  * rules: Fix by-path of mmc RPMB partitions and don't blkid them. Avoids
    kernel buffer I/O errors and timeouts. (LP: #1333140...

Read more...

Changed in systemd (Ubuntu):
status: Fix Committed → Fix Released
Revision history for this message
In , Yyz82 (yyz82) wrote :

This problem is back in Fedora 23 64 bits.

Revision history for this message
In , Yyz82 (yyz82) wrote :

This problem is back in Arch linux with systemd 229 too.

Changed in systemd:
status: Fix Released → Confirmed
Revision history for this message
Phil Wright (jozubiso) wrote :

The bug is still present in a new install of Xubuntu 16.04 (and presumably all the other *buntus using systemd 229), and this workaround still works:

sudo apt-get install dvd+rw-tools
echo 'KERNEL=="sr0", ACTION=="change", RUN+="/usr/local/bin/sr0_change.sh"' | sudo tee /etc/udev/rules.d/61-sr0-change.rules
cat << 'EOF' | sudo tee /usr/local/bin/sr0_change.sh
#!/bin/sh
dvd+rw-mediainfo /dev/sr0 > /dev/null
n=$?
if [ "$n" -ne '0' ];then eject /dev/sr0;fi
EOF

sudo chmod +x /usr/local/bin/sr0_change.sh
sudo reboot

Revision history for this message
Peter Bennett (pgbennett) wrote :

The above workaround prevent loading of Video CD's. With that workaround in place, the system immediately ejects any Video CD inserted, and prevents it being mounted.

Revision history for this message
Robert M. Muncrief (rmuncrief-9) wrote :

I can confirm this problem still exists with Xubuntu 16.04 x64. I hope it's fixed someday. It's difficult to win Windows users over when common things like this don't work, it's very confusing for them and they just want me to reinstall Windows :(

Revision history for this message
Phil Wright (jozubiso) wrote :

@ Peter Bennet (comment #30)
Sorry, I don't use Video CD's so I can't check what the problem is - presumably 'dvd-rw-mediainfo' doesn't recognise Video CD's and produces an error of some kind. You could try running 'dvd-rw-mediainfo /dev/sr0; echo "status = $?"' while a Video CD is in the drive to see what exit status dvd-rw-mediainfo returns, and modify the 'sr0_change.sh' script condition to ignore that exit status value, assuming that exit status is unique for Video CDs (if it's a general exit status, then ignore this suggestion):
'if [ "$n" -ne '0' ] && [ "$n" -ne '<VideoCD exit status>' ] ;then eject /dev/sr0;fi

@ Robert M. Muncrief (comment #31)
I agree, this is the sort of functionality that should work out of the box without fail. At the moment it sends the same old Linux subtext of 'geeks only need apply'. I've set up lots of Linux systems for complete newbies, and they've used them quite happily, but if I hadn't been there to work around some of these issues they would never have got started.

Revision history for this message
Peter Bennett (pgbennett) wrote :

I tested this. Video CD gives this
:-( non-DVD media mounted, exiting...
peter@andromeda:~$ echo $?
252

Data CD gives the same result so I suppose it would also have the same problem.

Audio CD gives the same so I suppose it would have the same problem of being ejected upon insertion.

I will rather live with the problem that try changing the script. If you want me to test a change out for the script or other fix I will be glad to help.

Revision history for this message
Phil Wright (jozubiso) wrote :

@Peter Bennett

Ok, I finally managed to test this with CDs and worked out the problem. This was a fault in my shell script.

The test line in the script should be 'if [ "$n" -ne '0' ];then umount /dev/sr0;fi'. Note the command should have been 'umount' not 'eject'.

Complete solution taking the above into account:

sudo apt-get install dvd+rw-tools
echo 'KERNEL=="sr0", ACTION=="change", RUN+="/usr/local/bin/sr0_change.sh"' | sudo tee /etc/udev/rules.d/61-sr0-change.rules
cat << 'EOF' | sudo tee /usr/local/bin/sr0_change.sh
#!/bin/sh
dvd+rw-mediainfo /dev/sr0 > /dev/null
n=$?
if [ "$n" -ne '0' ];then umount /dev/sr0;fi
EOF

sudo chmod +x /usr/local/bin/sr0_change.sh
sudo reboot

Revision history for this message
Peter Bennett (pgbennett) wrote :

I tested the new script.

Note - the reboot seems unnecessary, it works as soon as you have copied the files.

DVDs, Video CDs, Data CDs unmount correctly when ejected.

Audio CDs are another problem. Audio CDs cannot be mounted in the normal way. However the file manager applications (thunar and nautilus) have a button to "mount" the audio CD and then present it as a directory of wav files. It is not really mounted in Linux. If you have done this and eject the CD with the drive button, the CD Icon remains on the desktop and the CD remains open in the file manager. Even if you close the file manager the "Audio CD" icon remains on the desktop.

Bigger problem - according to the bug log above, this bug is fixed and closed. Since that is not the case, how do we get it re-opened so that it can really be fixed in Ubuntu?

Revision history for this message
Pheeble (enpheebled-git) wrote :

@ Peter Bennet (comment #35)

I (having dumped my old 'jozubiso' account because it was linked to the defunct lavabit.com) tested my system (Xubuntu 16.04.1 x64) with an audio cd and it works without a problem. I have to mount an audio cd as you stated by clicking an arrow button in Thunar, but ejecting the cd via the optical drive's eject button results in the mount closing and disappearing from both Thunar and the desktop. Mine is far from a new install, so perhaps I have installed something (such as gvfs, in addition to the default gvfs-backends) that helps.

As to reopening this bug, the status editing icon in the drop-down display of 'systemd (Ubuntu)' at the top of the screen indicates it can only be changed by a project maintainer or bug supervisor. Presumably we have to find a way to get someone with that authority to reopen the bug. Alternatively, perhaps we need to open a new bug and link it to this one.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.