PDA

View Full Version : auto mounting in Openbox


aragon
April 7th, 2011, 13:40
Hi

So I finally ditched Xfce 4.6 and decided to give Xfce 4.8 a skip to try something else instead. After playing with LXDE for a bit, I've ended up using standalone Openbox, tint2, and various other bits for my new desktop setup. I poked around for HAL-esque auto mounting setups, but they were all hacky or used amd - not really ideal for hot plug storage devices.

I've made a small auto mounting system that uses devd and integrates with Openbox via its pipemenu system. Mountable filesystems are added to a "Mount" menu entry in my Openbox menu, and clicking an entry toggles between mounted and unmounted with popup message boxes to confirm success/failure.

Filesystems are mounted to subdirectories below /media (or wherever you define), and are named in correspondence to their label if present, or their device name if not. Storage devices are probed to determine if a device is an MBR partition, BSD label, or raw disk device, and educated guesses are made to determine what is mountable. File systems are probed too, but currently only UFS and MSDOSFS are supported. Large MSDOSFS support still needs to be added too. The Openbox specific bit is also written to allow users to mix manual (via terminal) and auto mount/umounting of devices.

When it comes time to call mount/umount, sudo is used, so you will need that installed and correctly configured for this to work. I think one could also use vfs.usermount too, but I haven't tested that yet.

[2011-10-24] Defunct. See volman instead.
[2011-05-23] Latest version: here

aragon
April 7th, 2011, 13:56
My project's name is amount. At its core is a daemon logically named amountd. This daemon is a shell script that sets up an IPC channel with devd, listens for device attachment messages and attempts to discover mountable filesystems on newly attached devices.

When running, amountd creates a directory for itself at /tmp/.amountd, below which it maintains the text file mountable. This is simply a listing of file systems that amountd has discovered. As storage devices come and go, this file is updated with a listing of filesystems that are thought to be mountable, and some details about each file system.

All other components of amount essentially serve as clients to amountd - bridges between amountd, your desktop environment, and mount/umount commands. The most basic of which is a script named amount, a small CLI client to let you use amountd via a terminal, and hopefully to serve as a prototype for future clients to be written by others.

