OpenWrt Forum Archive

Topic: booting SD card as root 8.09.1 wrt54gl

The content of this topic has been archived on 21 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello everyone.
     I'm new to openwrt and am having some trouble. I've managed to get the sd card to mount to /mnt at boot. I did the following packagesonexternalmediahowto but every time I rebooted it didn't load. I read in the forums to add "echo 0x9c > /proc/diag/gpiomask" to /etc/init.d/boot, make a file in /etc/modules.d with mmc in it and added the following to my fstab.
config mount
        option target   /mnt/
        option device   /dev/mmc/disc0/part1
        option fstype   ext3
        option options  defaults
        option enabled  1

Now when I reboot i have the sd card on /mnt.

Here's my df -h

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    1.6M      1.6M         0 100% /
/dev/root                 1.6M      1.6M         0 100% /rom
tmpfs                     7.0M     56.0k      6.9M   1% /tmp
/dev/mtdblock/4           1.7M    888.0k    840.0k  51% /jffs
mini_fo:/jffs             1.6M      1.6M         0 100% /
/dev/mmc/disc0/part1      1.8G     40.8M      1.7G   2% /mnt

my /sbin/init

#!/bin/sh                                                                                 
. /etc/functions.sh                                                                       
config_load "bootfromexternalmedia"                                                       
local section="cfg1"                                                                       
config_get      "target"   "$section" "target"                                             
config_get      "device"   "$section" "device"                                             
config_get      "gpiomask" "$section" "gpiomask"                                           
config_get      "modules"  "$section" "modules"                                           
config_get_bool "enabled"  "$section" "enabled" '1'                                       
[ "$enabled" -gt 0 ] && {                                                                 
       [ -n "$gpiomask" ] && {                                                             
                       echo "$gpiomask" > /proc/diag/gpiomask                             
                               }                                                           
                                       for module in $modules; do {                       
                                                       insmod $module                     
                                                               }; done                     
                                                        sleep 5s                           
                                              mount -o rw "$device" $target               
                                          [ -x $target/sbin/init ] && {                   
                                                     . /bin/firstboot                     
                                             pivot $target $target                         
                                                       }                                   
                                                      }                                   
                                                   exec /bin/busybox init                 


my /etc/config/bootfromexternalmedia

config bootfromexternalmedia
        option target   '/mnt/'
        option device   '/dev/mmc/disc0/part1'
        option gpiomask '0x9c'
        option modules  'mmc jbd ext3'
        option enabled  '1'

Any help would be very much appreciated!

(Last edited by vio on 25 Oct 2009, 06:35)

you need to change
local section="cfg1" 
in
local section="$CONFIG_SECTIONS"
then it should work, it's possible that you'll have to increase also the wait time before mount
Bellow is an more advanced script based on the above:

#!/bin/ash
#set -x
log(){
        echo "NEW INIT: $*"
}
run_init(){
        log "Run busybox init"
        exec /bin/busybox init
}

log "START"
. /etc/functions.sh
log "Load Config"
config_load "bootfromusb"
[ "$?" != "0" ] && {
        log "Failed to load config"
        run_init
}
local section="$CONFIG_SECTIONS"

log "Get Settings"
config_get      "target"   "$section" "target"
config_get      "device"   "$section" "device"
config_get      "gpiomask" "$section" "gpiomask"
config_get      "modules"  "$section" "modules"
config_get_bool "enabled"  "$section" "enabled" '0'
log "Settings loaded: target=$target device=$device gpiomask=$gpiomask"
log "modules: $modules"
log "Boot from stick: $enabled"
[ "$enabled" -gt 0 ] && {
        log "true"
        [ -z "$target" -o -z "$device" ] && {
                log "Undefined device or mount point"
                run_init
        }
        [ -n "$gpiomask" ] && {
                echo "$gpiomask" > /proc/diag/gpiomask
        }

        log "Load modules: $modules"
        for module in $modules; do {
                echo -ne "$module\t"
                insmod $module
        }; done
        echo ""
        sleep 5

        log "Mount: $device on: $target"
        for i in `seq 1 18`; do
                if mount -o rw -t ext3 "$device" $target; then
                        break
                else
                        log "FAILED to mount $device"
                        sleep 10
                fi
        done

        [ -x $target/sbin/init ] && {
                log "Run firstboot"
                . $target/bin/firstboot
                log "Pivot Root"
                #$target/sbin/pivot_root $target $target
                #call func pivot from firstboot
                pivot $target $target
        }
}
log "Everything OK"
run_init
log "DONE"

Thank you! That fixed it. I didn't use the script, I wasn't sure if it needed modification.  I just changed the "cfg1" to "$CONFIG_SECTIONS" and it started up from the sd card.

The discussion might have continued from here.