Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    Permanently reassigning MyDocs to SD card

    Reply
    beermad | # 1 | 2011-04-20, 12:06 | Report

    Possible?

    I seem to have a problem with the MyDocs filesystem, so I'd like to use an SD card instead.

    I know I could play around with mountpoints with an upstart script, but it would be infinitely better to somehow persuade the startup to assign and mount it in the first place.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    iDont | # 2 | 2011-04-20, 13:23 | Report

    I've been running my device with MyDocs on a uSD card for a few months now. How to do it:

    -Make sure the original MyDocs partition won't be mounted at boot by either removing the partition or marking it as being a non-FAT partition by executing:
    Code:
    sfdisk -c /dev/mmcblk0 26
    *26 is a currently unused partition type

    -Add below the line containing "-f /usr/lib/genfstab.awk > $tmp_fstab" in /etc/event.d/rcS-late:
    Code:
    echo "/dev/mmcblk1p1 /home/user/MyDocs vfat $fat_opts 0 0" >> $tmp_fstab
    -Add above the line containing "# We can safely continue booting now." in the same file
    Code:
    /bin/mount /home/user/MyDocs
    -Make the last lines of /usr/sbin/osso-usb-mass-storage-enable.sh look like this:
    Code:
    if [ $# = 1 ]; then
        DEV=/dev/mmcblk1p1
        STR=`cat $LUN0`
        if [ "x$STR" = "x" ]; then
    #       echo $1 > $LUN0
            echo $DEV > $LUN0
        else
            echo $1 > $LUN1
        fi
    fi
    
    exit 0
    -And do the same for the last lines of /usr/sbin/osso-usb-mass-storage-disable.sh
    Code:
    mount /home/user/MyDocs
    exit 0
    That should do the trick
    Change mmcblk1p1 in the pieces of code to the device name of the FAT partition you want to use as your new MyDocs.

    Credits: http://talk.maemo.org/showthread.php...359#post425359

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by iDont; 2011-04-25 at 18:02.
    The Following 4 Users Say Thank You to iDont For This Useful Post:
    beermad, iceskateclog, reinob, vi_

     
    beermad | # 3 | 2011-04-25, 14:47 | Report

    Oh sod! I think I killed it.

    I don't know what went wrong there, but now my N900 just keeps showing the white "NOKIA" screen, going blank and then repeating itself.

    Plugging a USB cable in while it's completely off shows it attaching to the USB port, then almost immediately disconnecting. And repeating itself.

    I fear a re-flash is going to be needed :-(

    Edit | Forward | Quote | Quick Reply | Thanks

     
    iDont | # 4 | 2011-04-25, 18:02 | Report

    Originally Posted by beermad View Post
    I don't know what went wrong there, but now my N900 just keeps showing the white "NOKIA" screen, going blank and then repeating itself.
    This can happen when Maemo can't mount /home. I've been thinking what could've gone wrong, and it seems that I've made a very unfortunate error in my post.

    Nokia has made Maemo in such a way that it recreates fstab every time it gets booted. The first partition that identifies itself as FAT is used as MyDocs and the first one to identify itself as a Linux native partition is used as /home.

    By executing sfdisk -c /dev/mmcblk0 1 83 MyDocs won't get mounted as it identifies itself as not being FAT anymore, but rather as a Linux native partition.
    Now Maemo tries to mount it as /home as mmcblk0p1 gets checked earlier than mmcblk0p2. Of course, the content of /home isn't on mmcblk0p1, causing Maemo to get into a reboot loop.

    I didn't notice the error as I've partitioned my eMMC differently and changed rcS-late to recreate fstab in a static way.

    Originally Posted by beermad View Post
    I fear a re-flash is going to be needed :-(
    I'm afraid a reflash is required. Flashing only the rootfs should be enough to get your device working again (you won't lose any contact/personal data). Applications will need to be reinstalled probably though.

    I've edited my post above to set mmcblk0p1 to a different partition type than 83 to make sure this won't happen to someone else.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    beermad | # 5 | 2011-04-25, 18:09 | Report

    A re-flash was indeed needed. Messy and not fun, but at least I'm (I think) back where I started.

    I think I'll wimp out on trying this again and see if I can find another way of achieving what I need (I don't doubt iDont's correction, but cowardice has taken over)...

    [edit] Thinking about it, I've got an idea how this could be achieved in a way that shouldn't involve any risk. I'll report back when I've had time to test it out (might take a couple of days, as I've got some website commissions to work on).

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by beermad; 2011-04-26 at 09:15.

     
    beermad | # 6 | 2011-04-26, 15:53 | Report

    OK, here's a way to achieve this. Admittedly a bit of a cludge, but it has the advantage of failing non-fatally.

    One limitation is that it won't work if any processes open any files on either the SD card or MyDocs before it's run, as that will prevent the filesystem from being unmounted. As an upstart script it's probably not great, but it's working for me...

    If it fails, it tries to restore the system to as close as possible to its original state (eg, re-mounting the original MyDocs partition).

    If you've got processes that need to wait for the new MyDocs partition to be ready (for example my MySQL server, whose data files are on MyDocs) this script emits MYDOCS_REPLACED when it's successfully done its job, so you can change the upstart file's "start on" stanza to:
    Code:
    start on MYDOCS_REPLACED
    Upstart script replaceMyDocs
    Code:
    description "unmounts normal MyDocs filesystem and replaces it with the SD card"
    
    # Runs afer rcS-late has mounted everything
    start on MOUNTS_OK
    
    console none
    
    script
    
            # Alter the next six lines if necessary for your system
            MYDOCS_DEVICE=/dev/mmcblk0p1
            SD_DEVICE=/dev/mmcblk1p1
            MYDOCS_MOUNTPOINT=/home/user/MyDocs
            MYDOCS_FILESYSTEM=vfat
            SD_MOUNTPOINT=/media/mmc1
            SD_FILESYSTEM=vfat
    
            # Check that MyDocs hasn't already been replaced
            if [ ! -z "`mount | grep $MYDOCS_MOUNTPOINT | grep $SD_DEVICE`" ]
            then
                    # Already mounted.
                    normal exit 0
            fi
            # It can take a few seconds for MyDocs to actually mount after rsS-late
            # has finished, so we'll watch for it
            i=0
            while [ -z "`mount | grep $MYDOCS_MOUNTPOINT`" -o -z "`mount | grep $SD_MOUNTPOINT`" ]
            do
                    i=$(($i+1))
                    if [ $i -eq 120 ]
                    then
                            # If it hasn't mounted within two minutes, something's gone
                            # horribly wrong, so we may as well give up
                            normal exit 0
                    fi
                    sleep 1
            done
            # Get mount options from the fstab file
            OPTS=`grep $MYDOCS_MOUNTPOINT /etc/fstab | awk ' { print $4 } '`
    
            # Unmount the SD card
            umount $SD_MOUNTPOINT
            # Check it unmouted OK
            if [ $? -eq 0 ]
            then
                    # Unmount the MyDocs filesystem
                    umount $MYDOCS_MOUNTPOINT
                    # Check it unmounted OK
                    if [ $? -eq 0 ]
                    then
                            # Mount the SD on MyDocs
                            mount $SD_DEVICE -t $SD_FILESYSTEM -o "$OPTS" $MYDOCS_MOUNTPOINT
                            if [ $? -ne 0 ]
                            then
                                    # Failed to mount the SD so fall back to original
                                    mount $MYDOCS_DEVICE -t $MYDOCS_FILESYSTEM -o "$OPTS" $MYDOCS_MOUNTPOINT
                            else
                                    initctl emit MYDOCS_REPLACED
                            fi
                    fi
            fi
    
    end script
    normal exit 0

    Edit | Forward | Quote | Quick Reply | Thanks

     
    beermad | # 7 | 2011-05-06, 15:47 | Report

    Updated version of upstart script. This allows use of proper Linux filesystems.

    Code:
    description "unmounts normal MyDocs filesystem and replaces it with the SD card"
    
    # Runs afer rcS-late has mounted everything
    start on MOUNTS_OK
    
    console none
    
    script
    
            MYDOCS_DEVICE=/dev/mmcblk0p1
            SD_DEVICE=/dev/mmcblk1p1
            MYDOCS_MOUNTPOINT=/home/user/MyDocs
            MYDOCS_FILESYSTEM=vfat
            SD_MOUNTPOINT=/media/mmc1
            SD_FILESYSTEM=ext3
    
            # Check that MyDocs hasn't already been replaced
            if [ ! -z "`mount | grep $MYDOCS_MOUNTPOINT | grep $SD_DEVICE`" ]
            then
                    # Already mounted.
                    normal exit 0
            fi
            # It can take a few seconds for MyDocs to actually mount after rsS-late
            # has finished, so we'll watch for it
            i=0
            if [ $SD_FILESYSTEM == "vfat" ]
            then
                   # The SD will auto-mount if if's vfat, but won't otherwise. So if it's vfat
                   # we want to wait until it's been mounted so we don't interrupt
                    while [ "`mount | grep $SD_MOUNTPOINT`" ]
                    do
                            i=$(($i+1))
                            if [ $i -eq 120 ]
                            then
                                    # If it hasn't mounted within two minutes, something's gone
                                    # horribly wrong, so we may as well give up
                                    normal exit 0
                            fi
                            sleep 1
                    done
            fi
            i=0
            while [ -z "`mount | grep $MYDOCS_MOUNTPOINT`" ]
            do
                    i=$(($i+1))
                    if [ $i -eq 120 ]
                    then
                            # If it hasn't mounted within two minutes, something's gone
                            # horribly wrong, so we may as well give up
                            normal exit 0
                    fi
                    sleep 1
            done
            if [ $SD_FILESYSTEM == "vfat" ]
            then
                    # Get mount options from the fstab file
                    OPTS=`grep $MYDOCS_MOUNTPOINT /etc/fstab | awk ' { print $4 } '`
            else
                    # We don't want the mount options from fstab, as some are invalid for
                    # other filesystems.
                    OPTS="noauto,nodev,nosuid,noatime,nodiratime"
            fi
    
            if [ $SD_FILESYSTEM == "vfat" ]
            then
                    # Unmount the SD card
                    umount $SD_MOUNTPOINT
                    # Check it unmouted OK
                    if [ $? -ne 0 ]
                    then
                            exit
                    fi
            fi
            # Unmount the MyDocs filesystem
            umount $MYDOCS_MOUNTPOINT
            # Check it unmounted OK
            if [ $? -eq 0 ]
            then
                    # Mount the SD on MyDocs
                    mount $SD_DEVICE -t $SD_FILESYSTEM -o "$OPTS" $MYDOCS_MOUNTPOINT
                    if [ $? -ne 0 ]
                    then
                            # Failed to mount the SD so fall back to original
                            mount $MYDOCS_DEVICE -t $MYDOCS_FILESYSTEM -o "$OPTS" $MYDOCS_MOUNTPOINT
                    else
                            initctl emit MYDOCS_REPLACED
                    fi
            fi
    
    end script
    normal exit 0

    Edit | Forward | Quote | Quick Reply | Thanks

     
    iceskateclog | # 8 | 2014-06-11, 12:41 | Report

    Any idea how to handle USB Mass Storage mode in elegant way?

    Right now I just hack around /usr/sbin/osso-usb-mass-storage-enable.sh and /usr/sbin/osso-usb-mass-storage-disable.sh with umount and mount. My fstab is static

    Code:
    if [ $# = 1 ]; then
        umount /home/user/MyDocs
        STR=`cat $LUN0`
        if [ "x$STR" = "x" ]; then
           echo $1 > $LUN0
        else
            echo $1 > $LUN1
        fi
    fi
    
    exit 0
    Code:
    mount /home/user/MyDocs
    exit 0
    A bit different than in post #2, I believe ke-recv changed since then. Without "umount /home/user/MyDocs", my sdcard which is in /dev/mmcblk0p1 (because of SLOT_NUM exchange in /lib/udev/mmc_id) gets mounted on PC and stays mounted on N900 side.

    I guess this is something to do with internal and external card name, but can't find where and who is passing what ;]

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by iceskateclog; 2014-06-11 at 12:48.

     
    michaaa62 | # 9 | 2014-06-11, 16:33 | Report

    Never tried it, never needed to, but:
    Did you try to simply symlink the external card to MyDocs folder?

    Edit | Forward | Quote | Quick Reply | Thanks

     
    iceskateclog | # 10 | 2014-06-12, 07:53 | Report

    The "problem" is that my eMMC throws I/O errors and I use SDCARD as /home and MyDocs replacement.

    /home automatically works correctly with SLOT_NUM /lib/udev/mmc_id trick as /dev/mmcblk0p2, but MyDocs /dev/mmcblk0p1 still gets detected as SDCARD during USB Mass Storage mode. Hence doesn't autounmount from N900

    Edit | Forward | Quote | Quick Reply | Thanks

     
vBulletin® Version 3.8.8
Normal Logout