Mount points including spaces are not umounted at shutdown

Bug #32455 reported by Gary Coady
4
Affects Status Importance Assigned to Milestone
sysvinit (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

When a mount point with spaces exists, it is not unmounted at shutdown:
in /etc/mtab
/dev/sda1 /media/LEXAR\040MEDIA vfat rw,nosuid,nodev,quiet,shortname=mixed,uid=1000,gid=1000,umask=077,iocharset=utf8 0 0

See the getmntent manpage for the /etc/mtab syntax:
Since fields in the mtab and fstab files are separated by whitespace, octal escapes are used to represent the four characters space (\040), tab (\011), newline (\012) and backslash (\134) in those files when they occur in one of the four strings in a mntent structure.

Related branches

Revision history for this message
Gary Coady (garycoady) wrote : Patch for /etc/init.d/umountfs

This patch includes a few changes:
read takes a -d flag, so it doesn't strip out backslashes.
It echoes $DIR into a sed command, to replace certain octal sequences with the appropriate whitespace.
Couldn't get escaping of backslashes, etc. to work reliably in bash, dash - so I moved to calling umount individually on each directory, rather than using $DIRS (dash seemed to use different backslash escaping rules).

Tested somewhat in bash and dash so far.

Revision history for this message
Chris Moore (dooglus) wrote : more complete patch

Rather than having a separate sed expression for every possible backslashed octal triplet that we may see in /etc/mtab, we can use bash's built in "printf %b" conversion to convert \040 to a space, and all the other \nnn characters to the correct character.

There is a slight problem with this however - bash's printf accepts 4 digit octal codes, so if there is a space followed by a zero in your mount point it will show up in the mtab as "\0400" and bash will convert this as a single 4-digit octal character.

To work around this I use a sed expression to replace any octal digit which directly follows a 3 digit escaped octal character \nnn by its own escaped octal form, so for example "\0400" will be replaced with "\040\060" which bash's printf %b will then convert to " 0" as it should do.

I've tested this on all manner of weird and wonderful mount points and haven't seen it fail.

Revision history for this message
Gary Coady (garycoady) wrote :

However, this doesn't work with dash. Is there an Ubuntu policy dealing with whether init scripts can depend on bash rather than generic POSIX shells?

If it can, then it just needs a change to the #! line.

Revision history for this message
Scott James Remnant (Canonical) (canonical-scott) wrote :

Parsing of /etc/mtab should be done with a small C helper that wraps getmntent

Likewise /etc/fstab parsing in other scripts should be done with a getfsent helper

Revision history for this message
Scott James Remnant (Canonical) (canonical-scott) wrote :

Confirmed, but not for dapper

For dapper I'd like to move fstab mounting into udev rules anyway (fear now, gentle folk)

Changed in sysvinit:
assignee: nobody → keybuk
status: Unconfirmed → Confirmed
Revision history for this message
Scott James Remnant (Canonical) (canonical-scott) wrote :

Neither for edgy, will probably get done when filesystem mounting/unmounting is handled by upstart natively. I'll certainly keep this in mind when writing the upstart jobs

Changed in sysvinit:
assignee: keybuk → nobody
Revision history for this message
Launchpad Janitor (janitor) wrote :
Download full text (25.4 KiB)

This bug was fixed in the package sysvinit - 2.87dsf-4ubuntu1

---------------
sysvinit (2.87dsf-4ubuntu1) karmic; urgency=low

  * Merge from debian unstable, remaining changes:
    - Support Cell processor:
      + debian/initscripts/postinst: Create spu system group and /spu mount
        point if we are running on a Cell processor.
      + debian/initscripts/etc/init.d/mountkernfs.sh: Mount spufs if Cell
        processor is detected.
      + debian/initscripts/lib/init/mount-functions.sh: Modprobe spufs
        if not available.
      + debian/control: Add initscripts dependency 'passwd' for groupadd.
      (Forwarded to Debian #483399)
    - Use tmpfs mounts for /var/lock and /var/run:
      + debian/initscripts/share/default.rcS: Enable RAMRUN and RAMLOCK by
        default.
      + debian/initscripts.postinst: Enable RAMRUN and RAMLOCK in
        /etc/default/rcS on upgrades. This needs to be kept until the next
        LTS.
      + debian/initscripts/etc/init.d/mountkernfs.sh: Propagate files from the
        initramfs to our new /var/run, so that we can populate
        /var/run/sendsigs.omit from initramfs.
    - Boot ordering differences:
      + mountkernfs.sh: 02 -> 01
      + mountdevsubfs.sh: 04 -> 11
      + bootlogd: disabled by default
      + checkroot.sh: 10 -> 20
      + mtab.sh: 12 -> 22
    - debian/patches/91_sulogin_lockedpw.dpatch: Disable "root account is
      locked" warning, since this is the default in Ubuntu. Document this in
      sulogin.8.
    - debian/control: Drop Essential: yes from packages since we use Upstart.
    - debian/control: Conflict/Replace sysvconfig which has also previously
      provided service(8).
    - debian/control, debian/rules: Previous name for sysvinit-utils was
      'sysvutils' in Ubuntu, so Conflict/Replace/Provide it. Also create a
      dummy sysvutils package, since Hardy has reverse versioned dependencies
      to it. This needs to be kept until after the next LTS.
    - debian/control: Depend on lsb-base (>= 3.2-14) for status_of_proc()
      function.
    - debian/initscripts/etc/init.d/checkfs.sh: Don't depend on hwclockfirst
      which Ubuntu does not have.
    - debian/initscripts/etc/init.d/mountkernfs.sh: Always mount devpts, and
      do not touch /dev/ptmx (which is already managed by udev).
    - debian/initscripts/etc/init.d/mountkernfs.sh: mount fusectl if it is
      available
    - debian/initscripts/etc/init.d/mountkernfs.sh: mount securityfs if it is
      available. This allows for easier AppArmor confinement of applications
      early in the boot process. LP: #399954
    - debian/initscripts/etc/init.d/mountkernfs.sh: mount debugfs if it is
      available.
    - debian/initscripts/etc/init.d/ondemand: Sleep for 60 seconds, then
      set CPU Frequency Scaling governor to "ondemand". LP: #341573.
    - debian/initscripts/etc/init.d/umountfs: Don't unmount filesystems
      that precede root or use force for some mountpoints.
    - debian/initscripts/etc/network/if-up.d/mountnfs: Rename ifstate
      file to /var/run/network/ifstate
    - ./debian/initscripts/lib/init/usplash-fsck-functions.sh: Use blkid,
      vol_id is gone.
    - debian/initscripts.{...

Changed in sysvinit (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.