#!/bin/sh
#
# Author: Daniel Steen
# Email: daniel@steen-family.com # but your better off writing to:
# oe@handhelds.org
#
# Script to setup a Zaurus system to boot from the sd card (/mnt/card).
#
# I don't really know very much about shell scripting so this script is not
# very robust. Any suggestions would be most welcome.
# set up our variables
NEWROOT=/mnt/card
#DEVICE=/dev/mmcda1 # this is the future
# remount $NEWROOT with the sync option. This makes everything very slow,
# but it prevents corruption. if you want to risk it but speed things up alot
# comment this out
mount -o remount,sync $NEWROOT
# copy the files
echo "Copying /bin"
cp -a /bin /$NEWROOT/
echo "Copying /etc"
cp -a /etc /$NEWROOT/
echo "Copying /home"
cp -a /home /$NEWROOT/
echo "Copying /lib"
cp -a /lib /$NEWROOT/
echo "Copying /opt"
cp -a /opt /$NEWROOT/
# if you want to link the root folder comment in the next 2 lines this will
# speed up writes to your home folder because it is on internal memory,
# however you are now dependent on internal memory. This was more of an
# issue for pre-3.5.1 releases as 3.5.1 runs much faster.
echo "Copying /root"
cp -a /root /$NEWROOT/
echo "Copying /sbin"
cp -a /sbin /$NEWROOT/
echo "Copying /tmp"
cp -a /tmp /$NEWROOT/
echo "Copying /usr"
cp -a /usr /$NEWROOT/
echo "Copying /boot"
cp -a /boot /$NEWROOT/
echo "Copying /sys"
cp -a /sys /$NEWROOT/
# /dev is a special case and only some files are copied
mkdir /$NEWROOT/dev
cp -a /dev/hda /dev/mem /dev/tty /dev/hda1 /dev/hda2 /dev/hda3 /dev/hda4 /dev/hda5 /dev/hda6 /dev/hda7 /dev/hda8 /dev/hda9 /dev/kmem /dev/mtd0 /dev/mtd1 /dev/mtd2 /dev/mtd3 /dev/mtd4 /dev/mtd5 /dev/mtd6 /dev/mtd7 /dev/null /dev/ram0 /dev/ram1 /dev/ram2 /dev/ram3 /dev/tty0 /dev/tty1 /dev/tty2 /dev/tty3 /dev/tty4 /dev/tty5 /dev/tty6 /dev/tty7 /dev/tty8 /dev/zero /dev/console /dev/hda10 /dev/hda11 /dev/hda12 /dev/hda13 /dev/hda14 /dev/hda15 /dev/hda16 /dev/hda17 /dev/hda18 /dev/hda19 /dev/ttyS0 /dev/initctl /dev/apm_bios /dev/mtdblock0 /dev/mtdblock1 /dev/mtdblock2 /dev/mtdblock3 /dev/mtdblock4 /dev/mtdblock5 /dev/mtdblock6 /dev/mtdblock7 /dev/ttySA0 /$NEWROOT/dev
# this needs to be changed or opie does some funny things
cp /dev/mmcda1 /$NEWROOT/dev/mmsda1
# If you want to link the root folder uncomment the next two lines
#echo "Linking /root"
#ln -s /mnt/root/root /$NEWROOT/root
# make the folders that we don't copy
echo "Creating folders"
mkdir /$NEWROOT/var
mkdir /$NEWROOT/proc
mkdir /$NEWROOT/mnt
mkdir /$NEWROOT/mnt/root
mkdir /$NEWROOT/mnt/cf
mkdir /$NEWROOT/mnt/net
# copy the /dev/mmcda1 to the actual /dev folder. We have to move the
# ramfs that is mounted on /dev to do this, and then move it back.
# also change the name of mmcda1 to mmsda1 see above
mkdir /dev.tmp
mount -o move /dev /dev.tmp
cp -a /dev.tmp/mmcda1 /dev/mmsda1
mount -o move /dev.tmp /dev
rmdir /dev.tmp
# modify init to pivot the root
echo "Modifying init"
# see if init.org exists
if [ -f /sbin/init.org ]
then
echo 'Init already modified -'
echo 'Cleaning up from previous install'
mv /$NEWROOT/sbin/init.org /$NEWROOT/sbin/init
else
# move the old init and make our new one
cd /sbin
mv init init.org
touch init
echo "#!/bin/sh" >> init
echo " " >> init
echo "#Check to see if we are being run to shutdown" >> init
echo 'if [ "$1" = 0 ] || [ "$1" = 6 ]' >> init
echo "then" >> init
echo ' exec /sbin/init.org "$1"' >> init
echo "fi" >> init
echo " " >> init
echo "# Script to pivot the root to $NEWROOT" >> init
echo " " >> init
echo "echo \"Pivoting Root...\" >> /dev/tty0" >> init
echo " " >> init
echo "/sbin/insmod /lib/modules/2.4.18-rmk7-pxa3-embedix/kernel/drivers/block/sharp_mmcsd_m.o" >> init
echo "/bin/mount -t ext2 -o defaults,noatime /dev/mmsda1 $NEWROOT" >> init
echo " " >> init
echo "if [ -f $NEWROOT/sbin/init ]" >> init
echo "then" >> init
echo "if(/sbin/pivot_root $NEWROOT $NEWROOT/mnt/root)" >> init
echo "then" >> init
echo "echo \" Successful\" >> /dev/tty0" >> init
echo 'exec /sbin/init $1' >> init
echo "fi" >> init
echo "fi" >> init
echo " " >> init
echo "echo \" Failed!\" >> /dev/tty0" >> init
echo 'exec /sbin/init.org $1' >> init
# make init executable
chmod a+x init
fi
# modify /etc/device_table. If we don't do this than opie will do some
# funny things happen to opie
echo "modifying $NEWROOT/etc/device_table"
cd $NEWROOT/etc
mv device_table device_table.org
sed -e 's/mmcda1/mmsda1/' < device_table.org > device_table
# uncomment the following 14 lines if you are running 3.5.1 this will
# prevent it from crashing on wake
# create our remount script
echo "adding remount.sh bootscript"
cd $NEWROOT/etc/init.d
touch remount.sh
echo "#!/bin/sh" >> remount.sh
echo " " >> remount.sh
echo "# make sure that we only run if we are running off of the card" >> remount.sh
echo " " >> remount.sh
echo 'if [ ! -f /sbin/init.org ]' >> remount.sh
echo "then" >> remount.sh
echo ' mount -o remount,sync /' >> remount.sh
echo 'fi' >> remount.sh
# make remount.sh executable
chmod a+x remount.sh
# uncomment the following 11 lines if you are using OZ 3.3.6pre1. This will
# will prevent it from crashing on sleep.
#cd $NEWROOT/etc/apm/scripts.d
#touch mount
#echo "#!/bin/sh" >> mount
#echo "if [ \"\$1\" = suspend ]; then" >> mount
#echo " mount -o remount -o ro /" >> mount
#echo "elif [ \"\$1\" = resume ]; then" >> mount
#echo " mount -o remount -o rw /" >> mount
#echo "fi" >> mount
#chmod +x mount
#ln -s ../scripts.d/mount ../suspend.d/S34mount
#ln -s ../scripts.d/mount ../resume.d/R34mount
Try that out. Like I said ... its working great for me, but this is a total SD setup not just home. I can still remove my SD card and boot from the NVram.