There is one more client currently included: obamount.sh. Written by me too for use with my window manager of choice, Openbox (http://openbox.org/). I plan to include other clients into my distribution too, so feel free to make them public or send them my way.

aragon
April 7th, 2011, 14:32
I'm basically reciting my setup here. Feel free to experiment if you understand things. I'll formalise everything better later.

First you need to get xmountd starting in the background. Place it in ~/bin and make sure it's executable. Then add it to your X startup, in my case ~/.xsession. Here's what mine looks like:

xset m 1 1 r rate 250 30 dpms 0 0 300
xmodmap \
-e "keycode 210 = XF86AudioLowerVolume" \
-e "keycode 209 = XF86AudioRaiseVolume" \
-e "keycode 219 = XF86AudioMute" \
-e "keycode 220 = XF86AudioPause" \
-e "keycode 207 = XF86AudioStop" \
-e "keycode 190 = XF86AudioPrev" \
-e "keycode 130 = XF86AudioNext" \
-e "keycode 191 = XF86Calculator" \
-e "keycode 132 = XF86Music" \
-e "keycode 113 = Multi_key"
export CHARSET=UTF-8
nitrogen --restore &
xcompmgr -c -C -f -t 1 -l 1 -r5 -o.55 -I 0.4 -O 0.4 -D 50 &
~/bin/xmountd &
ssh-agent openbox-session


Place obmount.sh into ~/.config/openbox.

Open ~/.config/openbox/menu.xml and locate your root-menu block. Add a Pipemenu element to it that executes obmount.sh. Here's how mine looks:

<menu id="root-menu" label="Openbox 3">
<menu id="applications" label="Applications" execute="/usr/home/aragon/.config/openbox/dynmenu.pl"/>
<menu id="system-menu"/>
<menu id="mount" label="Mount" execute="/usr/home/aragon/.config/openbox/obmount.sh"/>
<separator/>
<item label="Log Out">
<action name="Exit">
<prompt>
yes
</prompt>
</action>
</item>
</menu>


Log out and back in. Check that xmountd is running:

$ ps ax |grep xmountd
33422 ?? I 0:00.02 /bin/sh /usr/home/aragon/bin/xmountd


Your Openbox menu should have a "Mount" entry on it that is empty.

Now install security/sudo if it isn't already installed:
pkg_add -r sudo

Use visudo to add an entry to sudoers that looks similar to mine:

aragon ALL=(ALL) NOPASSWD: /usr/home/aragon/.config/openbox/obmount.sh


Obviously you need to adjust the above for your username.

Test that sudo works:

$ sudo ~/.config/openbox/obmount.sh
<openbox_pipe_menu>
</openbox_pipe_menu>


If you get a password prompt or error, your sudoers entry is in correct.

Finally, try plug a USB disk in and try mount/umount it via the Openbox menu. With the above setup, errors should be logged to ~/.xsession-errors in case you need to debug.

Comments/contributions appreciated. :D

aragon
April 7th, 2011, 16:16
Ah, geek pride at its best... here's a video of it in action:

http://www.youtube.com/watch?v=VI9koEAes3U

roddierod
April 8th, 2011, 22:24
Just tried it out. It works nicely.

knk
April 15th, 2011, 21:03
Inspired by this, I wrote a PyQt based program that does roughly the same. It adds an icon to the system tray, notifies you when a device becomes available and has a context menu to mount / unmount devices.

It will only let you mount devices it knows about. An config entry look like:



[msdosfs/foo]
mount = sudo mount /media/foo
umount = sudo umount /media/foo
postmount = xdg-open /media/foo

So you specify the device you want to mount with the "/dev/" prefix striped and a command to execute when the device should be mounted or unmouted. The postmount command is executed after the mount command finished running and was successful.

The config files are /usr/local/etc/mountagent.conf and $HOME/.mountagent.conf (both are read, entries in the later may overwrite entries in the former).

Enjoy!

bbzz
April 27th, 2011, 15:50
@aragon

Hi, it doesn't work for me. I checked everything, code, permissions,..it's all there but there's no entry in openbox "mount" menu.

update: It seems that it works only with msdosfs, not with ufs. Tried with different gpart configurations, but it doesn't read it. Also, it can only mount a FS, not unmount it. I changed working dirs to ~/tmp and ~/mnt.

aragon
April 27th, 2011, 21:41
I recommend checking for error output in ~/.xsession-errors. If that doesn't work, try call the obmount.sh script manually to inspect output, eg.:

obmount.sh umount da0s1a aragon

(replace "aragon" with your username)

bbzz
April 28th, 2011, 20:50
I'm not using xsession, but .xinitrc. Script is started nonetheless.

If I run .config/openbox/obmount.sh umount /dev/da0s1 bbzz I get </openbox_pipe_menu only as an output. That's after FS is mounted. Like I said I'm able to mount msdosfs only. But there's no entry in openbox for unmount.

I changed paths to ~/media and ~/tmp where appropriate in scripts.

I though maybe sudo is messing up with something so I tried without it, but it isn't. To make it work without sudo, there needs to be writing permission to /dev/msdosfs/ so there needs to be an entry in /etc/devfs.rules, something like this:
add path "/dev/msdofs/*" mode 660 group operator which is...dirty. So sticking with sudo is better.

Anyway, not sure what else to try.

aragon
April 29th, 2011, 22:58
More information is really needed. Disable xmountd from starting in .xinitrc and run it manually in an xterm so you can see its output. Inspect the /tmp/.xmountd/mountable file for volumes to appear/disappear as you insert/remove devices. Finally run the obmount.sh script without parameters to inspect the menu XML it generates. If you post all that info here I should be able to help better.

bbzz
April 29th, 2011, 23:54
After a restart, msdofs disk can now mount as well as umount. Don't ask. I didn't change anything.
Anyway, still can't mount ufs. Tried different gpart configurations.
First only DD mode, no slices.

# gpart show da0
=> 63 7843752 da0 MBR (3.7G)
63 7843752 1 freebsd (3.7G)

xmountd gives
CREATE da0

~/tmp/.xmountd/mountable is empty, and obmount.sh prints
<openbox_pipe_menu>
</openbox_pipe_menu>

Mouse over openbox menu is empty.
So i tried with slices and labels.
# gpart show da0s1
=> 0 7843752 da0s1 BSD (3.7G)
0 16 - free - (8.0K)
16 7843736 1 freebsd-ufs (3.7G)

This time xmountd gives
CREATE da0
CREATE da0s1
CREATE da0s1
CREATE da0s1a
CREATE da0s1c
CREATE da0s1a
CREATE da0s1a
CREATE da0s1c
CREATE da0s1a
CREATE da0s1ca
CREATE da0s1ca

Does that look like it should?
The rest of output is just like before. There's no item in openbox menu.
Does that help any? So to recap, msdosfs works fine, but ufs doesn't at all.
Another thing that would be cool for future is maybe adding support for writable ntfs via ntfs-3g.

aragon
April 30th, 2011, 00:16
First only DD mode, no slices.

# gpart show da0
=> 63 7843752 da0 MBR (3.7G)
63 7843752 1 freebsd (3.7G)

The above looks strange to me, but TBH I can't recall playing with DD mode since I started using gpart. I will do some testing with this.


xmountd gives
CREATE da0

~/tmp/.xmountd/mountable is empty, and obmount.sh prints
<openbox_pipe_menu>
</openbox_pipe_menu>
This looks normal considering gpart's output above. I don't think my detection caters for this at the moment.

So i tried with slices and labels.
# gpart show da0s1
=> 0 7843752 da0s1 BSD (3.7G)
0 16 - free - (8.0K)
16 7843736 1 freebsd-ufs (3.7G)

This time xmountd gives
CREATE da0
CREATE da0s1
CREATE da0s1
CREATE da0s1a
CREATE da0s1c
CREATE da0s1a
CREATE da0s1a
CREATE da0s1c
CREATE da0s1a
CREATE da0s1ca
CREATE da0s1ca

Does that look like it should?
No, this looks rather strange. I will need to do some poking around here. Please do me another favour and send me your partition table as follows:

dd if=/dev/da0 of=/tmp/parttable bs=1k count=128

Gzip and attach here please.


Another thing that would be cool for future is maybe adding support for writable ntfs via ntfs-3g.
Ext2 too. :)

