LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-23-2010, 04:29 AM   #1
jsteel
Member
 
Registered: Mar 2007
Location: England
Distribution: Arch
Posts: 392

Rep: Reputation: 34
Auto Unmount before Suspend?


Hi,

I'm looking for a way to automatically unmount (CD drive, remote SMB/SSH/FTP shares etc.) as I ask my computer to suspend.

Basically I have a number open and can't be bothered to unmount each one before I suspend. If I leave them mounted and resume from suspend, I try browsing one and it throws an error (this is in GNOME/Nautilus). Nautilus will then unmount (or just remove the mount) and remount it when I click on it again. These are connections set up via "Connect to Server" in GNOME.

Thanks
 
Old 01-23-2010, 05:21 AM   #2
ozanbaba
Member
 
Registered: May 2003
Location: İzmir
Distribution: Slackware64 15.0 Multilib
Posts: 778

Rep: Reputation: 135Reputation: 135
Code:
 Creating your own hooks

If you want to do something specific to your setup during suspend / hibernate, then you can easily put your own hook into /etc/pm/hooks. The hooks in this directory will be called in alphabetic order during suspend (that's the reason their names all start with 2 digits, to make the ordering explicit) and in the reverse order during resume.

I'm showing a pretty useless demonstration hook here, that will just put some informative lines into your logfile:

#!/bin/bash
case $1 in
    hibernate)
        echo "Hey guy, we are going to suspend to disk!"
        ;;
    suspend)
        echo "Oh, this time we're doing a suspend to RAM. Cool!"
        ;;
    thaw)
        echo "oh, suspend to disk is over, we are resuming..."
        ;;
    resume)
        echo "hey, the suspend to RAM seems to be over..."
        ;;
    *)  echo "somebody is calling me totally wrong."
        ;;
esac

Put this into /etc/pm/sleep.d/66dummy, do a chmod +x /etc/pm/sleep.d/66dummy and it will spew some useless lines during suspend / resume.

Warning: All the hooks run as user root. This means that you need to be careful when creating temporary files, check that the PATH variable is set correctly etc. to avoid security problems.
 
Old 01-23-2010, 05:32 AM   #3
jsteel
Member
 
Registered: Mar 2007
Location: England
Distribution: Arch
Posts: 392

Original Poster
Rep: Reputation: 34
That looks like what I'm after, thanks. But for example if I get it to unmount /media/cdrom0 before suspend, that is fine but if there is nothing mounted at /media/cdrom0 it complains and will not suspend. Is there a way to tell it to ignore errors and continue?

Thanks
 
Old 01-23-2010, 06:18 AM   #4
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
You could use df to check for mounted filesystems and peform the unmount only if the filesystem is mounted
 
Old 01-23-2010, 06:22 AM   #5
ozanbaba
Member
 
Registered: May 2003
Location: İzmir
Distribution: Slackware64 15.0 Multilib
Posts: 778

Rep: Reputation: 135Reputation: 135
i don't know a general way, but it is possible to tell mount ignore some errors on fs spesific errors. maybe some sh scripting help needed but i don't remember anything
 
Old 01-23-2010, 06:38 AM   #6
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Test with df:
Code:
if df /media/cdrom0 > /dev/null 2>&1
then
   ###
   ### filesystem is mounted!
   ###
   umount /media/cdrom0
fi
 
Old 01-23-2010, 06:43 AM   #7
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
if you try to umount a filesystem that is not mounted, you should get a message like:

umount: /media/cdrom0 in not mounted (according to mtab)

sometimes if you try to umount a device that is not responding umount can be problematic (NFS tends to do this sometimes) in this scenario you should use umount -f (to attempt to force the umount operation)
 
Old 01-23-2010, 09:56 AM   #8
jsteel
Member
 
Registered: Mar 2007
Location: England
Distribution: Arch
Posts: 392

Original Poster
Rep: Reputation: 34
OK thanks I'll have a play with this information. This is fine for my CD drive, but what about SMB/SSH etc. sessions mounted through Nautilus? As these do not appear with the df or mount commands.

Thanks
 
Old 01-23-2010, 10:01 AM   #9
ozanbaba
Member
 
Registered: May 2003
Location: İzmir
Distribution: Slackware64 15.0 Multilib
Posts: 778

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by jsteel View Post
OK thanks I'll have a play with this information. This is fine for my CD drive, but what about SMB/SSH etc. sessions mounted through Nautilus? As these do not appear with the df or mount commands.

Thanks
maybe using samba tools would be the solution. however if it's not shown with mount and df then it's something else that Natilious is doing other than mounting them.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto suspend for my home server anutosho Linux - Server 10 12-30-2018 12:58 PM
flash disk can't auto unmount in gnome fedora 7 macintoshiba Linux - Hardware 0 11-19-2007 12:24 PM
AUM X-915 Mp4 Auto-unmount 2Pacalypse Linux - Hardware 3 05-28-2007 06:25 AM
unable to auto unmount after accessing dir with Konqueror infodoc Linux - Software 2 11-12-2003 10:22 PM
Auto suspend Donny Linux - Newbie 3 10-13-2002 04:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration