Summary

After installing the SDCard mod for WRT54GL, the following mounts the SDcard as root. The document is based on sd card mod with openwrt with some modifications and additions.

Setup

Moving mounting the card:

opkg update
opkg install ext2 e2fstools
insmod mmc
echo "0x9c" >/proc/diag/gpiomask
mkfs.ext2 /dev/mmc/disc0/part1
mkdir -p /mnt
mount -t ext2 -o noatime /dev/mmc/disc0/part1 /mnt
grep /mnt /proc/mounts

Moving the contents over to the card:

mkdir /tmp/orig
mount -o bind / /tmp/orig  
tar -c -C /tmp/orig -f - . | tar -xv -C /mnt -f -
umount /tmp/orig
rmdir /tmp/orig
rm -r /mnt/etc/* 
umount /mnt

bootext

Add a new file called /etc/init.d/bootext containing:

bootext
#!/bin/sh /etc/rc.common
 
START=11
STOP=91
 
bootext_cleanup() { # [cleanup_level]
[ "$1" -ge 3 ] && grep -q '^[^ ]* /rom ' /proc/mounts && mount -o move /rom $putold/rom
[ "$1" -ge 2 ] && { . $putold/bin/firstboot ; pivot $putold $target ; }
[ "$1" -ge 1 ] && umount -l $target/etc
return 0
}
 
bootext_fail() { # <error_message> [cleanup_level]
echo "$1" >&2
[ ! "$2" ] || bootext_cleanup $2
exit 1
}
 
bootext_quit() { # <message>
echo "$1" >&2
exit 0
}
 
bootext_start() {
! grep -q "^$device / " /proc/mounts || bootext_quit "$name already on /"
 
if ! grep -q "^$device $target " /proc/mounts
then
! grep -q "^$device " /proc/mounts || bootext_fail "$name already mounted"
 
for module in $modules
do
if ! grep -q "^$module " /proc/modules
then
[ $module != mmc ] || [ ! "$gpiomask" ] || echo "$gpiomask" > /proc/diag/gpiomask || bootext_fail "could not set gpiomask"
insmod $module || bootext_fail "could not insert $module module"
fi
done
 
while [ ! -b $device ]
do
[ "$waitdev" -gt 0 ] || bootext_fail "$device does not exist"
waitdev=$(( $waitdev - 1 ))
sleep 1
done
 
[ -d $target ] || mkdir $target || bootext_fail "could not create mountpoint $target"
mount ${filesys:+-t $filesys} ${mountopt:+-o $mountopt} $device $target || bootext_fail "could not mount $name on $target"
fi
 
[ -d $target$putold ] || mkdir $target$putold || bootext_fail "could not create mountpoint $putold"
[ -d $target/etc ] || mkdir $target/etc || bootext_fail "could not create mountpoint /etc"
mount -o bind /etc $target/etc || bootext_fail "could not bind mount /etc"
 
. /bin/firstboot
pivot $target $putold || bootext_fail "could not pivot to $target" 1
 
! grep -q "^[^ ]* $putold/rom " /proc/mounts || { [ -d /rom ] || mkdir /rom && mount -o move $putold/rom /rom ; }
 
return 0
}
 
bootext_stop() {
grep -q "^$device / " /proc/mounts || bootext_quit "$name not on /"
 
bootext_cleanup 999
}
 
bootext_config() { # <section> <action>
local section=$1
local action=$2
local enabled device name target putold modules gpiomask waitdev filesys mountopt
 
config_get_bool enabled $section enabled 1
[ "$enabled" -gt 0 ] || return 0
config_get device $section device
[ "$device" ] || bootext_fail "external boot device not configured"
config_get name $section name
config_get target $section target
config_get putold $section putold
config_get modules $section modules
config_get gpiomask $section gpiomask
config_get waitdev $section waitdev
config_get filesys $section filesys
config_get mountopt $section mountopt
 
[ "$name" ] || name="$device"
[ "$putold" ] || putold="${target:-/old}"
[ "$target" ] || target="/${filesys:-new}"
 
bootext_$action
}
 
start() {
config_load bootfromexternalmedia
config_foreach bootext_config bootfromexternalmedia start
}
 
stop() {
config_load bootfromexternalmedia
config_foreach bootext_config bootfromexternalmedia stop
}

bootfromexternalmedia

Create a new file /etc/config/bootfromexternalmedia:

bootfromexternalmedia
config bootfromexternalmedia
        option enabled  '1'
        option device   '/dev/mmc/disc0/part1'
        option name     'mmc'
        option target   '/mnt'
        option putold   '/mnt'
        option modules  'mmc ext2'
        option gpiomask '0x9c'
        option waitdev  '0'
        option filesys  'ext2'
        option mountopt 'noatime'

Testing

Isssue:

/etc/init.d/bootext

and if you get:

Filesystem           1k-blocks      Used Available Use% Mounted on
rootfs                 1889792     13504   1876288   1% /
/dev/root                 1600      1600         0 100% /rom
tmpfs                     7164       716      6448  10% /tmp
/dev/mtdblock/4           1728       788       940  46% /jffs
mini_fo:/jffs             1600      1600         0 100% /mnt
/dev/mmc/disc0/part1   1889792     13504   1876288   1% /
mini_fo:/jffs             1600      1600         0 100% /etc

you are good to go. To make the changes persist reboots:

/etc/init.d/bootext enable
reboot

hardware/openwrt/mmc.txt ยท Last modified: 2022/04/19 08:28 by 127.0.0.1

Wizardry and Steamworks

© 2025 Wizardry and Steamworks

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.