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 -n " ${BOLD}${BLUE}*${NORM} Creating and mounting tmpfs... "
34 mount
-t tmpfs tmpfs
/.tmpfs
37 echo -e " ${BOLD}${BLUE}*${NORM} Searching for the CRUX media..."
38 mkdir
-p /.tmpfs
/.media
40 CDROM_DEVICES
="`grep 'drive name:' /proc/sys/dev/cdrom/info | awk '{ print $3 }'`"
41 MMC_DEVICES
="`grep -E 'mmcblk' /proc/partitions | awk '{ print $4 }'`"
42 BLOCK_DEVICES
="`grep -E '[sh]d' /proc/partitions | awk '{ print $4 }'`"
43 for DEV
in $CDROM_DEVICES $MMC_DEVICES $BLOCK_DEVICES
46 mount
-r $DEV /.tmpfs
/.media
2> /dev
/null
49 echo -e -n " ${BOLD}${GREEN}*${NORM} Found media on $DEV"
50 if [ -e /.tmpfs
/.media
/crux-media
]
56 echo ", but it's not the CRUX media."
60 echo -e " ${BOLD}${YELLOW}*${NORM} No media found on $DEV."
64 # check if the media was mounted properly. if not, spawn a shell
65 if [ ! -e /.tmpfs
/.media
/crux-media
]
67 echo -e " ${BOLD}${RED}*${NORM} The CRUX media was not properly mounted!"
68 echo " Spawning a shell for you to attempt to fix this problem. If"
69 echo " you are able to find the correct device, mount it at"
70 echo " /.tmpfs/.media and then log out of this shell to continue."
71 echo " If you are NOT able to fix the problem, installation will"
72 echo " not be possible."
77 # check again and stop if it's still not there
78 if [ ! -e /.tmpfs
/.media
/crux-media
]
80 echo -e " ${BOLD}${RED}*${NORM} The CRUX media still appears not to be"
81 echo " found and installation will not continue."
87 echo -e " ${BOLD}${BLUE}*${NORM} Populating root filesystem..."
89 echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting new root filesystem... "
90 mount
-t tmpfs tmpfs
/newroot
92 echo -e -n " ${BOLD}${BLUE}*${NORM} Copying files from rootfs.tar.xz... "
93 tar -xpf /.tmpfs
/.media
/rootfs.
tar.xz
-C /newroot
95 echo -e -n " ${BOLD}${BLUE}*${NORM} Copying devices from rootfs... "
96 cp -af /dev
/* /newroot
/dev
/
98 mkdir
-p /newroot
/dev
/pts
/newroot
/media
100 # the media gets unmounted here and remounted after switch_root
101 umount
/.tmpfs
/.media
103 sed -i -e "s,#CRUXMEDIA#,${CRUXMEDIA}," /newroot
/etc
/fstab
105 echo -e -n " ${BOLD}${BLUE}*${NORM} Unmounting tmpfs... "
111 /bin
/busybox
--install -s /bin
116 echo -e "${BOLD}CRUX-ARM 2.7.1 - ${BLUE}http://crux-arm.nu/${NORM}"
119 exec >/dev
/console
</dev
/console
2>&1
121 echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting "
122 echo -e -n "${BOLD}${GREEN}/proc${NORM}"
123 mount
-t proc proc
/proc
125 PRINTK
="`cat /proc/sys/kernel/printk`"
126 echo "0" > /proc
/sys
/kernel
/printk
128 echo -e ", ${BOLD}${GREEN}/sys${NORM}."
129 mount
-t sysfs sysfs
/sys
131 echo -e -n " ${BOLD}${BLUE}*${NORM} Populating /dev via mdev... "
134 echo -e -n " ${BOLD}${BLUE}*${NORM} Registering mdev as hotplug agent... "
135 echo "/bin/mdev" > /proc
/sys
/kernel
/hotplug
138 if [ -d /lib
/modules
]
140 echo -e -n " ${BOLD}${BLUE}*${NORM} Loading modules... "
143 echo -e " ${BOLD}${YELLOW}*${NORM} No modules were found in the initial RAM filesystem."
146 grep -q "devicetimeout=*" /proc
/cmdline
149 for opt
in `cat /proc/cmdline`
151 echo "$opt" | grep -q "devicetimeout="
154 DEVTIMEOUT
=`echo $opt | cut -d'=' -f2`
160 echo -e " ${BOLD}${BLUE}*${NORM} Waiting $DEVTIMEOUT seconds for devices to settle..."
163 # if root=/dev/XXX was specified on the command line, use that as the new root
164 # instead of searching for the media and using it. if it fails, fall back to
166 grep -q "root=/dev/*" /proc
/cmdline
169 for opt
in `cat /proc/cmdline`
171 echo "$opt" | grep -q "root="
174 ROOTDEV
=`echo $opt | cut -d'=' -f2`
178 # check the specified root device to see if it has an init
179 mount
$ROOTDEV /newroot
182 echo -e " ${BOLD}${RED}*${NORM} Unable to mount the specified root device! Falling back to the live media."
185 if [ -x /newroot
/sbin
/init
]
187 echo -e " ${BOLD}${BLUE}*${NORM} Mounted root device $ROOTDEV."
189 echo -e " ${BOLD}${RED}*${NORM} The specified root device ($ROOTDEV) does not appear to be usable! Falling back to the live media."
198 echo -e " ${BOLD}${BLUE}*${NORM} Switching root.\n"
199 echo "$PRINTK" > /proc
/sys
/kernel
/printk
200 echo > /proc
/sys
/kernel
/hotplug
203 exec /bin
/switch_root
/newroot
/sbin
/init
205 echo "Something's broken, here's a shell."