[Miscellaneous Android Development] Deleted member 5186178:
Next open the init.{hardware}.rc from recovery folder, and you have to make some changes to be able to use sdcards and USB mass storage. Typical it looks like this:

import /init.recovery.${ro.hardware}.rc

on early-init
# Apply strict SELinux checking of PROT_EXEC on mmap/mprotect calls.
write /sys/fs/selinux/checkreqprot 0

# Set the security context for the init process.
# This should occur before anything else (e.g. ueventd) is started.
setcon u:r:init:s0

start ueventd
start healthd

on init
export PATH /sbin:/system/bin
export ANDROID_ROOT /system
export ANDROID_DATA /data
export EXTERNAL_STORAGE /sdcard

symlink /system/etc /etc

mkdir /boot
mkdir /recovery
mkdir /sdcard
mkdir /internal_sd
mkdir /external_sd
mkdir /sd-ext
mkdir /datadata
mkdir /emmc
mkdir /system
mkdir /data
mkdir /cache
mount tmpfs tmpfs /tmp

chown root shell /tmp
chmod 0775 /tmp

mkdir /mnt 0775 root system
mkdir /storage 0050 root sdcard_r
mount tmpfs tmpfs /storage mode=0050,uid=0,gid=1028

# See storage config details at http://source.android.com/tech/storage/
mkdir /mnt/shell 0700 shell shell

# Directory for putting things only root should see.
mkdir /mnt/secure 0700 root root

# Create private mountpoint so we can MS_MOVE from staging
mount tmpfs tmpfs /mnt/secure mode=0700,uid=0,gid=0

# Directory for staging bindmounts
mkdir /mnt/secure/staging 0700 root root

# Fuse public mount points.
mkdir /mnt/fuse 0700 root system
mount tmpfs tmpfs /mnt/fuse mode=0775,gid=1000

on fs
mkdir /dev/usb-ffs 0770 shell shell
mkdir /dev/usb-ffs/adb 0770 shell shell
mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000

write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idVendor 18D1
write /sys/class/android_usb/android0/idProduct D001
write /sys/class/android_usb/android0/f_ffs/aliases adb
write /sys/class/android_usb/android0/functions adb
write /sys/class/android_usb/android0/iManufacturer ${ro.product.manufacturer}
write /sys/class/android_usb/android0/iProduct ${ro.product.model}
write /sys/class/android_usb/android0/iSerial ${ro.serialno}

on boot

ifup lo
hostname localhost
domainname localdomain

class_start default

on property:sys.powerctl=*
powerctl ${sys.powerctl}

service ueventd /sbin/ueventd
critical
seclabel u:r:ueventd:s0

service healthd /sbin/healthd -n
critical
seclabel u:r:healthd:s0

service recovery /sbin/recovery
seclabel u:r:recovery:s0

service setup_adbd /sbin/setup_adbd
oneshot

service adbd /sbin/adbd --root_seclabel=u:r:su:s0 --device_banner=recovery
disabled
socket adbd stream 660 system system
seclabel u:r:adbd:s0

service vold /sbin/minivold
socket vold stream 0660 root mount
ioprio be 2
seclabel u:r:recovery:s0

# setup_adbd will start adb once it has checked the keys
on property:service.adb.root=1
write /sys/class/android_usb/android0/enable 0
restart adbd
write /sys/class/android_usb/android0/enable 1

on property:sys.storage.ums_enabled=1
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idProduct D003
write /sys/class/android_usb/android0/functions mass_storage,adb
write /sys/class/android_usb/android0/enable 1

on property:sys.storage.ums_enabled=0
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idProduct D001
write /sys/class/android_usb/android0/functions adb
write /sys/class/android_usb/android0/enable ${service.adb.root}

but it won't mount well both sdcards because it's missing some parts. You can add those either in this file or in a separate init.recovery.{hardware}.rc file placed in /recovery/root folder. For defining sdcards take a look here, but keep in mind that is for Android system fstab, and for recovery things will be slightly different.

