Here is a workaround which I believe is Ubuntu and Debian compliant.  It
requires sed, inotify-tools, and upstart (current versions of Ubuntu use
upstart instead if initd):

Step 0) Prep:
sudo apt-get install inotify-tools (sed and upstart are standard parts of 
Ubuntu now)

Step 1) Create an upstart job which will run and respawn whenever the system is 
running (the criteria are identical to the current tty* jobs).  Please note 
that upstart jobs are NOT shell scripts.  Please do not include a shebang, or 
set the executable bits on them.
(As the su) I created a file called /etc/event.d/sshfsmountfix, with the 
following contents:
# sshfsmountfix - FUSE based sshfs mounting fix
#
# This service maintains a getty on monitors the /etc/mtab
# file from the point the system is started until it is shut
# down again.  It runs a small sed script to change entries
# with fuse.sshfs as their "type" so that they can be
# correctly unmounted by the same user that mouned them
# with umount or applications that call umount (otherwise,
# fusermount -u [-z] is required)

start on runlevel 2
start on runlevel 3

stop on runlevel 0
stop on runlevel 1
stop on runlevel 4
stop on runlevel 5
stop on runlevel 6

respawn
exec /usr/local/bin/mtab-monitor

Step 2) Create the script that this job execs and respawns as needed.  Please 
note every time inotify observes a MODIFY event for /etc/mtab, this script will 
execute sed on /etc/mtab (in-place), and this script will then exit!!!  Yes, it 
will exit.  Do not fear.  Since this script is called by the upstart job above, 
it will automatically respawn as long as the runlevel is 2 or 3 (or if it 
changes to 2 or 3).  Upstart jobs are cool. :)
(As the su), I created a file called /usr/local/bin/mtab-monitor with the 
following contents:
#!/bin/sh
while inotifywait -e modify /etc/mtab; do
        /bin/sed 's/\([EMAIL PROTECTED],[EMAIL PROTECTED])\(.\{1,\}\) 
fuse\.sshfs /sshfs#\1\2 fuse /' -i /etc/mtab
done

Step 3) Set the permissions and ownership for /usr/local/bin/mtab-monitor
sudo chown root.root /usr/local/bin/mtab-monitor
chmod 700 /usr/local/bin/mtab-monitor

Step 4) Manually start the new upstart sshfsmountfix job (you can verify that 
the job exists and is stopped with "sudo initctl list":
sudo initctl start sshfsmountfix

Note that this fix is ONLY a workaround.  It does not fix the bug that
caused this condition to occur.  It also does NOT make changes to what
is seen by /proc/mounts or /proc/self/mounts, or any programs that
depend on /proc/mounts or /proc/self/mounts.

However, this workaround is nice in that it only has to be installed by
a su once, and it should "automagically" fix any sshfs entries in
/etc/mtab.  It of course, is completely reliant on inotify (not
officially supported by Ubuntu) and upstart (officially supported by
Ubuntu).  In all fairness, sshfs is not officially supported by Ubuntu
either, so this doesn't really change your support status.

High-level overview:  An upstart job called sshfsmountfix is started and
respawned as needed on runlevels 2 and 3, and stopped for all other
runlevels.  This job, when running, keeps a copy of /usr/local/bin/mtab-
monitor running at all times.  /usr/local/bin/mtab-monitor runs
inotifywait until a MODIFY event for /etc/mtab is seen by inotify.  It
then runs sed to "fix" any problem sshfs lines in /etc/mtab, and exits
(and then is respawned by the upstart job sshfsmountfix).  The sed line
is designed to change the fuse.sshfs part of the line to fuse, and to
prepend sshfs# to the beginning of the line.  This should match any
entries you have in fstab, allowing a regular fuse user to unmount more
easily.  Since the upstart job, and in turn, the called script, and in
turn, sed, are run by root, no sudo lines are needed in these files, and
no user intervention is required.  sshfs lines in /etc/mtab should be
automatically fixed with no user intervention whatsoever when this fix
is installed as described above.

Here is a reminder that this is GNU software (including my fixes listed
above), and there is no warranty.  If my fix breaks your computer, you
are own your own.  However, it is free, and will remain that way
(because it is GNU).

-- 
In hardy, sshfs /etc/mtab and /etc/fstab do not match, umount and unmount 
through "Disk Mounter" applet do not work
https://bugs.launchpad.net/bugs/243298
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to