CRUX-ARM : Home

Home :: Documentation :: Download :: Development :: Community :: Ports :: Packages :: Bugs :: Links :: About :: Donors
Updated busybox to 1.20.2
[initramfs.git] / filesystem / rc
CommitLineData
be3fa5e6 1#!/bin/sh
1d7b9c8a 2
be3fa5e6 3#
1d7b9c8a 4# initramfs /init (busybox ash)
be3fa5e6
JB
5#
6
1d7b9c8a
JB
7# color codes and some predefined texts
8BOLD="\033[1m"
9NORM="\033[0m"
10RED="\033[31m"
11GREEN="\033[32m"
12YELLOW="\033[33m"
13BLUE="\033[34m"
14OK="${BOLD}${GREEN}OK${NORM}"
15FAILED="${BOLD}${RED}FAILED${NORM}"
16
17# helper functions
18
19# check an exit value and print a colored status
20checkReturn() {
21 if [ $? -ne 0 ]
22 then
23 echo -e $FAILED
24 else
25 echo -e $OK
26 fi
27}
be3fa5e6 28
1d7b9c8a
JB
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
31find_and_mount_media() {
32 echo -e " ${BOLD}${BLUE}*${NORM} Searching for the CRUX media..."
33 mkdir -p /media
34 CRUXMEDIA=""
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
38 do
39 DEV="/dev/$DEV"
40 mount -r $DEV /media 2> /dev/null
41 if [ $? -eq 0 ]
42 then
43 echo -e -n " ${BOLD}${GREEN}*${NORM} Found media on $DEV"
44 if [ -e /media/crux-media ]
45 then
46 echo ", CRUX media."
47 CRUXMEDIA=$DEV
48 ln -s $DEV /dev/media
49 break
50 else
51 echo ", but it's not the CRUX media."
52 umount /media
53 fi
54 else
55 echo -e " ${BOLD}${YELLOW}*${NORM} No media found on $DEV."
56 fi
57 done
be3fa5e6 58
1d7b9c8a
JB
59 # check if the media was mounted properly. if not, spawn a shell
60 if [ ! -e /media/crux-media ]
61 then
62 echo
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."
69 echo
70 /bin/sh
71 fi
be3fa5e6 72
1d7b9c8a
JB
73 # check again and stop if it's still not there
74 if [ ! -e /media/crux-media ]
75 then
76 echo
77 echo -e " ${BOLD}${RED}*${NORM} The CRUX media still appears not to be"
78 echo " found and installation will not continue."
79 echo
80 else
81 # configure modules
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/* .
86 depmod
87 fi
88 # configure pkgutils
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/* .
94 fi
95 fi
96}
97
55f11ffe
JB
98/bin/busybox --install -s /bin
99
1d7b9c8a
JB
100#
101# main script
102#
be3fa5e6 103
1d7b9c8a
JB
104echo ""
105echo -e "${BOLD}CRUX-ARM 2.7.1 - ${BLUE}http://crux-arm.nu/${NORM}"
106echo ""
be3fa5e6 107
1d7b9c8a
JB
108exec >/dev/console </dev/console 2>&1
109
55f11ffe
JB
110echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting "
111echo -e -n "${BOLD}${GREEN}/proc${NORM}"
112mount -t proc proc /proc
113
114PRINTK="`cat /proc/sys/kernel/printk`"
115echo "0" > /proc/sys/kernel/printk
116
117echo -e ", ${BOLD}${GREEN}/sys${NORM}."
118mount -t sysfs sysfs /sys
1d7b9c8a
JB
119
120echo -e -n " ${BOLD}${BLUE}*${NORM} Populating /dev via mdev... "
121mdev -s
122checkReturn
123
124echo -e -n " ${BOLD}${BLUE}*${NORM} Registering mdev as hotplug agent... "
be3fa5e6 125echo "/bin/mdev" > /proc/sys/kernel/hotplug
1d7b9c8a
JB
126checkReturn
127
128echo -e -n " ${BOLD}${BLUE}*${NORM} Creating and mounting /dev/pts... "
129mkdir /dev/pts
130mount -t devpts devpts /dev/pts
131checkReturn
132
133echo -e -n " ${BOLD}${BLUE}*${NORM} Starting kernel log daemon... "
134klogd
135checkReturn
be3fa5e6 136
1d7b9c8a
JB
137echo -e -n " ${BOLD}${BLUE}*${NORM} Setting hostname... "
138hostname crux
139checkReturn
be3fa5e6 140
1d7b9c8a
JB
141echo -e -n " ${BOLD}${BLUE}*${NORM} Loading network loopback device... "
142ip addr add 127.0.0.1/8 dev lo broadcast + scope host && \
143ip link set lo up && \
144echo "127.0.0.1 localhost crux" > /etc/hosts
145checkReturn
be3fa5e6 146
1d7b9c8a
JB
147echo -e -n " ${BOLD}${BLUE}*${NORM} Saving boot messages... "
148dmesg > /var/log/boot
149checkReturn
be3fa5e6 150
55f11ffe
JB
151grep -q "devicetimeout=*" /proc/cmdline
152if [ $? -eq 0 ]
153then
154 for opt in `cat /proc/cmdline`
155 do
156 echo "$opt" | grep -q "devicetimeout="
157 if [ $? -eq 0 ]
158 then
159 DEVTIMEOUT=`echo $opt | cut -d'=' -f2`
160 fi
161 done
162else
163 DEVTIMEOUT=10
164fi
165echo -e " ${BOLD}${BLUE}*${NORM} Waiting $DEVTIMEOUT seconds for devices to settle..."
166sleep $DEVTIMEOUT
167
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
170grep -q "root=/dev/*" /proc/cmdline
171if [ $? -eq 0 ]
172then
173 for opt in `cat /proc/cmdline`
174 do
175 echo "$opt" | grep -q "root="
176 if [ $? -eq 0 ]
177 then
178 ROOTDEV=`echo $opt | cut -d'=' -f2`
179 fi
180 done
181 mkdir -p /newroot
182 # check the specified root device to see if it has an init
183 mount $ROOTDEV /newroot
184 if [ $? -ne 0 ]
185 then
186 echo -e " ${BOLD}${RED}*${NORM} Unable to mount the specified root device! Falling back to the live media."
187 find_and_mount_media
188 else
189 if [ -x /newroot/sbin/init ]
190 then
191 echo -e " ${BOLD}${BLUE}*${NORM} Mounted root device $ROOTDEV."
192 else
193 echo -e " ${BOLD}${RED}*${NORM} The specified root device ($ROOTDEV) does not appear to be usable! Falling back to the live media."
194 umount /newroot
195 find_and_mount_media
196 fi
197 fi
198else
199 find_and_mount_media
200fi
201
202echo -e "${BOLD}${BLUE}*${NORM} Switching root.\n"
203echo "$PRINTK" > /proc/sys/kernel/printk
204echo > /proc/sys/kernel/hotplug
205umount /sys
206umount /proc
207exec /bin/switch_root /newroot /sbin/init
208
209echo "Something's broken, here's a shell."
210exec /bin/sh
be3fa5e6
JB
211
212# End of file