Few examples:

1. noemulated:

on early-init
# Apply strict SELinux checking of PROT_EXEC on mmap/mprotect calls.
write /sys/fs/selinux/checkreqprot 0

# Set the security context for the init process.
# This should occur before anything else (e.g. ueventd) is started.
setcon u:r:init:s0

start ueventd
start healthd

on init
export PATH /sbin:/system/bin
export ANDROID_ROOT /system
export ANDROID_DATA /data
[COLOR="Red"]export EXTERNAL_STORAGE /storage/sdcard0
export SECONDARY_STORAGE /storage/sdcard1[/COLOR]

symlink /system/etc /etc

mkdir /boot
mkdir /recovery
mkdir /sdcard
mkdir /internal_sd
mkdir /external_sd
mkdir /sd-ext
mkdir /datadata
[COLOR="Red"]mkdir /sdcard2[/COLOR]
mkdir /system
mkdir /cache
mkdir /data
mount tmpfs tmpfs /tmp

chown root shell /tmp
chmod 0775 /tmp

# See storage config details at http://source.android.com/tech/storage/
mkdir /mnt 0775 root system
mkdir /storage 0050 root sdcard_r
mount tmpfs tmpfs /storage mode=0050,uid=0,gid=1028

[COLOR="Red"]mkdir /mnt/media_rw/sdcard0 0700 media_rw media_rw
mkdir /mnt/media_rw/sdcard1 0700 media_rw media_rw
mkdir /storage/sdcard0 0700 root root
mkdir /storage/sdcard1 0700 root root

symlink /storage/sdcard0 /sdcard
symlink /storage/sdcard0 /mnt/sdcard
symlink /storage/sdcard1 /sdcard2
symlink /storage/sdcard1 /mnt/sdcard2[/COLOR]

mkdir /mnt/shell 0700 shell shell

# Directory for putting things only root should see.
mkdir /mnt/secure 0700 root root

# Create private mountpoint so we can MS_MOVE from staging
mount tmpfs tmpfs /mnt/secure mode=0700,uid=0,gid=0

# Directory for staging bindmounts
mkdir /mnt/secure/staging 0700 root root

# Fuse public mount points.
mkdir /mnt/fuse 0700 root system
mount tmpfs tmpfs /mnt/fuse mode=0775,gid=1000

on fs
mkdir /dev/usb-ffs 0770 shell shell
mkdir /dev/usb-ffs/adb 0770 shell shell
mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000

write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idVendor 18D1
write /sys/class/android_usb/android0/idProduct [COLOR="Red"]D003[/COLOR]
write /sys/class/android_usb/android0/f_ffs/aliases adb
[COLOR="Red"]write /sys/class/android_usb/android0/functions mass_storage,adb[/COLOR]
write /sys/class/android_usb/android0/iManufacturer ${ro.product.manufacturer}
write /sys/class/android_usb/android0/iProduct ${ro.product.model}
write /sys/class/android_usb/android0/iSerial ${ro.serialno}

on boot
ifup lo
hostname localhost
domainname localdomain

class_start default

on property:sys.powerctl=*
powerctl ${sys.powerctl}

service ueventd /sbin/ueventd
critical
seclabel u:r:ueventd:s0

service healthd /sbin/healthd -n
critical
seclabel u:r:healthd:s0

service recovery /sbin/recovery
seclabel u:r:recovery:s0

service setup_adbd /sbin/setup_adbd
oneshot

service adbd /sbin/adbd --root_seclabel=u:r:su:s0 --device_banner=recovery
disabled
socket adbd stream 660 system system
seclabel u:r:adbd:s0

service vold /sbin/minivold
socket vold stream 0660 root mount
ioprio be 2
seclabel u:r:recovery:s0

[COLOR="Red"]# virtual sdcard daemon running as media_rw (1023)
service fuse_sdcard0 /system/bin/sdcard -u 1023 -g 1023 -w 1023 -d /mnt/media_rw/sdcard0 /storage/sdcard0
class late_start
disabled