bbzz
April 30th, 2011, 00:33
Yeah figured something doesn't look right there :e
gpart was used to create da0s1a like this:


gpart create -s mbr da0
gpart add -b 63 -t freebsd da0
gpart create -s bsd da0s1
gpart add -i 1 -b 16 -t freebsd-ufs da0s1
newfs da0s1a

aragon
May 22nd, 2011, 23:11
I've had some time to do more work on this. Changes include:


Renamed to amount and version set to 0.5.
Improved handling of Android and other similar devices.
File system detection using file. (thanks wblock)
Untested ext2fs support.
Command line utility added.
Logging moved from stdout to syslog.
Bug fix: incorrect mount state in OpenBox menu generation.


Script file names have changed so I recommend deleting your old version completely to save you any confusion when installing this version.

If you want to see log messages, please setup your syslog to catch user.* or tag "amountd", eg.

/etc/syslog.conf

user.* /var/log/user

/etc/newsyslog.conf

/var/log/user 644 3 100 * JC


Since script names have changed, please update your sudoers file with the new names.

Everything else should work the same. An example of the command line utility in action:

$ amount
mount da0 msdosfs
mount da1 msdosfs/SAMSD
$ amount da0
mounting da0 msdosfs... success
$ ls -l /media
total 32
drwxr-xr-x 1 aragon wheel 32768 Jan 1 1980 da0/
$ amount
umount da0 msdosfs
mount da1 msdosfs/SAMSD
$ amount da0
umounting da0 msdosfs... success
$ ls -l /media
total 0


bbzz, sorry, I have been unable to reproduce the problem you're having. Your partition table looked fine here and worked fine too. I can only guess it's a hardware issue...

Todo:

Large FAT32 support.
NTFS support.

vermaden
May 23rd, 2011, 00:37
Large FAT32 support.
It should work to add -o large for ALL msdosfs mounts, it should not break anything I suppose.

NTFS support.
Check if there is ntfs-3g binary in ${PATH}, if not, then mount read only using base system mount_ntfs.

jjjesss
June 14th, 2011, 22:55
Hi all:

I've made a custom hack of fabulous 'amount'. It runs fine in XFCE 4.8. NTFS support was added but not widely tested, but it seems to work fine.

