CRUX-ARM : Home

Home :: Documentation :: Download :: Development :: Community :: Ports :: Packages :: Bugs :: Links :: About :: Donors
Synced changes with initramfs.git
[initrd.git] / filesystem / rc
CommitLineData
b70e0e65 1#!/bin/sh
60a77e5f 2
b70e0e65 3#
60a77e5f 4# initramfs /init (busybox ash)
b70e0e65
JB
5#
6
60a77e5f
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}
b70e0e65 28
60a77e5f
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..."
dfd7aefe 33 mkdir -p /media
06ba1c90 34 MMC_DEVICES="`grep -E 'mmcblk0p' /proc/partitions | awk '{ print $4 }'`"
60a77e5f
JB
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."
60a77e5f
JB
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
b70e0e65 56
60a77e5f
JB
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
b70e0e65 70
60a77e5f
JB
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
dfd7aefe 79 # configure modules
eebbffc5 80 MODULES="`find /media/crux/kernel -type f -name 'modules-*.tar.*' 2>/dev/null`"
6cc6cf55
JB
81 if [ ! -z "$MODULES" ]; then
82 tar -C /tmp -xf $MODULES
b3584205 83 cd /lib && ln -s /tmp/lib/* .
60a77e5f
JB
84 depmod
85 fi
dfd7aefe 86 # configure pkgutils
eebbffc5 87 PKGUTILS="`find /media/crux/core -type f -name 'pkgutils#*.pkg.tar.*' 2>/dev/null`"
dfd7aefe 88 if [ ! -z "$PKGUTILS" ]; then
6cc6cf55 89 tar -C /tmp -xf $PKGUTILS
dfd7aefe
JB
90 cd /usr/bin && ln -s /tmp/usr/bin/* .
91 cd /etc && ln -s /tmp/etc/* .
60a77e5f
JB
92 fi
93 fi
94}
95
96#
97# main script
98#
b70e0e65 99
60a77e5f 100echo ""
2b95ffc0 101echo -e "${BOLD}CRUX-ARM 3.0 - ${BLUE}http://crux-arm.nu/${NORM}"
60a77e5f 102echo ""
b70e0e65 103
60a77e5f
JB
104exec >/dev/console </dev/console 2>&1
105
1a72982e
JB
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
60a77e5f 126echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting filesystems... "
dfd7aefe
JB
127mount -a && \
128mount -o remount,rw /
60a77e5f
JB
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... "
b70e0e65 136echo "/bin/mdev" > /proc/sys/kernel/hotplug
60a77e5f
JB
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
b70e0e65 147
60a77e5f
JB
148echo -e -n " ${BOLD}${BLUE}*${NORM} Setting hostname... "
149hostname crux
150checkReturn
b70e0e65 151
60a77e5f 152echo -e -n " ${BOLD}${BLUE}*${NORM} Loading network loopback device... "
dfd7aefe
JB
153ip addr add 127.0.0.1/8 dev lo broadcast + scope host && \
154ip link set lo up && \
60a77e5f
JB
155echo "127.0.0.1 localhost crux" > /etc/hosts
156checkReturn
b70e0e65 157
60a77e5f
JB
158echo -e -n " ${BOLD}${BLUE}*${NORM} Saving boot messages... "
159dmesg > /var/log/boot
160checkReturn
b70e0e65 161
1a72982e
JB
162# run mdev again to fix issues with mmc devices. yeah, it is weird but worked
163mdev -s
164
dfd7aefe 165echo -e " ${BOLD}${BLUE}*${NORM} Trying to find and mount the media installer..."
60a77e5f 166find_and_mount_media
b70e0e65 167
1a72982e
JB
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
06ba1c90
JB
174 echo -e -n " ${BOLD}${BLUE}*${NORM} Loading debug script..."
175 /media/debug.sh
176 checkReturn
177fi
178
60a77e5f
JB
179echo
180echo "The system is coming up. Please wait."
181echo
b70e0e65 182
1a72982e
JB
183# restore kernel printk status
184echo "$PRINTK" > /proc/sys/kernel/printk
185
b70e0e65 186# End of file