auto mounting in Openbox

XFCE, Fluxbox, Enlightenment, IceWM, WindowMaker, ION, etc.

auto mounting in Openbox

Postby aragon » 07 Apr 2011, 12: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 [man=8]amd[/man] - not really ideal for hot plug storage devices.

I've made a small auto mounting system that uses [man=8]devd[/man] 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 [file]/media[/file] (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 [thread=27233]volman[/thread] instead.
[2011-05-23] Latest version: [post=135232]here[/post]
aragon
Giant Locked
 
Posts: 2031
Joined: 16 Nov 2008, 17:04
Location: Cape Town, South Africa

Postby aragon » 07 Apr 2011, 12: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 [man=8]devd[/man], listens for device attachment messages and attempts to discover mountable filesystems on newly attached devices.

When running, amountd creates a directory for itself at [file]/tmp/.amountd[/file], below which it maintains the text file [file]mountable[/file]. 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 [file]amount[/file], 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: [file]obamount.sh[/file]. Written by me too for use with my window manager of choice, Openbox. I plan to include other clients into my distribution too, so feel free to make them public or send them my way.
aragon
Giant Locked
 
Posts: 2031
Joined: 16 Nov 2008, 17:04
Location: Cape Town, South Africa

Postby aragon » 07 Apr 2011, 13: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 [file]xmountd[/file] starting in the background. Place it in [file]~/bin[/file] and make sure it's executable. Then add it to your X startup, in my case [file]~/.xsession[/file]. Here's what mine looks like:
Code: Select all
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 [file]obmount.sh[/file] into [file]~/.config/openbox[/file].

Open [file]~/.config/openbox/menu.xml[/file] and locate your root-menu block. Add a Pipemenu element to it that executes [file]obmount.sh[/file]. Here's how mine looks:
Code: Select all
        <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:
Code: Select all
$ 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 [port]security/sudo[/port] if it isn't already installed:
[cmd=#]pkg_add -r sudo[/cmd]

Use visudo to add an entry to [file]sudoers[/file] that looks similar to mine:
Code: Select all
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:
Code: Select all
$ 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 [file]~/.xsession-errors[/file] in case you need to debug.

Comments/contributions appreciated. :D
aragon
Giant Locked
 
Posts: 2031
Joined: 16 Nov 2008, 17:04
Location: Cape Town, South Africa

Postby aragon » 07 Apr 2011, 15:16

Ah, geek pride at its best... here's a video of it in action:

http://www.youtube.com/watch?v=VI9koEAes3U
aragon
Giant Locked
 
Posts: 2031
Joined: 16 Nov 2008, 17:04
Location: Cape Town, South Africa

Postby roddierod » 08 Apr 2011, 21:24

Just tried it out. It works nicely.
User avatar
roddierod
Member
 
Posts: 697
Joined: 17 Nov 2008, 12:36
Location: On my Slingerlands!

Postby knk » 15 Apr 2011, 20: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:

Code: Select all

[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 "[FILE]/dev/[/FILE]" 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 [FILE]/usr/local/etc/mountagent.conf[/FILE] and [FILE]$HOME/.mountagent.conf[/FILE] (both are read, entries in the later may overwrite entries in the former).

Enjoy!
Attachments
mountagent.py.gz
(1.65 KiB) Downloaded 43 times
knk
Junior Member
 
Posts: 10
Joined: 13 Jan 2011, 21:19

Postby bbzz » 27 Apr 2011, 14: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 [FILE]~/tmp[/FILE] and [FILE]~/mnt[/FILE].
bbzz
Member
 
Posts: 858
Joined: 04 Nov 2010, 01:07
Location: random

Postby aragon » 27 Apr 2011, 20:41

I recommend checking for error output in [file]~/.xsession-errors[/file]. If that doesn't work, try call the [file]obmount.sh[/file] script manually to inspect output, eg.:

[cmd=$]obmount.sh umount da0s1a aragon[/cmd]

(replace "aragon" with your username)
aragon
Giant Locked
 
Posts: 2031
Joined: 16 Nov 2008, 17:04
Location: Cape Town, South Africa

Postby bbzz » 28 Apr 2011, 19:50

I'm not using [FILE]xsession[/FILE], but [FILE].xinitrc[/FILE]. Script is started nonetheless.

If I run
Code: Select all
.config/openbox/obmount.sh umount /dev/da0s1 bbzz
I get
Code: Select all
</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 [FILE]~/media[/FILE] and [FILE]~/tmp[/FILE] where appropriate in scripts.

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

Anyway, not sure what else to try.
bbzz
Member
 
Posts: 858
Joined: 04 Nov 2010, 01:07
Location: random

Postby aragon » 29 Apr 2011, 21:58

More information is really needed. Disable xmountd from starting in [file].xinitrc[/file] and run it manually in an xterm so you can see its output. Inspect the [file]/tmp/.xmountd/mountable[/file] file for volumes to appear/disappear as you insert/remove devices. Finally run the [file]obmount.sh[/file] script without parameters to inspect the menu XML it generates. If you post all that info here I should be able to help better.
aragon
Giant Locked
 
Posts: 2031
Joined: 16 Nov 2008, 17:04
Location: Cape Town, South Africa

Postby bbzz » 29 Apr 2011, 22: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.

Code: Select all
# gpart show da0
=>     63  7843752  da0  MBR  (3.7G)
       63  7843752    1  freebsd  (3.7G)


[FILE]xmountd[/FILE] gives
Code: Select all
CREATE da0


[FILE]~/tmp/.xmountd/mountable[/FILE] is empty, and [FILE]obmount.sh[/FILE] prints
Code: Select all
<openbox_pipe_menu>
</openbox_pipe_menu>


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


This time [FILE]xmountd[/FILE] gives
Code: Select all
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 [FILE]ntfs-3g[/FILE].
bbzz
Member
 
Posts: 858
Joined: 04 Nov 2010, 01:07
Location: random

Postby aragon » 29 Apr 2011, 23:16

bbzz wrote:First only DD mode, no slices.

Code: Select all
# 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.


bbzz wrote:[FILE]xmountd[/FILE] gives
Code: Select all
CREATE da0


[FILE]~/tmp/.xmountd/mountable[/FILE] is empty, and [FILE]obmount.sh[/FILE] prints
Code: Select all
<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.

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


This time [FILE]xmountd[/FILE] gives
Code: Select all
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:

[cmd=#]dd if=/dev/da0 of=/tmp/parttable bs=1k count=128[/cmd]

Gzip and attach here please.


bbzz wrote:Another thing that would be cool for future is maybe adding support for writable ntfs via [FILE]ntfs-3g[/FILE].

Ext2 too. :)
aragon
Giant Locked
 
Posts: 2031
Joined: 16 Nov 2008, 17:04
Location: Cape Town, South Africa

Postby bbzz » 29 Apr 2011, 23:33

Yeah figured something doesn't look right there :e
[FILE]gpart[/FILE] was used to create da0s1a like this:

Code: Select all
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
Attachments
parttable.gz
(467 Bytes) Downloaded 21 times
bbzz
Member
 
Posts: 858
Joined: 04 Nov 2010, 01:07
Location: random

Postby aragon » 22 May 2011, 22: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 [man=1]file[/man]. (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.

[file]/etc/syslog.conf[/file]
Code: Select all
user.*                  /var/log/user

[file]/etc/newsyslog.conf[/file]
Code: Select all
/var/log/user            644  3     100  *     JC


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

Everything else should work the same. An example of the command line utility in action:
Code: Select all
$ 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.
Attachments
amount-0.5.tar.gz
(2.52 KiB) Downloaded 82 times
aragon
Giant Locked
 
Posts: 2031
Joined: 16 Nov 2008, 17:04
Location: Cape Town, South Africa

Postby vermaden » 22 May 2011, 23:37

aragon wrote:[*] Large FAT32 support.

It should work to add [FILE]-o large[/FILE] for ALL msdosfs mounts, it should not break anything I suppose.

[*] NTFS support.

Check if there is [FILE]ntfs-3g[/FILE] binary in [FILE]${PATH}[/FILE], if not, then mount read only using base system [FILE]mount_ntfs[/FILE].
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
[FILE][color="DarkSlateBlue"]http://vermaden.blogspot.com[/color][/FILE]
User avatar
vermaden
Giant Locked
 
Posts: 2316
Joined: 16 Nov 2008, 19:37
Location: pl_PL.lodz

Postby jjjesss » 14 Jun 2011, 21: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.
Attachments
amount.tar.bz2
(23.14 KiB) Downloaded 46 times
jjjesss
Junior Member
 
Posts: 8
Joined: 14 Jun 2011, 21:35
Location: Spain, Europe

Postby aragon » 14 Jun 2011, 21:58

Cheers jjjesss. I'll take a look at it soon. :)
aragon
Giant Locked
 
Posts: 2031
Joined: 16 Nov 2008, 17:04
Location: Cape Town, South Africa

Postby bigtoque » 16 Jun 2011, 19:35

@jjjesss and @aragon,

Thanks for your scripts!

@jjjess,

A couple of things:

First off, I added this line to my [FILE]sudoers[/FILE] file
Code: Select all
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
Code: Select all
%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 [CMD=""]camcontrol eject [device][/CMD] to properly disconnect the iPod. I'm just curious if something like this could be added to the script.
bigtoque
Junior Member
 
Posts: 75
Joined: 16 Jul 2010, 05:55

Postby aragon » 16 Jun 2011, 19:45

bigtoque wrote: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?

bigtoque wrote: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 [CMD=""]camcontrol eject [device][/CMD] 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.
aragon
Giant Locked
 
Posts: 2031
Joined: 16 Nov 2008, 17:04
Location: Cape Town, South Africa

Postby bigtoque » 16 Jun 2011, 21:13

aragon wrote: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:

Code: Select all
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.

aragon wrote: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?
bigtoque
Junior Member
 
Posts: 75
Joined: 16 Jul 2010, 05:55

Postby aragon » 16 Jun 2011, 21:21

bigtoque wrote:
Code: Select all
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 [file]/etc/amount/amount[/file], so you need to add that to your sudoers.

What is [FILE]openthunar.sh[/FILE]?


bigtoque wrote: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.
aragon
Giant Locked
 
Posts: 2031
Joined: 16 Nov 2008, 17:04
Location: Cape Town, South Africa

Postby jjjesss » 16 Jun 2011, 21:35

Hi all:

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

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

Probably [file]openthunar.pl[/file] does not need to be included but..

And the [file]updatedesktop.pl[/file] is an absolutely dirty script, relying on things like [file]whoami[/file] 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 ([FILE]/dev/mmcsd[/FILE]).

BR
jjjesss
Junior Member
 
Posts: 8
Joined: 14 Jun 2011, 21:35
Location: Spain, Europe

Postby bigtoque » 16 Jun 2011, 21:42

aragon wrote:You are running [file]/etc/amount/amount[/file], 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 [file]/etc/amount/amount[/file] in my sudoers. I put [file]/etc/amount/openthunar.sh[/file] in there because that's what the launcher that came up on the desktop referenced.

Everything seems to work just fine.
bigtoque
Junior Member
 
Posts: 75
Joined: 16 Jul 2010, 05:55

Postby jjjesss » 17 Jun 2011, 08:37

Added support for [FILE]/dev/mmcsdXXXX[/FILE] devices (MMC Card Reader integrated in laptops). Included some notes about permissions and the [FILE]sudoers[/FILE] file.
Attachments
amount.tar.bz2
(23.19 KiB) Downloaded 48 times
jjjesss
Junior Member
 
Posts: 8
Joined: 14 Jun 2011, 21:35
Location: Spain, Europe

Postby jjjesss » 18 Jun 2011, 10:59

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

Thanks in advance.
jjjesss
Junior Member
 
Posts: 8
Joined: 14 Jun 2011, 21:35
Location: Spain, Europe

Next

Return to Other Window Managers

Who is online

Users browsing this forum: No registered users and 0 guests