CRUX-ARM : Home

Home :: Documentation :: Download :: Development :: Community :: Ports :: Packages :: Bugs :: Links :: About :: Donors
Synced changes with initramfs.git
[initrd.git] / filesystem / rc
... / ...
CommitLineData
1#!/bin/sh
2
3#
4# initramfs /init (busybox ash)
5#
6
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}
28
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 MMC_DEVICES="`grep -E 'mmcblk0p' /proc/partitions | awk '{ print $4 }'`"
35 BLOCK_DEVICES="`grep -E '[sh]d' /proc/partitions | awk '{ print $4 }'`"
36 for DEV in $MMC_DEVICES $BLOCK_DEVICES
37 do
38 DEV="/dev/$DEV"
39 mount -r $DEV /media 2> /dev/null
40 if [ $? -eq 0 ]
41 then
42 echo -e -n " ${BOLD}${GREEN}*${NORM} Found media on $DEV"
43 if [ -e /media/crux-media ]
44 then
45 echo ", CRUX media."
46 ln -s $DEV /dev/media
47 break
48 else
49 echo ", but it's not the CRUX media."
50 umount /media
51 fi
52 else
53 echo -e " ${BOLD}${YELLOW}*${NORM} No media found on $DEV."
54 fi
55 done
56
57 # check if the media was mounted properly. if not, spawn a shell
58 if [ ! -e /media/crux-media ]
59 then
60 echo
61 echo -e " ${BOLD}${RED}*${NORM} The CRUX media was not properly mounted!"
62 echo " Spawning a shell for you to attempt to fix this problem. If"
63 echo " you are able to find the correct device, mount it at"
64 echo " /media and then log out of this shell to continue."
65 echo " If you are NOT able to fix the problem, installation will"
66 echo " not be possible."
67 echo
68 /bin/sh
69 fi
70
71 # check again and stop if it's still not there
72 if [ ! -e /media/crux-media ]
73 then
74 echo
75 echo -e " ${BOLD}${RED}*${NORM} The CRUX media still appears not to be"
76 echo " found and installation will not continue."
77 echo
78 else
79 # configure modules
80 MODULES="`find /media/crux/kernel -type f -name 'modules-*.tar.*' 2>/dev/null`"
81 if [ ! -z "$MODULES" ]; then
82 tar -C /tmp -xf $MODULES
83 cd /lib && ln -s /tmp/lib/* .
84 depmod
85 fi
86 # configure pkgutils
87 PKGUTILS="`find /media/crux/core -type f -name 'pkgutils#*.pkg.tar.*' 2>/dev/null`"
88 if [ ! -z "$PKGUTILS" ]; then
89 tar -C /tmp -xf $PKGUTILS
90 cd /usr/bin && ln -s /tmp/usr/bin/* .
91 cd /etc && ln -s /tmp/etc/* .
92 fi
93 fi
94}
95
96#
97# main script
98#
99
100echo ""
101echo -e "${BOLD}CRUX-ARM 3.0 - ${BLUE}http://crux-arm.nu/${NORM}"
102echo ""
103
104exec >/dev/console </dev/console 2>&1
105
106# premature mount /proc since we need some rw operations
107echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting "
108echo -e -n "${BOLD}${GREEN}/proc${NORM}"
109mount -t proc proc /proc
110
111if grep -q "debug" /proc/cmdline
112then
113 DEBUG=1
114fi
115
116# dont show kernel printk messages
117PRINTK="`cat /proc/sys/kernel/printk`"
118if [ -z $DEBUG ]
119then
120 echo "0" > /proc/sys/kernel/printk
121fi
122
123echo -e ", ${BOLD}${GREEN}/sys${NORM}."
124mount -t sysfs sysfs /sys
125
126echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting filesystems... "
127mount -a && \
128mount -o remount,rw /
129checkReturn
130
131echo -e -n " ${BOLD}${BLUE}*${NORM} Populating /dev via mdev... "
132mdev -s
133checkReturn
134
135echo -e -n " ${BOLD}${BLUE}*${NORM} Registering mdev as hotplug agent... "
136echo "/bin/mdev" > /proc/sys/kernel/hotplug
137checkReturn
138
139echo -e -n " ${BOLD}${BLUE}*${NORM} Creating and mounting /dev/pts... "
140mkdir /dev/pts
141mount -t devpts devpts /dev/pts
142checkReturn
143
144echo -e -n " ${BOLD}${BLUE}*${NORM} Starting kernel log daemon... "
145klogd
146checkReturn
147
148echo -e -n " ${BOLD}${BLUE}*${NORM} Setting hostname... "
149hostname crux
150checkReturn
151
152echo -e -n " ${BOLD}${BLUE}*${NORM} Loading network loopback device... "
153ip addr add 127.0.0.1/8 dev lo broadcast + scope host && \
154ip link set lo up && \
155echo "127.0.0.1 localhost crux" > /etc/hosts
156checkReturn
157
158echo -e -n " ${BOLD}${BLUE}*${NORM} Saving boot messages... "
159dmesg > /var/log/boot
160checkReturn
161
162# run mdev again to fix issues with mmc devices. yeah, it is weird but worked
163mdev -s
164
165echo -e " ${BOLD}${BLUE}*${NORM} Trying to find and mount the media installer..."
166find_and_mount_media
167
168# debug could be necessary when are working with a new device and/or features
169# and for a weird reason you can't see any output message on the console.
170# You can create a debug.sh script at topdir of your install media and redirect
171# the output to a file to inspect later
172if [ ! -z $DEBUG ];
173then
174 echo -e -n " ${BOLD}${BLUE}*${NORM} Loading debug script..."
175 /media/debug.sh
176 checkReturn
177fi
178
179echo
180echo "The system is coming up. Please wait."
181echo
182
183# restore kernel printk status
184echo "$PRINTK" > /proc/sys/kernel/printk
185
186# End of file