Thanks for the original 'amount', aragon. It's a great piece of code.

Attached to this post my hack.

aragon
June 14th, 2011, 22:58
Cheers jjjesss. I'll take a look at it soon. :)

bigtoque
June 16th, 2011, 20:35
@jjjesss and @aragon,

Thanks for your scripts!

@jjjess,

A couple of things:

First off, I added this line to my sudoers file bigtoque ALL=(ALL) NOPASSWD: /etc/amount/openthunar.sh but I still get asked for a password, so unless I run the command from a terminal, the script doesn't work for me. At the moment I'm just using the line %wheel ALL=(ALL) ALL

Have I entered the entry I need in my sudoers file incorrectly?

Second, the command run from the launcher icon doesn't work for me. If I right-click on the icon, edit the launcher and tell it to run from the terminal, mounting and unmounting works just fine. Unfortunately, you need to edit the launcher every time you mount and unmount.

Finally, (and I have no idea if this should or should not be part of the script), but when unmounting an iPod, I have to run the command camcontrol eject [device] to properly disconnect the iPod. I'm just curious if something like this could be added to the script.

aragon
June 16th, 2011, 20:45
so unless I run the command from a terminal
Are you saying that you don't get prompted for a password when it's run from a terminal? Can you provide more information on your WM/DE setup?

Finally, (and I have no idea if this should or should not be part of the script), but when unmounting an iPod, I have to run the command camcontrol eject [device] to properly disconnect the iPod.
By "properly disconnect", do you mean so that the iPod recognises that it can be disconnected?

When amount unmounts something, it unmounts the file system only. It doesn't try to "eject" or reset the hardware in any way. This means your device won't realise what's happening, but disconnecting it should be safe in terms of data integrity.

bigtoque
June 16th, 2011, 22:13
Are you saying that you don't get prompted for a password when it's run from a terminal? Can you provide more information on your WM/DE setup?

I'm using a stock XFCE 4.8.

I can see that my post wasn't worded that well. When I run the command from the launcher (without editing the launcher to open in a terminal), nothing happens (or at least I can't see anything happening).

When I edit the launcher to open in a terminal (or just run the command from a terminal), I get asked for my password. After I enter my password, I get the output:

Sorry, user bigtoque is not allowed to execute '/etc/amount/amount doCmd mount msdosfs /dev/msdosfs/FLASH /media/FLASH stefan' as root on bsd-toque.
Mountdir = /media/FLASH

I assume this means that the entry I made in my sudoers file wasn't correct.

By "properly disconnect", do you mean so that the iPod recognises that it can be disconnected?

When amount unmounts something, it unmounts the file system only. It doesn't try to "eject" or reset the hardware in any way. This means your device won't realise what's happening, but disconnecting it should be safe in terms of data integrity.

Yes, when I say "properly disconnect" I mean that the iPod goes from saying "Connected - Eject before disconnecting" on it's screen to "Ejecting" and finally "OK You may now disconnect".

You're suggesting that as long as the iPod has been properly unmounted, it should be safe to just disconnect it?

aragon
June 16th, 2011, 22:21
Sorry, user bigtoque is not allowed to execute '/etc/amount/amount doCmd mount msdosfs /dev/msdosfs/FLASH /media/FLASH stefan' as root on bsd-toque.
Mountdir = /media/FLASH

I assume this means that the entry I made in my sudoers file wasn't correct.

You are running /etc/amount/amount, so you need to add that to your sudoers.

What is openthunar.sh?


You're suggesting that as long as the iPod has been properly unmounted, it should be safe to just disconnect it?
Yes, it is safe. You can add the eject command if you like, but one downside I can think of is that once you unmount, you will have to physically unplug and replug your ipod to mount it again.

jjjesss
June 16th, 2011, 22:35
Hi all:

My user belongs to 'wheel' group in my computer, so I put in the /usr/local/etc/sudoers:

%wheel ALL=(ALL) NOPASSWD: /etc/amount/amount
%wheel ALL=(ALL) NOPASSWD: /etc/amount/amountd
%wheel ALL=(ALL) NOPASSWD: /etc/amount/openthunar.pl

Probably openthunar.pl does not need to be included but..

And the updatedesktop.pl is an absolutely dirty script, relying on things like whoami to guess the user who is clicking in the desktop icon but it's a matter of time (and hurry).

