Comment 1 for bug 48517

Revision history for this message
In , Marcel Sebek (sebek64) wrote : Re: /etc/init.d/umountfs: swapoff should be called before unmounting localfs and not after?

On Fri, Sep 16, 2005 at 10:55:37AM +0200, johannes wrote:
> hi all,
>
> i'm using a swapfile in a file on a local filesystem "/data/swapfile" (not a swap partition!)
> during shutdown /etc/init.d/umountfs first tries to unmount all local filesystems and then deactivates all swap
> but unmounting of the partitition wich has the swapfile "/data" fails because the swapfile is still active
>
> if i change /etc/init.d/umountfs in such a way that it first calls swapoff and then unmounts the local filesystems it works correctly
>

I think it should unmount all tmpfs'es (except /dev and similar) first.
Then it can safely turn off swapping. Doing it in reverse order could
cause trouble in some configurations (eg. /tmp as tmpfs).

Something like this:

do_stop () {
    # Umount all memory filesystems except /dev
    log_begin_msg "Unmounting memory filesystems..."
    LANG=C sort -r -k 2 /etc/mtab |
    (
    DIRS=""
    while read DEV DIR TYPE REST ; do
        case "$TYPE" in
        tmpfs)
            ;;
 *)
            continue
            ;;
        esac

        case "$DIR" in
        /dev)
            continue
            ;;
        esac
        DIRS="$DIRS $DIR"
    done
    umount -r -d $DIRS
    )
    log_end_msg $?

    log_begin_msg "Deactivating swap..."
    swapoff -a
    log_end_msg $?

    # Umount all filesystems except root and the virtual ones
    log_begin_msg "Unmounting local filesystems..."

    # List all mounts, deepest mount point first
    LANG=C sort -r -k 2 /etc/mtab |
    (
    DIRS=""
    while read DEV DIR TYPE REST ; do
 case "$DIR" in
 /|/proc|/dev|/.dev|/dev/pts|/proc/*|/sys)
     continue # Ignoring virtual file systems needed later
     ;;
 esac

        case $TYPE in
        proc|procfs|linprocfs|devfs|sysfs|usbfs|usbdevfs|devpts)
     continue # Ignoring non-tmpfs virtual file systems
            ;;
        esac
 DIRS="$DIRS $DIR"
    done
    umount -r -d $DIRS
    )
    log_end_msg $?
}

--
Marcel Sebek