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 - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 05-25-2011, 11:20 PM   #1
dimm0k
Member
 
Registered: May 2008
Location: Brooklyn ZOO
Distribution: Slackware64 14.2
Posts: 564

Rep: Reputation: 56
Help creating a suspend/hibernate script to handle USB HDDs


Currently running Slackware 13.37 64-bit on a notebook and finally have suspend/hibernate after realizing that USB devices, especially USB HDDs, need to be disconnected before suspend/hibernate can work. Problem is I have 2 USB HDDs that are connected to my notebook whenever the notebook is stationary for the extra storage so I'd like to create a script that would get invoked that would stop the suspend/hibernate process if certain partitions are mounted. I know what I would like to accomplish, but I have basic scripting knowledge so I was hoping to get some assistance.

1. script would basically store a user specified string containing devices that are non-USB, ie: $NONUSB="/dev/sda /dev/sdb"

2. possibly use /etc/mtab to get a list of what is currently mounted and then remove lines containing whatever is specified in $NONUSB and store those values in $USB

3. run a for loop that executes 'umount' on each token in $USB
3a. stop suspend/hibernate process if 'umount' fails at any point
3b. if 'umount' passes then suspend/hibernate

Is this possible?
 
Old 05-26-2011, 01:01 PM   #2
dimm0k
Member
 
Registered: May 2008
Location: Brooklyn ZOO
Distribution: Slackware64 14.2
Posts: 564

Original Poster
Rep: Reputation: 56
Ok, so so far I have the following which lets a user specify devices that are not USB and removes those specific entries from /etc/mtab, storing them in /tmp/mountedusb. From that file the script issues the umount command to unmount all the entries in /tmp/mountedusb. The script gives an "exit 1" to abort suspend/hibernation if umount fails along the way. Is it possible to avoid the use/creation of /tmp/mountedusb and have everything done by passing things in memory? Anything else I might be missing that I should include to make it a little more robust?

Code:
#!/bin/sh

# devices that are known to not be USB
NONUSB="/dev/sda /dev/sdc"
DEVICES="0000:00:1a.0 0000:00:1d.0"

case "${1}" in
  hibernate|suspend)
    # writes to disk
    /bin/sync

    # extract first column of /etc/mtab, remove everything that is not /dev/sd?
    cat /etc/mtab | cut -d" " -f1 | grep /dev/sd > /tmp/mountedusb

    # remove devices listed in NONUSB, essentially creating a file that contains only
    # USB/removable devices
    for nu in $NONUSB; do
      cat /tmp/mountedusb | grep -v $nu > /tmp/mountedusb.tmp
      mv -f /tmp/mountedusb.tmp /tmp/mountedusb
    done

    # unmount devices, abort suspend if umount fails
    for um in `cat /tmp/mountedusb`; do
      /bin/umount $um 2> /dev/null
      if [ $? -gt 0 ]; then
        exit 1
      fi
    done

    # Unbind ehci_hcd for all devices
    for d in $DEVICES; do
      echo -n "$d" | tee /sys/bus/pci/drivers/ehci_hcd/unbind
    done
    ;;
  resume|thaw)
    # Bind ehci_hcd for all devices
    for d in $DEVICES; do
      echo -n "$d" | tee /sys/bus/pci/drivers/ehci_hcd/bind
    done
    ;;
esac

Last edited by dimm0k; 05-26-2011 at 02:06 PM.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu - Can't Hibernate or Suspend orangesky Linux - Laptop and Netbook 12 01-28-2011 06:25 PM
[SOLVED] Can't suspend or hibernate 0zMe Slackware 5 06-27-2010 01:43 PM
Need to suspend or hibernate fletcher08 Linux - Newbie 1 04-18-2010 10:24 AM
my laptop does not hibernate or suspend? kiruja Linux - Newbie 1 03-18-2010 06:58 AM
Boot from USB key, does suspend or hibernate work? paulsiu Linux - Hardware 1 05-02-2008 02:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:15 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