You are not logged in.
devmon is a configuration-less bash wrapper script for udisks which automounts optical discs and removable drives. It can also selectively autostart apps or execute commands after mounting, ignore specified devices and volume labels, and unmount removable drives.
udisks has the advantage that it works directly through udev and policykit, requires no configuration or udev/rules.d changes, and does not require HAL. You simply install udisks with pacman , then run devmon to enable automounting. udisks allows you to mount and unmount drives as a normal user.
The aim for this version of devmon was to make it a simple yet flexible automounting solution. Here are some possible ways you can use it:
Automounter
With a single command added to your startup script, you have automounting - when CD/DVDs or removable drives are inserted they are immediately mounted to /media. It can also unmount all removable drives with one command so they are safe to remove.
Autostarter
By adding a few options on the command line, devmon becomes an autostarter which can start apps based on the media type, or run other commands you specify. For example, when you insert a DVD video, it can play automatically.
Custom Uses
Using only command-line options, devmon gives you almost complete control over what happens when devices are added. You can run custom scripts or commands, or inhibit automounting to handle that yourself as well. devmon takes care of the device events, allowing you to design a custom automounting solution.
devmon --help
Automounts and unmounts optical and removable drives using udisks
Requires: udisks
Recommended: zenity
Usage: devmon [AUTOMOUNT-OPTIONS]
devmon [UNMOUNT-OPTIONS]
AUTOMOUNT-OPTIONS:
--exec-on-device DEVICE "COMMAND" Execute COMMAND after mounting DEVICE
--exec-on-label "LABEL" "COMMAND" Execute COMMAND after mounting LABEL
--exec-on-video "COMMAND" Execute COMMAND after video DVD mount
--exec-on-audio "COMMAND" Execute COMMAND after audio CD insertion
--exec-on-disc "COMMAND" Execute COMMAND after data CD/DVD mount
--exec-on-drive "COMMAND" Execute COMMAND after drive mount
--ignore-device DEVICE Ignore DEVICE (eg /dev/sdd1)
--ignore-label "LABEL" Ignore volume with LABEL
--no-mount Don't mount anything, just exec (disables
--exec-on-video)
Where the following in COMMAND will be replaced with:
%d mount point directory
%f device name (eg /dev/sdd1)
%l label of mounted volume
Multiple --exec-on-XXX options may be used to execute multiple commands.
Other exec-on-XXX commands are ignored if exec-on-device or -label executed.
UNMOUNT-OPTIONS:
--unmount-all sync and unmount all removable drives and show
pop-up dialog (zenity installation required)
--nogui do not show zenity pop-up dialogs
--ignore-device DEVICE Do not unmount DEVICE (eg /dev/sdd1)
--ignore-label "LABEL" Do not unmount volume with LABEL
EXAMPLES:
Start devmon and leave it running to automount devices:
devmon &
Unmount all removable drives and sync:
devmon --unmount-all
For example, to have devmon open removable drives and data CD/DVD’s with the PCManFM-Mod file manager, and open video DVDs and audio CDs with vlc:
devmon --exec-on-drive "pcmanfm-mod -t %d" \
--exec-on-disc "pcmanfm-mod -t %d" \
--exec-on-video "vlc dvd://%f" \
--exec-on-audio "vlc cdda://%f"
The exec-on-XXX command(s) specified will be executed after a drive is auto-mounted. %d, if present in the command, will be replaced with the mount point (eg /media/cd), %f will be replaced with the device (eg /dev/sdd1), and %l with the volume label. Multiple exec-on-XXX options may be specified to issue multiple commands.
For additional examples and discussion, please see the website. If you encounter any problems, please let me know so I can try to address them - thanks. I have tested it quite a bit and am using it now myself, but please keep an eye on this post or the blog for updates. And my thanks to Bernard Baeyens for some nice bash 4 code borrowed from his udisksvm script - it made monitoring much simpler.
Additional info, instructions, and download links:
http://igurublog.wordpress.com/downloads/script-devmon/
http://aur.archlinux.org/packages.php?ID=45842
Note: sourceforge isn't letting me update files at the moment, so the website and PKGBUILD downloads it from my backup site for now. I will update the PKGBUILD once sourceforge cooperates.
Last edited by IgnorantGuru (2011-01-27 23:07:20)
Offline
devmon 0.8.1 is available. This update adds one feature and includes some very minor housekeeping:
* added --unmount-on-exit option which causes devmon to automatically unmount all removable drives on exit. This helps prevent vacant directories being left behind in /media when you reboot, for example.
* if you try to run devmon as root, it will exit with an error
* adjusted start udisks daemon trigger and timing to make it more universally functional (on systems without a CD drive, for example)
* added trap to ignore SIGHUP signal (if you close the terminal you started devmon in, it should now keep running in the background)
* the use and installation instructions have been updated
Also, SourceForge is preventing developers from uploading new releases for several days now due to the attack. So devmon is still hosted on my backup site for now. UPDATE: devmon is on sourceforge now
http://igurublog.wordpress.com/downloads/script-devmon/
http://aur.archlinux.org/packages.php?ID=45842
Last edited by IgnorantGuru (2011-02-02 02:25:57)
Offline
Hi, I installed devmon (aur), it works well executed in a terminal window, but nothing happens when executed via xinitrc (devmon &).
1-Running - ok (htop shows it).
2-ConsoleKit - ok (exec ck-launch-session subtle). //Tried 10-udisks.pkla too, automount still not working.
What I should try?
Offline
Hi, I installed devmon (aur), it works well executed in a terminal window, but nothing happens when executed via xinitrc (devmon &).
1-Running - ok (htop shows it).
2-ConsoleKit - ok (exec ck-launch-session subtle). //Tried 10-udisks.pkla too, automount still not working.What I should try?
You could try
devmon 2>&1 > /tmp/devmon.log &
to capture any errors or info messages. You might also try
( sleep 10 && devmon ) &
so that start of devmon is delayed until after the consolekit session is started.
Also, does htop show "udisks --monitor" running, as well as the udisks daemon? Should look like:
$ ps -Af | grep -e udisks -e devmon
user 6096 1 0 Feb02 ? 00:00:00 /bin/bash devmon
root 6100 1 0 Feb02 ? 00:00:00 /usr/lib/udisks/udisks-daemon
root 6101 6100 0 Feb02 ? 00:00:05 udisks-daemon: polling /dev/sr0
user 6275 6096 0 Feb02 ? 00:00:00 udisks --monitor
devmon should trigger the start of the daemon - if it is not running then it is probably a udisks permission problem.
Thanks for your feedback and please let me know your results.
Last edited by IgnorantGuru (2011-02-05 00:20:00)
Offline
Ok, tried. I got no error message (2 info line found, "===" and "Monitoring... Ctrl+C to cancel."), ps -Af | grep -e udisks -e devmon shows me the exact same thing as yours (everything tested with and without 'sleep', same result).
Offline
Ok, tried. I got no error message (2 info line found, "===" and "Monitoring... Ctrl+C to cancel."), ps -Af | grep -e udisks -e devmon shows me the exact same thing as yours (everything tested with and without 'sleep', same result).
Thanks. Only other things I can think of at present...
devmon doesn't have a verbose mode, but If you don't mind editing the script, changes these lines:
# Trigger udisks daemon start (either of these should work)
udisks --poll-for-media /dev/sr0 2>&1 > /dev/null
udisks --show-info /dev/sda > /dev/null
to
# Trigger udisks daemon start (either of these should work)
udisks --poll-for-media /dev/sr0
udisks --show-info /dev/sda
then repeat the logfile test:
devmon 2>&1 > /tmp/devmon.log &
That might free up a little more information on errors. That logfile should be updated with device/CD insertions as they occur, just like devmon in a terminal reports. If it doesn't, then for some reason udisks --monitor isn't working properly, but I can't think of why that would be given what you've reported doing.
Only other thought: When you say nothing happens, if you're expecting an app to start, be sure to look in /media as well to see if the media is being silently mounted, even if --exec-on-XXX isn't working. If that's the case, some programs aren't happy run from the devmon daemon started in xinitrc without some environment variables added, although the log file should capture their error, if any. If that's the case, I can give you a little more advice on that.
With Openbox, I haven't had any problems running devmon from autostart.sh, but I haven't tried it directly from xinitrc. When I have a chance I will give that a try to see if I can duplicate your problem.
Offline
Hum, this helped a bit, now I'll search how to fix (I just do not know how, but I'll try ).
started from xinitrc: http://pastebin.com/Ak3TtEk5
running in a terminal (killall devmon; devmon 2>&1 > /tmp/devmon.log2 &): http://pastebin.com/t5KguDmT
Offline
Hum, this helped a bit, now I'll search how to fix (I just do not know how, but I'll try ).
started from xinitrc: http://pastebin.com/Ak3TtEk5
running in a terminal (killall devmon; devmon 2>&1 > /tmp/devmon.log2 &): http://pastebin.com/t5KguDmT
In the former, line 1:
Poll for media failed: Not Authorized
should not be saying that. It appears device insertion is being detected and devmon is issuing the mount commands. The commands aren't returning an error code, but if they're returning error text devmon will hide it. Those mount commands are probably saying 'not authorized' as well. To confirm that, you could change these lines in the mountdrive() function:
point=`udisks --mount $1 --mount-options noexec,nosuid,noatime 2>&1 \
| grep "^Mounted " | sed 's/^Mounted .* at \(.*\)/\1/'`
to
point=`udisks --mount $1 --mount-options noexec,nosuid,noatime \
| grep "^Mounted " | sed 's/^Mounted .* at \(.*\)/\1/'`
which should allow you to see or log the error from the udisks --mount command. (I'm going to either add a verbose mode or make that change in the script on the next update, as devmon is already quite verbose).
As for the Not authorized error, I'm not sure what would cause that (it is the "udisks --poll-for-media /dev/sr0" command that is triggering that error). I'm still going to try to duplicate the problem. Thanks for your patience.
Offline
Another possible fix as suggested by berbae for his udisks script:
In .xinitrc before you start devmon:
if which dbus-launch >/dev/null 2>&1 && test -z "$DBUS_SESSION_BUS_ADDRESS"; then
eval $(dbus-launch --sh-syntax --exit-with-session)
fi
In case the not authorized error is caused by the lack of a dbus session address environment variable, that should correct it.
Offline
Hum, this helped a bit, now I'll search how to fix (I just do not know how, but I'll try ).
started from xinitrc: http://pastebin.com/Ak3TtEk5
running in a terminal (killall devmon; devmon 2>&1 > /tmp/devmon.log2 &): http://pastebin.com/t5KguDmT
I have tried to reproduce this problem but was unable to do so. Even starting devmon from xinitrc with no sleep delay and starting openbox without consolekit, with no dbus environment variable, devmon and udisks still worked (although other things relying on consolekit did not). So I don't know what is producing that 'Not Authorized" message in your case.
Also, reviewing the logs you posted, it certainly appears that devmon is successfully mounting the media. If udisks doesn't return a mount point, then devmon will produce an error, which I did not see in your logs. Only thing I can think of is that udisks is for some reason mounting to a folder other than /media. You might issue a 'mount' command to see if the devices are in fact mounted elsewhere.
Last edited by IgnorantGuru (2011-02-05 14:26:26)
Offline
It still only working if executed in a terminal window.
mount(xinitrc - usb flash drive plugged after login)
[irtigor@seedadler ~]$ mount
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sys on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=10240k,nr_inodes=480714,mode=755)
/dev/sda2 on / type ext4 (rw,relatime,barrier=1,data=ordered)
devpts on /dev/pts type devpts (rw)
shm on /dev/shm type tmpfs (rw,nosuid,nodev)
/dev/sda1 on /boot type ext2 (rw)
/dev/sda4 on /home type ext4 (rw,user_xattr)
mount(killall devmon; devmon & - usb flash drive unplugged/plugged)
[irtigor@seedadler ~]$ mount
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sys on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=10240k,nr_inodes=480714,mode=755)
/dev/sda2 on / type ext4 (rw,relatime,barrier=1,data=ordered)
devpts on /dev/pts type devpts (rw)
shm on /dev/shm type tmpfs (rw,nosuid,nodev)
/dev/sda1 on /boot type ext2 (rw)
/dev/sda4 on /home type ext4 (rw,user_xattr)
/dev/sdb1 on /media/3AB6-36FB type vfat (rw,noexec,nosuid,nodev,noatime,uhelper=udisks,uid=1000,gid=100,shortname=mixed,dmask=0077,utf8=1,showexec)
/dev/sdb2 on /media/DATA type vfat (rw,noexec,nosuid,nodev,noatime,uhelper=udisks,uid=1000,gid=100,shortname=mixed,dmask=0077,utf8=1,showexec)
No extra log generated (without 2>&1).
Offline
It still only working if executed in a terminal window.
If you haven't already done so, I would try the dbus tip, but I doubt that is the issue. I don't believe the problem is in devmon but in udisks - something about the 'Not Authorized' message you're getting.
To get more directly to the problem, you can try this in xinitrc:
udisks --mount /dev/sdb1 &> /tmp/udisks.log &
(with the sdb1 device already inserted)
If you can get that udisks command to work, then devmon should work. You could also just try it in Ctrl-Alt-F1 terminal with no user logged into X - should be equivalent to doing it from xinitrc.
Now that you've narrowed it down to a udisks or consolekit/policykit problem, you might ask elsewhere on this forum or on the udisks mailing list for help with the permissions. I'm fairly new to udisks myself and haven't had to troubleshoot it much, so I'm running out of ideas on this one, but I'll still see what else I can find.
Offline
I did read:
From what I remember ages ago when I had problems with Xsession, if
you have a ~/.xinitrc, startx won't read /etc/X11/xinit/xinitrc ,
which means /etc/X11/Xsession isn't imported into xinit, which leads
to no consolekit session being created/maintained among some daemons,
dbus listeners .. bla bla ..Adding a '. /etc/X11/Xsession' in the beginning of my ~/.xinitrc
solved that, now ck-list-sessions list two sessions, one inactive (the
window which I've typed startx) and one active (my X .. ).
Worth examing ck-list-sessions output, but ironicaly on my machine it says active=FALSE and udisks still works (I have no pkla involved), which I can't explain.
Offline
Yeah, I agree with you, udisks command worked in a terminal (with no user logged into X), but not in .xinitrc ("Mount failed: Not Authorized").
One last thing, digging my log files I found "/usr/bin/devmon: line 280: /dev/stderr: Permission denied" in /var/log/slim.log, is it relevant?
Offline
Yeah, I agree with you, udisks command worked in a terminal (with no user logged into X), but not in .xinitrc ("Mount failed: Not Authorized").
One last thing, digging my log files I found "/usr/bin/devmon: line 280: /dev/stderr: Permission denied" in /var/log/slim.log, is it relevant?
That explains why you're not seeing the mount error in the devmon log - for some reason devmon can't write to stderr on your system, which is unusual. I'll have a look at that. But it doesn't explain why the mount is failing in the first place.
You could try starting devmon elsewhere, either before your subtle session, or from within it. I don't understand why udisks isn't authorizing mounts from within ~/.xinitrc.
I might try adding this to /etc/rc.local:
su -c "devmon" yourusername &
replacing 'yourusername' with your normal user, but I don't know if udisks will work from there in general. Since it's working in your subtle session, maybe you can start it within there. (I'm not familiar with subtle) You can start it manually simply by opening a terminal window and running "devmon &" or "nohup devmon > /dev/null &", then closing the terminal. It should keep running.
Offline
One last thing, digging my log files I found "/usr/bin/devmon: line 280: /dev/stderr: Permission denied" in /var/log/slim.log, is it relevant?
Yes that was a bug. I have corrected that in 0.8.2 which is now available. This update corrects that bug and lets you see errors more verbosely in general, making your edits to the script above unnecessary. Unrelated, it also changes the 'do not run as root' error to a warning, as some distros run more as root. However, this update won't have any effect on your udisks permission problem.
http://igurublog.wordpress.com/downloads/script-devmon/
http://aur.archlinux.org/packages.php?ID=45842
Offline
Nice script. It has replaced my udev rules. I was also having the above issues, and none of the fixes worked for me. I start my WM from xinitrc through a script, and starting devmon in that script works just fine. Very weird!
Offline
Curiouser and curiouser.
Offline
I use this instead of udev rules as well. Very nice. thanks IgnorantGuru.
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
Starting devmon within subtle solved my problem. Thanks for your helping IgnorantGuru.
Offline
Using it instead of udiskie (which did not work 100% for me). Great work IgnorantGuru, thanks.
Offline
Thanks for the positive feedbacks. I looked into this whole consolekit business in some detail, and if I don't fully understand it, I think I now know what does and doesn't work. If you just want the short version, you can check out the updated installation instructions for devmon. Thanks to irtigor for feedback and testing contributing to these more functional instructions.
alterecco's comment above led me to suspect that the reason udisks was working regardless of where I started devmon was because I start my X session from a rather convoluted script. I was able to reproduce the 'Not Authorized' error once I tried starting X with 'startx' directly.
ck-launch-session sets env variables and other voodoo which enables udisks to have the required policykit permissions to mount devices. If devmon is started outside of a consolekit session, it doesn't appear to work, even if the pklocalauthority file is created to allow users to mount unconditionally. Except when it does. It seems to be able to run from a tty terminal. But if you try to run it from within Openbox, for example, without ck-launch-session, it won't work, presumably because xinit does not inherit its parent's authority (at least as far as consolekit/policykit is concerned). You can read a little more in this mailing list discussion which directly addresses this problem.
So I now solely recommend launching your window manager with consolekit (if that isn't already built into it?), then launching devmon from one of your WM's initialization scripts (such as Openbox's autostart.sh).
I completely removed the pklocalauthority instructions from devmon's installation instructions because it seems to have no effect on the problem of starting devmon from xinitrc.
The only way I was able to start devmon in xinitrc and have it work was like this:
exec ck-launch-session bash -c "devmon & openbox-session"
You could also write a script to launch devmon and your window manager, and as long as you launch your script with ck-launch-session, it should work. Simply launching devmon from a script launched in xinitrc outside of the consolekit session did not work (as expected).
They certainly didn't make udisks simple with all this linkage to consolekit and policykit. I have a good mind to write a root daemon that just mounts things for users, as doing this in Linux is ridiculously convoluted. But consolekit is increasingly required by many apps, so devmon requiring it shouldn't be too much of a hassle - it's just important where you start it. And udisks does work reliably once this is handled correctly.
So devmon's installation instructions have been rewritten to reflect all of this. Please let me know if they need any refinement for any particular setup.
Other than the permissions problems (which I didn't encounter until I forced the issue), devmon has been working very well for me also. This is the first time I've had an automounting solution, on any distro, that behaves reliably and how I want, so in that sense udisks has been helpful.
Offline
I've just moved from udiskie - this is awesome! IgnorantGuru, thanks for this - great work!
Is there any chance you could in future implement on-mounting dialog showing info like size, filesystem etc.?
Last edited by pit (2011-02-08 23:28:45)
Offline
I've just moved from udiskie - this is awesome! IgnorantGuru, thanks for this - great work!
Is there any chance you could in future implement on-mounting dialog showing info like size, filesystem etc.?
Glad you like it. Try adding this --exec-on-drive option to your devmon command (make sure you copy all of it):
devmon --exec-on-drive "zenity --info --text=\"The following device has been mounted:\\n\\n\$(df -hT %f | grep %f | awk '{print \"Device:\\\\t\"\$1\"\\x0AType:\\\\t\"\$2\"\\x0ASize:\\\\t\\\\t\"\$3\"\\x0AUsed:\\\\t\"\$4\"\\x0A\"\"Avail:\\\\t\"\$5\"\\x0AUse%:\\\\t\"\$6\"\\x0AMount:\\\\t\"\$7}')\\nLabel:\\t%l\" --title=\"devmon mount\""
That should do what you're talking about. I'll consider adding that as an option though. I assume you mean only for removable drives, not CDs. Personally this feature would drive me crazy, but that's what's nice about being able to build a custom automount solution. Thanks for your feedback.
Offline