# virtual sdcard daemon running as media_rw (1023)
service fuse_sdcard1 /system/bin/sdcard -u 1023 -g 1023 -d /mnt/media_rw/sdcard1 /storage/sdcard1
class late_start
disabled[/COLOR]

# setup_adbd will start adb once it has checked the keys
on property:service.adb.root=1
write /sys/class/android_usb/android0/enable 0
restart adbd
write /sys/class/android_usb/android0/enable 1

on property:sys.storage.ums_enabled=1
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idProduct D003
write /sys/class/android_usb/android0/functions mass_storage,adb
write /sys/class/android_usb/android0/enable 1

on property:sys.storage.ums_enabled=0
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idProduct D001
write /sys/class/android_usb/android0/functions adb
write /sys/class/android_usb/android0/enable ${service.adb.root}

2. one emulated:

on early-init
# Apply strict SELinux checking of PROT_EXEC on mmap/mprotect calls.
write /sys/fs/selinux/checkreqprot 0

# Set the security context for the init process.
# This should occur before anything else (e.g. ueventd) is started.
setcon u:r:init:s0

start ueventd
start healthd

on init
export PATH /sbin:/system/bin
export ANDROID_ROOT /system
export ANDROID_DATA /data
[COLOR="Red"]export EXTERNAL_STORAGE /storage/sdcard0[/COLOR]

symlink /system/etc /etc
[COLOR="Red"]symlink /data/media/0 /storage/sdcard0[/COLOR]

mkdir /boot
mkdir /recovery
mkdir /sdcard
mkdir /internal_sd
mkdir /external_sd
mkdir /sd-ext
mkdir /datadata
mkdir /system
mkdir /emmc
mkdir /cache
mkdir /data
mount tmpfs tmpfs /tmp

chown root shell /tmp
chmod 0775 /tmp

# See storage config details at http://source.android.com/tech/storage/
mkdir /mnt 0775 root system
mkdir /storage 0050 root sdcard_r
mount tmpfs tmpfs /storage mode=0050,uid=0,gid=1028

mkdir /mnt/shell 0700 shell shell

# Directory for putting things only root should see.
mkdir /mnt/secure 0700 root root

# Create private mountpoint so we can MS_MOVE from staging
mount tmpfs tmpfs /mnt/secure mode=0700,uid=0,gid=0

# Directory for staging bindmounts
mkdir /mnt/secure/staging 0700 root root

# Fuse public mount points.
mkdir /mnt/fuse 0700 root system
mount tmpfs tmpfs /mnt/fuse mode=0775,gid=1000

on fs
mkdir /dev/usb-ffs 0770 shell shell
mkdir /dev/usb-ffs/adb 0770 shell shell
mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000

write /sys/class/android_usb/android0/enable 0
[COLOR="Red"]write /sys/class/android_usb/android0/idVendor 0BB4
write /sys/class/android_usb/android0/idProduct 0C03[/COLOR]
write /sys/class/android_usb/android0/f_ffs/aliases adb
[COLOR="Red"]write /sys/class/android_usb/android0/functions mass_storage,adb[/COLOR]
write /sys/class/android_usb/android0/iManufacturer ${ro.product.manufacturer}
write /sys/class/android_usb/android0/iProduct ${ro.product.model}
write /sys/class/android_usb/android0/iSerial ${ro.serialno}

on boot
ifup lo
hostname localhost
domainname localdomain

class_start default

on property:sys.powerctl=*
powerctl ${sys.powerctl}

service ueventd /sbin/ueventd
critical
seclabel u:r:ueventd:s0

service healthd /sbin/healthd -n
critical
seclabel u:r:healthd:s0

service recovery /sbin/recovery
seclabel u:r:recovery:s0

service setup_adbd /sbin/setup_adbd
oneshot