Next thing I'd like to implement is mount/unmount sd cards from my MMC Card Reader (/dev/mmcsd).

BR

bigtoque
June 16th, 2011, 22:42
You are running /etc/amount/amount, so you need to add that to your sudoers.

What is openthunar.sh?



Yes, it is safe. You can add the eject command if you like, but one downside I can think of is that once you unmount, you will have to physically unplug and replug your ipod to mount it again.

Thanks aragon, my problem was that I didn't have /etc/amount/amount in my sudoers. I put /etc/amount/openthunar.sh in there because that's what the launcher that came up on the desktop referenced.

Everything seems to work just fine.

jjjesss
June 17th, 2011, 09:37
Added support for /dev/mmcsdXXXX devices (MMC Card Reader integrated in laptops). Included some notes about permissions and the sudoers file.

jjjesss
June 18th, 2011, 11:59
aragon, one question: amountd intends to mount devices like /dev/adaxxx, for example, in my computer, /dev/ada0s3.journal. According to the code it seems only devices starting by da or in my hack mmcsd, so any ada device should be watched by amountd. So, why does this happen? I don't want amountd watch my computer partitions. How can be this arranged?

Thanks in advance.

richardpl
June 20th, 2011, 22:22
It looks like two or more instances of amountd can be run at same time, this should not be allowed.

This is an extremely useful tool and it makes our devd shine.

jjjesss
June 29th, 2011, 10:36
New update. Now two icons are created on the desktop when a drive is mounted. One is to unmount it and the another one is to explore the media with Thunar.

openthunar.sh can be customized to replace Thunar with whichever file manager.

BR

Columbo0815
July 24th, 2011, 10:21
New update. Now two icons are created on the desktop when a drive is mounted. One is to unmount it and the another one is to explore the media with Thunar.

openthunar.sh can be customized to replace Thunar with whichever file manager.

BR
Hi jjjesss, thank you very much for this helpful scripts! I love them! :) I have changed them a little bit, because I want to "install" it in /usr/local/etc/amount not in /etc/amount. And I use vfs.usermount=1 and a mountdir in $HOME instead of /media. So I don't have to use sudo and can mount without it.

2 questions (because my experience in scripting isn't really good):
- Can you rename the "Unmount"-button? When I mount the device there are 2 icons: "mount device" and "Explore device". If I run "mount device" the second time, it will be unmounted. But the name "mount device" to unmount is a little bit confusing. :)
- Can you upload it to the ports? :-D

Thanks
Columbo0815

jjjesss
July 25th, 2011, 01:03
Thanks should go to aragon, the guy who programed the 'amount' and 'amountd'. I only made a few hacks to work with xfce4.

About the 'ports'... aragon is author of the original code. So... I'm not very confortable publishing it in other site or so, only here, where aragon shared it with us.

About your other suggestions I think I could do it. So... stay tuned :D.. I'll try it.

BR

Columbo0815
July 25th, 2011, 05:00
Ok, I read the whole thread now... Thank you aragon! :)

Another thing: If I mount the Device, the new icon "explore" is named "explore $USER". Ok... I mount in /home/$USER/media but is this the reason?! :)

I think there are many users who will use (and love) the scripts. So aragon... Do you think a port of amount is possible?

gour
July 25th, 2011, 18:40
Thanks should go to aragon, the guy who programed the 'amount' and 'amountd'. I only made a few hacks to work with xfce4.

This could be real life-saver here. :-)

In the last few days I was reflecting what is the future of Xfce on FreeBSD desktop considering they're going to linux-only route.

I can personally mount manually, but it's not very user-friendly for the rest of my family members.

GNOME-3 is probably not according to my taste and that's why I've installed KDE yesterday.

Although people on #kde-freebsd were really helpful and provided two patches so I was able to finish building of KDE from ports, today I removed KDE. I simply do not like it and went back to my preferred Xfce.

Now, considering I use PCBSD-9.0 I wonder if such scripts could be added to it to 1st class user-experience for Xfce users?

jjjesss
July 26th, 2011, 08:45
I like KDE, but it's a bit heavy for my laptop. The scripts to mount/umount devices included in this posts are very useful but need to be improved. In my opinion there's no need to reinvent wheel or build big software layers only to mount devices. Tools like these, with improvements, is all XFCE4 and other wm need to deal with devices.

