SD card unmounting when suspending

Discussion in 'Linux' started by poesje, Jan 11, 2009.

  1. poesje

    poesje

    Joined:
    Dec 17, 2008
    Messages:
    16
    Likes Received:
    0
    For everyone who losses all the data on a sd card when suspending. People omitted the problem by using XFS on those cards, but personally I didn't want a journaling filesystem on a flash card.

    So when I looked closer at the problem, it is caused by not unmounting the card when going to suspend so (i presume) the device cannot be unloaded while it is being disconnected. Therefore when the system comes back from suspend and detects the card reader again and assigns the next device number to the card, after which hal automounts it. And when it is double mounted through different devices it erases all the data.

    If I unmounted the sd-card manually before suspending, nothing went wrong when I resumed. Except for HAL that generated a message so that the card was automounted again. And since I want to have a SD card in the left slot all the time, I wrote a simple script to unmount the cardslots.

    /usr/lib/pm-utils/sleep.d/97acermmcblk
    Code:
    #!/bin/sh
    # . "${PM_FUNCTIONS}"
    case "$1" in
      hibernate|suspend)
        MOUNTPOINTS=$(mount -l | awk '/mmcblk/{print $1}')
        if [ $MOUNTPOINTS ];then
          umount $MOUNTPOINTS
        fi
        exit 0
        ;;
      thaw|resume)
        mount -a
        exit 0
        ;;
      *)
        ;;
    esac
    
    This will unmount any /dev/mmcblk device if /dev/mmcblk0 exists when suspending. And wil reload the fstab when resuming.

    And in order to keep hal from generating messages about a newly found card device. I created a rule for hal that makes it ignore a single device.

    /etc/hal/fdi/preprobe/10-leftcardreader.fdi
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <deviceinfo version="0.2">
     <device>
      <match key="block.device" string="/dev/mmcblk0">
       <merge key="info.ignore" type="bool">true</merge>
      </match>
     </device>
    </deviceinfo>
    
     
    poesje, Jan 11, 2009
    #1
  2. poesje

    donec

    Joined:
    Sep 11, 2008
    Messages:
    952
    Likes Received:
    0
    It may be that those people are not really loosing their data but just the access to the SDHC card. If that is the case then reinstalling the OS may fix the problem.
     
    donec, Jan 13, 2009
    #2
  3. poesje

    jcm

    Joined:
    Sep 3, 2008
    Messages:
    51
    Likes Received:
    0
    Location:
    Eastern England
    After installing acpid, creating a conf. file in /etc/acpi/events/ with the following code in it [event=button/lid.* action=/usr/sbin/pm-suspend, thanks jorge ;) ], coming out of suspension I found the file system for the sd card in the expansion slot was corrupted as a "superblock" couldn't be recovered to retrieve my data, so it seems you have no choice but to reformat to ext2.

    @poesje, I followed your script and xml files, but unfortunately they never worked, and made my mmcblk0 SD-card icon disappear permanently. :p Still, thanks for the information.
     
    jcm, Jan 25, 2009
    #3
  4. poesje

    poesje

    Joined:
    Dec 17, 2008
    Messages:
    16
    Likes Received:
    0
    I've updated the unmount script in order to make it more stable. Since I noticed sometimes unmounting would give an error and abort standby.

    And for the xml, the first cardreader will be totally ignored by hal. So it would also disappear from thunar. The xml doesn't need to be created to make the unmounting work, in my case it will not popup thunar when coming out of standby (for I always have a SD in my left cardreader and mounted somewhere).
     
    poesje, Jan 26, 2009
    #4
  5. poesje

    jcm

    Joined:
    Sep 3, 2008
    Messages:
    51
    Likes Received:
    0
    Location:
    Eastern England
    poesje, or anyone else reading, could you insert an action in between the code below of a .conf file that unmounts mmcblk0 -- for instance, action=umount dev/mmcblk0? I'm not familiar with how to use acpi scripts for events and actions, but it kind of looks straightforward.

    event=button/lid.*
    action=/usr/sbin/pm-suspend
     
    jcm, Jan 27, 2009
    #5
  6. poesje

    poesje

    Joined:
    Dec 17, 2008
    Messages:
    16
    Likes Received:
    0
    acpi scripts execute a single script on the selected event. So in order to add a addition action, you can create a script which will be executed and call the pm-suspend in that script.

    Or you could just do as I did, add a script to pm-utils which is executed when pm-suspend is called. As in my 97acermmcblk script.
     
    poesje, Jan 28, 2009
    #6
  7. poesje

    jcm

    Joined:
    Sep 3, 2008
    Messages:
    51
    Likes Received:
    0
    Location:
    Eastern England
    Okay, thanks for the info, poesje.

    You know, we're going to great lengths to get this suspend feature to work, which affects a lot of laptops as well, but perhaps proper suspend/resume mode for SD cards has been fixed in the updated F10 kernel? Does anyone know? I've yet to do a single F10 update yet. :|
     
    jcm, Jan 28, 2009
    #7
  8. poesje

    poesje

    Joined:
    Dec 17, 2008
    Messages:
    16
    Likes Received:
    0
    The required feature for suspend with cards in the slots is available in the kernel, but it is marked dangerous. For it makes the kernel think the cards always stay in when it goes to suspend, so it will damage your sd-fs when it is removed while in suspend. Therefor I don't think they will enable the feature in the default kernel. It is ofcourse possible to create a custom kernel which is also optimized for the One and will be smaller (so also faster).
    Someday soon I'll try to make a custom kernel rpm (also because I want to learn making custom packages).
     
    poesje, Jan 29, 2009
    #8
  9. poesje

    EasyTarget

    Joined:
    Oct 7, 2008
    Messages:
    13
    Likes Received:
    0
    Location:
    Amsterdam, the Netherlands
    I just thought I'd drop a note in here, I hit this over the weekend when I 'accidentally' suspended the machine :-S and corrupted my /home folder. I -really- needed something in there, and didn't have a recent backup, oops.

    Turns out that recovering my corrupted SD card was trivial...

    The damage seems to be confined to the partition table, the filesystem(s) are intact, so I installed testdisk:
    Code:
    $ sudo yum install testdisk
    It dragged in an additional library (libewf) ..

    I then just ran it as root on the corrupted device:
    Code:
    $ sudo testdisk /dev/mmcblk0
    Testdisk is pretty good, and steps you through the process. I was in a hurry and did not keep any logs of what I did but essentially:
    - I ensured I had the correct device selected (it gives a list if nothing specified on the command line)
    - I told it I was using an Intel/PC partition scheme.
    - I told it to analyse the device.
    - I did a quick search (said 'no' to the Vista question ;-) ) and it found the filesystem on the device, which I selected and proceeded to the next screen.
    - Then I tried the optional deeper search (just in case.. although it found nothing).
    - Finally I selected 'Write', and it re-wrote my partition table.

    After a reboot my homedir was mounting properly again.
    :)

    The moral is; if you do corrupt the device, it can be fixed, there is no need to reformat it..
     
    EasyTarget, Feb 10, 2009
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.