Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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?
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
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)
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.