[Android Q&A, Help & Troubleshooting] gaixixon:
Hi.. I need to run a script AFTER the sdcard is mounted. However, it seems that my script is always run before or when the sdcard is not mounted yet. My phone is rooted already.

This is my script, located at /etc/init.d/myscript.sh

#!system/bin/sh
#this is to show that my script is run properly as root.
chmod 777 /cache
mkdir /cache/foo
### and it runs without any problem. So far so good.
#now I want to check if there is file "foo.img" at my external sd card "/storage/0764-8617"
#of course, there IS the file at /storage/0764-8617
#i tried all "wait", "loop" below to make sure sdcard is loaded before the "if" block below..
wait /dev/block/loop1
count=10
until [ -d /storage/0764-8617 ] || [ $count -lt 1 ];
do
sleep 1
count=$((count-1));
done;
sleep 10
if [ -f /storage/0764-8617/foo.img ] ; then
echo "File existed
else
echo "File not found"
fi
#but it always spits out that "File not found!"

How should I fix this code so that the script can always find /storage/0764-8617/foo.img

this is what mounted in my phone:

cat /proc/mounts

rootfs / rootfs rw,seclabel 0 0

tmpfs /tmp tmpfs rw,seclabel,relatime 0 0

proc /proc proc rw,relatime 0 0

tmpfs /proc/cmdline tmpfs rw,seclabel,relatime 0 0

tmpfs /dev tmpfs rw,seclabel,nosuid,relatime,mode=755 0 0

devpts /dev/pts devpts rw,seclabel,relatime,mode=600 0 0

none /dev/cpuctl cgroup rw,relatime,cpu 0 0

adb /dev/usb-ffs/adb functionfs rw,relatime 0 0

sysfs /sys sysfs rw,seclabel,relatime 0 0

selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0

debugfs /sys/kernel/debug debugfs rw,seclabel,relatime 0 0

none /sys/fs/cgroup tmpfs rw,seclabel,relatime,mode=750,gid=1000 0 0

none /acct cgroup rw,relatime,cpuacct 0 0

tmpfs /mnt tmpfs rw,seclabel,relatime,mode=755,gid=1000 0 0

/dev/fuse /mnt/runtime/default/emulated fuse rw,nosuid,nodev,noexec,noatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0

/dev/fuse /mnt/runtime/read/emulated fuse rw,nosuid,nodev,noexec,noatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0

/dev/fuse /mnt/runtime/write/emulated fuse rw,nosuid,nodev,noexec,noatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0

/dev/block/vold/public:179,129 /mnt/media_rw/0764-8617 vfat rw,dirsync,nosuid,nodev,noexec,noatime,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0

/dev/block/vold/public:179,129 /mnt/secure/asec vfat rw,dirsync,nosuid,nodev,noexec,noatime,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0

/dev/fuse /mnt/runtime/default/0764-8617 fuse rw,nosuid,nodev,noexec,noatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0

/dev/fuse /mnt/runtime/read/0764-8617 fuse rw,nosuid,nodev,noexec,noatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0

/dev/fuse /mnt/runtime/write/0764-8617 fuse rw,nosuid,nodev,noexec,noatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0

/dev/block/dm-0 /mnt/asec/com.UCMobile.intl-2 ext4 ro,dirsync,seclabel,nosuid,nodev,noatime 0 0

tmpfs /storage/emulated tmpfs rw,seclabel,relatime,mode=755,uid=1023,gid=1023 0 0

/emmc@android /system ext4 ro,seclabel,relatime,data=ordered 0 0

/emmc@cache /cache ext4 rw,seclabel,nosuid,nodev,noatime,discard,noauto_da_alloc,data=ordered 0 0

/dev/block/loop101 /cache/QQdata ext4 rw,seclabel,relatime,data=ordered 0 0

/emmc@usrdata /data ext4 rw,seclabel,nosuid,nodev,noatime,discard,noauto_da_alloc,resuid=10010,data=ordered 0 0

/emmc@cache /data/sdext2 ext4 rw,seclabel,nosuid,nodev,noatime,discard,noauto_da_alloc,data=ordered 0 0

/emmc@protect_f /protect_f ext4 rw,seclabel,nosuid,nodev,noatime,nodelalloc,noauto_da_alloc,commit=1,data=ordered 0 0

/emmc@protect_s /protect_s ext4 rw,seclabel,nosuid,nodev,noatime,nodelalloc,noauto_da_alloc,commit=1,data=ordered 0 0

/emmc@cust /cust ext4 rw,seclabel,nosuid,nodev,noatime,discard,noauto_da_alloc,data=ordered 0 0

/emmc@persist /persist ext4 rw,seclabel,nosuid,nodev,noatime,discard,noauto_da_alloc,data=ordered 0 0

/emmc@persist_lg /persist-lg ext4 rw,seclabel,nosuid,nodev,noatime,discard,noauto_da_alloc,data=ordered 0 0

/emmc@mpt /mpt ext4 rw,seclabel,nosuid,nodev,noatime,discard,noauto_da_alloc,data=ordered 0 0

tmpfs /storage tmpfs rw,seclabel,relatime,mode=755,gid=1000 0 0

/dev/fuse /storage/emulated fuse rw,nosuid,nodev,noexec,noatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0

/dev/fuse /storage/0764-8617 fuse rw,nosuid,nodev,noexec,noatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0

/dev/block/loop1 /su ext4 rw,seclabel,noatime,data=ordered 0 0

p/s: I have found a way quite simple, but crazy solution to my problem by directly check and wait for the file and IT WORKS.

until [ [COLOR="Red"]-f /storage/0764-8617/foo.img[/COLOR]] || [ $count -lt 1 ];

but my question is still open: I link some app from foo.img, (that is mounted to /dev/block/loop1), to /data/app but it is not shown in the app drawer, even after reboot. However if I put the image in internal storage, then the app can be shown.