Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: [Solved] Unmount optical media with eject button (Read 944 times) previous topic - next topic
0 Members and 3 Guests are viewing this topic.

[Solved] Unmount optical media with eject button

Is there a way to configure the system to fully unmount an optical disc when the hardware eject button is pressed on the Optical drive? I have been looking for a solution and so far have only found reference to an old systemd bug in Arch.

This is the last piece of the puzzle to my entertainment system running Artix, for some reason Kodi only palys BluRay discs if the disc is mounted first (automounts in XFCE), but when you press the eject button on the drive itself, it doesn't completely unmount and the next disc doesn't mount properly and causes playback issues/won't play the next disc if its a DVD.

Running OpenRC with the XFCE DE. I have udisk2, gvfs-nosystemd (1.32.1-1, older package I know, but its what has been installed and running and never asked to replace during updates) installed if that makes any difference.

Thanks in advance.

Re: Unmount optical media with eject button

Reply #1
https://aur.archlinux.org/packages/gvfs-nosystemd/
gvfs-nosystemd is an AUR package, it was last updated in 2017, flagged out of date in 2020, and is / was maintained by nous - who might know more about this subject!  ;)
So swapping that for world/gvfs 1.48.1-1 could be worth a try. I have that version installed here, but using Mate, automount disabled, and if I put in a DVD (it's not a BluRay drive) it appears in VLC after a few seconds when I go to discs, hit eject on the drive and put in another, it appears like the other one does and can be played. Probably not a useful comparison given what you are using though!

Re: Unmount optical media with eject button

Reply #2
Any "nosystemd" package is no longer needed because all artix packages are compiled without systemd. I recommend replacing all your nosystemd packages with the ones in artix's repos.

Also, those nosystemd packages may cause bugs and issues in Artix because they are not compiled against eudev and elogind which is present in artix repos.

It's a really bad idea to leave them installed and could cause things to break someday.
Chris Cromer

Re: Unmount optical media with eject button

Reply #3
I thought about/wondered about that as I typed everything up before turning out the lights. If I remember right, the two gvfs-nosystemd packages were what I needed to get mounting to work properly back in 2017 when I setup this system. I installed the gvfs package from world and removed the nosystemd ones, but the behavior is still the same.  When the eject button the Bluray drive is pushed the disc ejects but doesn't completely unmount, so when a new disc is put in, the mount point doesn't get reset and it caused mounting/playback issues with the next disc.

Re: Unmount optical media with eject button

Reply #4
If a disc is ejected with the command, is it gets unmounted?  :
Code: [Select]
sudo eject /dev/sr0
If yes, the command may be assigned to some GUI element and used as a workaround until a better solution is found.

Re: Unmount optical media with eject button

Reply #5
I installed kodi, I'd read about it before and thought it sounded interesting but never used it. I put in a DVD, opened kodi from the cmdline, couldn't see it listed anywhere (unlike with vlc) so I exited kodi using the power button, and mounted /dev/sr0 (remember I don't have automount enabled here.) Then I started kodi again, it played, fine. Ejected the dvd, put in another without umount, no good, stopped kodi and restarted it, some menus in kodi could see the name of the new dvd but it wouldn't play. Also kodi has an onscreen eject button which didn't work. Shutting kodi there were several error messages in the terminal like this:
Code: [Select]
umount: /mymntdir: must be superuser to unmount.
So it looks like kodi has some permissions elevation problem as installed, which would need to be configured.  Probably it's trying to mount and unmount things but can't. vlc seems able to play dvd's without them being mounted, according to the output of mount.


 

Re: Unmount optical media with eject button

Reply #7
Code: [Select]
$ sudo groupadd kodi
$ sudo groupmod -a disk -U kodi
$ sudo groupmod -a optical -U kodi
If I put a dvd in the drive, it's shown in kodi, and it can be ejected when I click the onscreen button in kodi. But it cannot be played until I do ctrl alt f2 and mount /dev/sr0 somewhere. Then it cannot be ejected with the onscreen button, giving the terminal error message about needing root permission to unmount again. If I put another dvd in without unmounting it cannot be played, but if I unmount then remount in the other tty it can.

Re: Unmount optical media with eject button

Reply #8
Code: [Select]
$ sudo groupadd kodi
$ sudo groupmod -a disk -U kodi
$ sudo groupmod -a optical -U kodi
If I put a dvd in the drive, it's shown in kodi, and it can be ejected when I click the onscreen button in kodi. But it cannot be played until I do ctrl alt f2 and mount /dev/sr0 somewhere. Then it cannot be ejected with the onscreen button, giving the terminal error message about needing root permission to unmount again. If I put another dvd in without unmounting it cannot be played, but if I unmount then remount in the other tty it can.
Did you also create the polkit file as was shown in the link I sent?
Chris Cromer

Re: Unmount optical media with eject button

Reply #9
Code: [Select]
# cat /etc/polkit-1/rules.d/50-customactions.rules 
[Actions for kodi user]
Identity=unix-user:kodi
Action=org.freedesktop.upower.*;org.freedesktop.consolekit.system.*;org.freedesk​top.udisks.*;org.freedesktop.udisks.filesystem-mount;org.freedesktop.login1.*
ResultAny=yes
ResultInactive=yes
ResultActive=yes
# cat /etc/polkit-1/localauthority/50-local.d/custom-actions.pkla
[Actions for kodi user]
Identity=unix-user:kodi
Action=org.freedesktop.upower.*;org.freedesktop.consolekit.system.*;org.freedesk​top.udisks.*;org.freedesktop.udisks.filesystem-mount;org.freedesktop.login1.*
ResultAny=yes
ResultInactive=yes
ResultActive=yes
Doesn't seem to make any difference. Probably doing it wrong, the existing rules in /etc/polkit-1/rules.d/99-artix.rules look quite different in format, perhaps things have changed now? If I run kodi as root (obviously not advisable for normal use) then it still doesn't mount /dev/sr0 itself, and can't play the DVD until it has been mounted. But running as root the onscreen eject button works and /dev/sr0 is unmounted if it's already mounted, and ejected. And I can't change ownership of the mounted DVD because it's read only so stays as nobody:nobody.
Even if I got that part to work, it still wouldn't alter the OP's problem of the physical eject button on the drive itself not triggering a umount, that might be something outside of kodi if it doesn't mount things itself.

Re: Unmount optical media with eject button

Reply #10
Code: [Select]
man eject
then /^ +-i and press Enter.

Code: [Select]
       -i, --manualeject on|off
           This option controls locking of the hardware eject button. When enabled, the drive will not be ejected when the button is
           pressed. This is useful when you are carrying a laptop in a bag or case and don’t want it to eject if the button is
           inadvertently pressed.

Re: Unmount optical media with eject button

Reply #11
This works for me here, not to fix the eject button in kodi itself, that's a different problem, but it unmounts the drive before ejecting it when the physical drive button is pressed. This is also better because it avoids the unclean umount warning that was displayed before, not an issue with a read only disk but it would be undesirable on a rw one I expect. So with automount enabled it should work as expected hopefully.
https://superuser.com/questions/920087/how-to-unmount-dvd-external-usb-via-eject-button-on-device
https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1168742
Solution from the bug report:
Install the dvd+rw-tools package then run these 3 commands:
Code: [Select]
$ 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
Possibly reading the bug report this has been fixed by changes in systemd which is why it doesn't work properly elsewhere but I haven't tried that to compare.

Re: Unmount optical media with eject button

Reply #12
You guys are awesome! I didn't have to modify any groups or look into Kodi specific issues or polkit rules as the fix below did the trick! Kodi didn't have an issue playing DVD's without mounting, only Bluray. But the umount issue caused issues for subsequent discs, implementing this and everything is working great! The Kodi eject button isn't much of a concern as everyone who will use the system will just end up using the eject button on the optical drive anyway.

Solution from the bug report:
Install the dvd+rw-tools package then run these 3 commands:
Code: [Select]
$ 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


Thanks again everyone for the time and effort!