service adbd /sbin/adbd --root_seclabel=u:r:su:s0 --device_banner=recovery
disabled
socket adbd stream 660 system system
seclabel u:r:adbd:s0

service vold /sbin/minivold
socket vold stream 0660 root mount
ioprio be 2
seclabel u:r:recovery:s0

# setup_adbd will start adb once it has checked the keys
on property:service.adb.root=1
write /sys/class/android_usb/android0/enable 0
restart adbd
write /sys/class/android_usb/android0/enable 1

on property:sys.storage.ums_enabled=1
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idProduct 0C03
write /sys/class/android_usb/android0/functions mass_storage,adb
write /sys/class/android_usb/android0/enable 1

on property:sys.storage.ums_enabled=0
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idProduct 0C01
write /sys/class/android_usb/android0/functions adb
write /sys/class/android_usb/android0/enable ${service.adb.root}

3. one emulated and one noemulated:

on early-init
# Apply strict SELinux checking of PROT_EXEC on mmap/mprotect calls.
write /sys/fs/selinux/checkreqprot 0

# Set the security context for the init process.
# This should occur before anything else (e.g. ueventd) is started.
setcon u:r:init:s0

start ueventd
start healthd

on init
export PATH /sbin:/system/bin
export ANDROID_ROOT /system
export ANDROID_DATA /data
[COLOR="Red"]export EXTERNAL_STORAGE /storage/sdcard0
export SECONDARY_STORAGE /storage/sdcard1[/COLOR]

symlink /system/etc /etc
[COLOR="Red"]symlink /data/media/0 /storage/sdcard0[/COLOR]

mkdir /boot
mkdir /recovery
mkdir /sdcard
mkdir /internal_sd
mkdir /external_sd
mkdir /sd-ext
[COLOR="Red"]mkdir /sdcard2[/COLOR]
mkdir /datadata
mkdir /system
mkdir /emmc
mkdir /cache
mkdir /data
mount tmpfs tmpfs /tmp

chown root shell /tmp
chmod 0775 /tmp

# See storage config details at http://source.android.com/tech/storage/
mkdir /mnt 0775 root system
mkdir /storage 0050 root sdcard_r
mount tmpfs tmpfs /storage mode=0050,uid=0,gid=1028
[COLOR="Red"]mkdir /mnt/media_rw/sdcard1 0700 media_rw media_rw
mkdir /mnt/shell 0700 shell shell
mkdir /storage/sdcard1 0700 root root
symlink /storage/sdcard1 /mnt/sdcard2[/COLOR]

# Directory for putting things only root should see.
mkdir /mnt/secure 0700 root root

# Create private mountpoint so we can MS_MOVE from staging
mount tmpfs tmpfs /mnt/secure mode=0700,uid=0,gid=0

# Directory for staging bindmounts
mkdir /mnt/secure/staging 0700 root root

# Fuse public mount points.
mkdir /mnt/fuse 0700 root system
mount tmpfs tmpfs /mnt/fuse mode=0775,gid=1000

on fs
mkdir /dev/usb-ffs 0770 shell shell
mkdir /dev/usb-ffs/adb 0770 shell shell
mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000

write /sys/class/android_usb/android0/enable 0
[COLOR="Red"]write /sys/class/android_usb/android0/idVendor 0BB4
write /sys/class/android_usb/android0/idProduct 0C03[/COLOR]
write /sys/class/android_usb/android0/f_ffs/aliases adb
[COLOR="Red"]write /sys/class/android_usb/android0/functions mass_storage,adb[/COLOR]
write /sys/class/android_usb/android0/iManufacturer ${ro.product.manufacturer}
write /sys/class/android_usb/android0/iProduct ${ro.product.model}
write /sys/class/android_usb/android0/iSerial ${ro.serialno}

on boot
ifup lo
hostname localhost
domainname localdomain
class_start default

on property:sys.powerctl=*
powerctl ${sys.powerctl}

service ueventd /sbin/ueventd
critical
seclabel u:r:ueventd:s0