BR

kmoore134
July 26th, 2011, 17:48
This auto-mount script is quite handy, Thanks Aragon and jjjesss! I've begun to import it into our tree for PC-BSD 9, along with some modifications to make it support multiple WM's, icons, etc.

https://trac.pcbsd.org/changeset/11872

BTW what license is this code under? I'm assuming BSD, but I wanted to ask before marking it as such :)

gour
July 26th, 2011, 20:35
Hello Kris,

This auto-mount script is quite handy, Thanks Aragon and jjjesss! I've begun to import it into our tree for PC-BSD 9, along with some modifications to make it support multiple WM's, icons, etc.

https://trac.pcbsd.org/changeset/11872

BTW what license is this code under? I'm assuming BSD, but I wanted to ask before marking it as such :)

this is wonderful news. Thanks a lot for this contribution to PCBSD!

jjjesss
July 27th, 2011, 19:53
This auto-mount script is quite handy, Thanks Aragon and jjjesss! I've begun to import it into our tree for PC-BSD 9, along with some modifications to make it support multiple WM's, icons, etc.

https://trac.pcbsd.org/changeset/11872

BTW what license is this code under? I'm assuming BSD, but I wanted to ask before marking it as such :)

This is great! about BSD license I have no problems with it so... and Aragon seems to be missing lately :)

I can't wait for PC-BSD 9 and try this but... now that my system is 100% functional I'm wonder if I will can update the system without impact...

Thanks Kris

BR

aragon
August 6th, 2011, 14:44
Pardon my silence folks. Been busy moving into a new country. Now hopefully I can finish some cleanup that I've been wanting to do.

Glad this work so far has been useful.


BTW what license is this code under?

Public domain. :)

aragon
August 9th, 2011, 19:58
Hey,

I've finally submitted this as a port:

http://www.freebsd.org/cgi/query-pr.cgi?pr=159631

The port version is bumped to 0.6 and receives some changes:

* a proper daemon with RC script for start up (problem solved, richardpl).
* read-only NTFS support.
* experimental large FAT32 support (untested by me, but should work).
* handles spaces in labels now.
* code cleanup.

I'm going to be changing its architecture a bit for 0.7. Hopefully it will make clients simpler to write, and maybe remove the need for sudo. Oh, and read/write NTFS support (NTFS-3G) will be done by then too.

I've had a look at your code, Jes, and added mmcsd to the default DEVMATCH pattern. The rest I'll try do better when I've got the new architecture in 0.7 working. For now, still only CLI and Openbox are officially supported.

I haven't perused Kris's mods yet. Glad to see him taking it up for PC-BSD!

Columbo0815
August 10th, 2011, 08:38
Cool, thank you!

I think XRUN_DEPENDS= ${LOCALBASE}/bin/sudo:${PORTSDIR}/security/sudo means that this port needs sudo. Is it possible to make a make config menu for installing without sudo? Maybe there are users (here is one! :) ) that use vfs.usermount=1 So I don't need sudo...

aragon
August 10th, 2011, 11:05
Is it possible to make a "make config" menu for installing without sudo? Maybe there are users (here is one! :) ) that use vfs.usermount=1. So I dont need sudo...
Not possible at this stage. If you want to use vfs.usermount without sudo, you will have to modify amount code. In which case you can modify the port's Makefile too. :)

Hopefully 0.7 won't require sudo anymore.

kamikaze
August 12th, 2011, 23:20
I poked around for HAL-esque auto mounting setups, but they were all hacky or used amd - not really ideal for hot plug storage devices.Just out of curiosity, what's wrong with amd? On access mounting seems like a good idea to me.

aragon
August 13th, 2011, 00:19
Probably not much wrong with amd. I mainly wanted manual mounting abstracted enough to be easy. With amd, mounting is easy, but I guess a manual umount requires one to fumble on the command line.

zeissoctopus
August 13th, 2011, 15:48
Why no committer takes this PR ?

aragon
October 24th, 2011, 20:15
latest developments

musucopo
February 4th, 2012, 02:39
Thank you very much for your work aragon, vmount works perfectly with USB keys and USB HDD ntfs.
Thxs!