4 # initramfs /init (busybox ash)
7 # color codes and some predefined texts
14 OK
="${BOLD}${GREEN}OK${NORM}"
15 FAILED
="${BOLD}${RED}FAILED${NORM}"
19 # check an exit value and print a colored status
29 # search for and mount the crux media, populate a tmpfs from it,
30 # and prepare /newroot for switch_root at the end of the script
31 find_and_mount_media
() {
32 echo -e " ${BOLD}${BLUE}*${NORM} Searching for the CRUX media..."
35 MMC_DEVICES
="`grep -E 'mmcblk' /proc/partitions | awk '{ print $4 }'`"
36 BLOCK_DEVICES
="`grep -E '[sh]d' /proc/partitions | awk '{ print $4 }'`"
37 for DEV
in $MMC_DEVICES $BLOCK_DEVICES
40 mount
-r $DEV /media
2> /dev
/null
43 echo -e -n " ${BOLD}${GREEN}*${NORM} Found media on $DEV"
44 if [ -e /media
/crux-media
]
51 echo ", but it's not the CRUX media."
55 echo -e " ${BOLD}${YELLOW}*${NORM} No media found on $DEV."
59 # check if the media was mounted properly. if not, spawn a shell
60 if [ ! -e /media
/crux-media
]
63 echo -e " ${BOLD}${RED}*${NORM} The CRUX media was not properly mounted!"
64 echo " Spawning a shell for you to attempt to fix this problem. If"
65 echo " you are able to find the correct device, mount it at"
66 echo " /media and then log out of this shell to continue."
67 echo " If you are NOT able to fix the problem, installation will"
68 echo " not be possible."
73 # check again and stop if it's still not there
74 if [ ! -e /media
/crux-media
]
77 echo -e " ${BOLD}${RED}*${NORM} The CRUX media still appears not to be"
78 echo " found and installation will not continue."
82 MODULES
="`find /media/crux/kernel -type f -name 'modules-*.tar.*'`"
83 if [ ! -z "$MODULES" ]; then
84 tar -C /tmp
-xf $MODULES
85 cd /lib
&& ln -s /tmp
/lib
/* .
89 PKGUTILS
="`find /media/crux/core -type f -name 'pkgutils#*.pkg.tar.*'`"
90 if [ ! -z "$PKGUTILS" ]; then
91 tar -C /tmp
-xf $PKGUTILS
92 cd /usr
/bin
&& ln -s /tmp
/usr
/bin
/* .
93 cd /etc
&& ln -s /tmp
/etc
/* .
98 /bin
/busybox
--install -s /bin
105 echo -e "${BOLD}CRUX-ARM 2.7.1 - ${BLUE}http://crux-arm.nu/${NORM}"
108 exec >/dev
/console
</dev
/console
2>&1
110 echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting "
111 echo -e -n "${BOLD}${GREEN}/proc${NORM}"
112 mount
-t proc proc
/proc
114 PRINTK
="`cat /proc/sys/kernel/printk`"
115 echo "0" > /proc
/sys
/kernel
/printk
117 echo -e ", ${BOLD}${GREEN}/sys${NORM}."
118 mount
-t sysfs sysfs
/sys
120 echo -e -n " ${BOLD}${BLUE}*${NORM} Populating /dev via mdev... "
124 echo -e -n " ${BOLD}${BLUE}*${NORM} Registering mdev as hotplug agent... "
125 echo "/bin/mdev" > /proc
/sys
/kernel
/hotplug
128 echo -e -n " ${BOLD}${BLUE}*${NORM} Creating and mounting /dev/pts... "
130 mount
-t devpts devpts
/dev
/pts
133 echo -e -n " ${BOLD}${BLUE}*${NORM} Starting kernel log daemon... "
137 echo -e -n " ${BOLD}${BLUE}*${NORM} Setting hostname... "
141 echo -e -n " ${BOLD}${BLUE}*${NORM} Loading network loopback device... "
142 ip addr add
127.0.0.1/8 dev lo broadcast
+ scope
host && \
143 ip link
set lo up
&& \
144 echo "127.0.0.1 localhost crux" > /etc
/hosts
147 echo -e -n " ${BOLD}${BLUE}*${NORM} Saving boot messages... "
148 dmesg
> /var
/log
/boot
151 grep -q "devicetimeout=*" /proc
/cmdline
154 for opt
in `cat /proc/cmdline`
156 echo "$opt" | grep -q "devicetimeout="
159 DEVTIMEOUT
=`echo $opt | cut -d'=' -f2`
165 echo -e " ${BOLD}${BLUE}*${NORM} Waiting $DEVTIMEOUT seconds for devices to settle..."
168 # if root=/dev/XXX was specified on the command line, use that as the new root
169 # instead of searching for the media and using it. if it fails, fall back to the media
170 grep -q "root=/dev/*" /proc
/cmdline
173 for opt
in `cat /proc/cmdline`
175 echo "$opt" | grep -q "root="
178 ROOTDEV
=`echo $opt | cut -d'=' -f2`
182 # check the specified root device to see if it has an init
183 mount
$ROOTDEV /newroot
186 echo -e " ${BOLD}${RED}*${NORM} Unable to mount the specified root device! Falling back to the live media."
189 if [ -x /newroot
/sbin
/init
]
191 echo -e " ${BOLD}${BLUE}*${NORM} Mounted root device $ROOTDEV."
193 echo -e " ${BOLD}${RED}*${NORM} The specified root device ($ROOTDEV) does not appear to be usable! Falling back to the live media."
202 echo -e "${BOLD}${BLUE}*${NORM} Switching root.\n"
203 echo "$PRINTK" > /proc
/sys
/kernel
/printk
204 echo > /proc
/sys
/kernel
/hotplug
207 exec /bin
/switch_root
/newroot
/sbin
/init
209 echo "Something's broken, here's a shell."