service healthd /sbin/healthd -n
critical
seclabel u:r:healthd:s0

service recovery /sbin/recovery
seclabel u:r:recovery:s0

service setup_adbd /sbin/setup_adbd
oneshot

service adbd /sbin/adbd --root_seclabel=u:r:su:s0 --device_banner=recovery
disabled
socket adbd stream 660 system system
seclabel u:r:adbd:s0

service vold /sbin/minivold
socket vold stream 0660 root mount
ioprio be 2
seclabel u:r:recovery:s0

[COLOR="Red"]
# virtual sdcard daemon running as media_rw (1023)
service fuse_sdcard1 /system/bin/sdcard -u 1023 -g 1023 -w 1023 -d /mnt/media_rw/sdcard1 /storage/sdcard1
class late_start
disabled[/COLOR]

# setup_adbd will start adb once it has checked the keys
on property:service.adb.root=1
write /sys/class/android_usb/android0/enable 0
restart adbd
write /sys/class/android_usb/android0/enable 1

on property:sys.storage.ums_enabled=1
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idProduct 0C03
write /sys/class/android_usb/android0/functions mass_storage,adb
write /sys/class/android_usb/android0/enable 1

on property:sys.storage.ums_enabled=0
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idProduct 0C01
write /sys/class/android_usb/android0/functions adb
write /sys/class/android_usb/android0/enable ${service.adb.root}

As you can see, for external sdcard (/storage/sdcard1), when it exists, the read write permissions include also "other/world" (-w 1023), but for internal sdcard, either emulated or not, only user and group have permissions.

If you want to use a separate init.recovery.{hardware}.rc file, just copy the extra stuff from these init.{hardware}.rc examples compared with default init.rc and keep same triggers (on init, on fs, on boot, etc.). Example for both sdcards noemulated, the init.recovery.{hardware}.rc file could look like this:

on init
export EXTERNAL_STORAGE /storage/sdcard0
export SECONDARY_STORAGE /storage/sdcard1

mkdir /sdcard2

# See storage config details at http://source.android.com/tech/storage/

mkdir /mnt/media_rw/sdcard0 0700 media_rw media_rw
mkdir /mnt/media_rw/sdcard1 0700 media_rw media_rw
mkdir /storage/sdcard0 0700 root root
mkdir /storage/sdcard1 0700 root root

symlink /storage/sdcard0 /sdcard
symlink /storage/sdcard0 /mnt/sdcard
symlink /storage/sdcard1 /sdcard2
symlink /storage/sdcard1 /mnt/sdcard2

on fs

write /sys/class/android_usb/android0/functions mass_storage,adb

on boot

# virtual sdcard daemon running as media_rw (1023)
service fuse_sdcard0 /system/bin/sdcard -u 1023 -g 1023 -w 1023 -d /mnt/media_rw/sdcard0 /storage/sdcard0
class late_start
disabled

# virtual sdcard daemon running as media_rw (1023)
service fuse_sdcard1 /system/bin/sdcard -u 1023 -g 1023 -d /mnt/media_rw/sdcard1 /storage/sdcard1
class late_start
disabled

One other thing to check is your device "idVendor" and "idProduct":

write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idVendor 18D1
write /sys/class/android_usb/android0/idProduct [COLOR="Red"]D003[/COLOR]
write /sys/class/android_usb/android0/f_ffs/aliases adb
[COLOR="Red"]write /sys/class/android_usb/android0/functions mass_storage,adb[/COLOR]

Initial was:

write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idVendor 18D1
write /sys/class/android_usb/android0/idProduct D001
write /sys/class/android_usb/android0/f_ffs/aliases adb
write /sys/class/android_usb/android0/functions adb

but I changed that to activate mass storage function from start. That is up to you, but in any case you need to check those numbers. The "18D1" and "D001", "D003" are ok if you have google usb drivers installed, but also you can use specific vendor and product Ids. These can be found in boot unpacked ramdisk, in init.usb.rc file.