Blog Forum Wiki Links Contact Us
 
Translations of this page:

Proper unmount of external drives

There is a lot of discussion in this thread about SD corrpution on umount detailing the different ways the default xandros installation does a shutdown and suspend and how the unmounting of external devices is handled (SD cards, USB and truecrypt volumes). Here is some insight into possible solutions.

Shutdown and Suspend details

It is important to understand which scripts are called by xandros on shutdown and suspend.

Shutdown

Power button + Shutdown or Reboot selected

  1. Dialog is called: /etc/acpi/powerbtn.sh
    1. This calls: /sbin/fast{reboot | shutdown}.sh

Suspend

Lid closed

  1. This calls: /etc/acpi/lidbtn.sh
  2. Also calls: /etc/acpi/suspend2ram.sh

Fn F1 pressed

(The Zz button)

  1. This calls: /etc/acpi/suspend2ram.sh

Power button + Suspend selected

  1. This calls: /etc/acpi/suspend2ram.sh

Setup proper unmount

  1. Install lsof, run: 'apt-get install lsof'. (see: http://wiki.eeeuser.com/addingxandrosrepos if you have trouble) This program is required in order to close any programs that are using files on the drive so that you can unmount the disk.
  2. copy the jumount.sh script from below to your system
  3. For suspend: place a call to jumount.sh in /etc/suspend2ram.sh (or /etc/acpi/suspend2ram.sh) just after the “sync” line.
  4. For shutdown: place a call to jumount.sh in /etc/powerbtn.sh (or /etc/acpi/powerbtn.sh)

Setup remount after suspend

unmounting on suspend will close any applications you have open using those files, which slightly defeats the use of suspending in the first place. The system will have to remount the disk when you come out of suspend. You can get over this by putting in a line to remount the SD card into suspend2ram.sh after it comes back for suspend.

  1. Find the this line in the suspend2ram.sh: echo -n “mem” > /sys/power/state
  2. add this command after it: sudo mount -a

Scripts

Important to note that apart from the jumount.sh script the others are scripts which are already on your system and which programs like Tweakee other tweak programs copy from their own archive. Meaning, when you edit the system scripts and then make a change in a tweak program you might find your changes lost.

jumount.sh script

Change the paths for your paticular SD or USB drive mount point.

### jumount.sh ###
#!/bin/bash
sync
echo $(date) >> /var/log/jumount.log
# write list of open files on SD card to temp file
lsof | grep "/home/user/sdhc" > /tmp/jumount.log
# copy temporary list to log file
cat /tmp/jumount.log >> /var/log/jumount.log
# kill any processes with open files
grep "/home/user/sdhc" /tmp/jumount.log | awk '{system ("kill -TERM "$2)}'
# wait for the processes to unwind
sleep 2
sync
# use eject to dismount the SD card (essential!)
/usr/bin/eject /home/user/sdhc 2>> /var/log/jumount.log
# check if eject has fully dismounted SD card.  If not, dismount it explicitly
df | grep /home/user/sdhc | awk '{system("umount "$1)}'

unmountenc script

This script unmounts a truecrypt partition whose raw file is on a SD card. It unmounts the encrypted partition first and then unmounts the SD drive that contained the raw file. If you run this by hand you will need to do so outside of the path for the SD or truecrypt drives.

#!/bin/sh
# IMPORTANT: we use this value to avoid killing ourselves. should match
# the script file name:
SCRIPTNAME=unmountenc
# Set this to the mountpoint of your SD card
SD=/media/D:
 
# Shouldnt need to change this unless you have other encrypted drives. This is the loop device for the encrypted drive. 
DEV=/dev/loop0
MNT=`df | grep $DEV | awk '{print $6}'`
 
echo "Closing applications using $MNT ($DEV):"
# if we are running under the SD or MNT we want to unmount
# we have to avoid killing ourselves by filtering out:
# grep, lsof, awk, sort, uniq, our PID for bash, script name
sudo lsof +c 0 | grep $MNT | awk '{print $1 " " $2}' | sort | uniq | egrep -v "grep|lsof|awk|sort|uniq|$PPID|$SCRIPTNAME" || echo "no applications using $MNT"
# 15 = SIGTERM
echo "First sync disks before closing the applications"
sudo sync
echo "Now closing applications"
sudo lsof +c 0 | grep $MNT | awk '{print $1 " " $2}' | sort | uniq | egrep -v "grep|lsof|awk|sort|uniq|$PPID|$SCRIPTNAME" | awk '{system("kill -15 "$2)}'
# wait for processes to stop
sleep 3
 
echo "Unmounting $MNT and $SD"
sudo sync && truecrypt -d && sudo sync && sudo eject $SD
echo "check df:"
df | egrep "$MNT|$DEV|$SD" || echo everything unmounted

A pop up to test if the unmount was successful

You can add this script to the end of the jumount.sh and add an icon to your desktop sudo /home/user/jumount.sh to unmount while your computer is still on and have confirmation that it was successful!!

varCheck=`mount | grep " /home/user/SDHC "`
if [[ ${#varCheck} > 0 ]]
then
zenity --error \
--text="Close all programs and try again"
else
zenity --info \
--text="Drive is unmounted"
fi
 
howto/properumountstorage.txt · Last modified: 2008/07/29 05:36 by samfiller
 
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki