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
]
54 #ln -s $DEV /dev/media
57 echo ", but it's not the CRUX media."
61 echo -e " ${BOLD}${YELLOW}*${NORM} No media found on $DEV."
65 # check if the media was mounted properly. if not, spawn a shell
66 if [ ! -e /.tmpfs
/.media
/crux-media
]
69 echo -e " ${BOLD}${RED}*${NORM} The CRUX media was not properly mounted!"
70 echo " Spawning a shell for you to attempt to fix this problem. If"
71 echo " you are able to find the correct device, mount it at"
72 echo " /.tmpfs/.media and then log out of this shell to continue."
73 echo " If you are NOT able to fix the problem, installation will"
74 echo " not be possible."
79 # check again and stop if it's still not there
80 if [ ! -e /.tmpfs
/.media
/crux-media
]
83 echo -e " ${BOLD}${RED}*${NORM} The CRUX media still appears not to be"
84 echo " found and installation will not continue."
90 echo -e " ${BOLD}${BLUE}*${NORM} Populating root filesystem..."
92 echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting new root filesystem... "
93 mount
-t tmpfs tmpfs
/newroot
95 echo -e -n " ${BOLD}${BLUE}*${NORM} Copying files from rootfs.tar.xz... "
96 tar -xpf /.tmpfs
/.media
/rootfs.
tar.xz
-C /newroot
98 echo -e -n " ${BOLD}${BLUE}*${NORM} Copying devices from rootfs... "
99 cp -af /dev
/* /newroot
/dev
101 mkdir
-p /newroot
/dev
/pts
/newroot
/media
103 # the media gets unmounted here and remounted after switch_root
104 umount
/.tmpfs
/.media
106 sed -i -e "s,#CRUXMEDIA#,${CRUXMEDIA}," /newroot
/etc
/fstab
108 echo -e -n " ${BOLD}${BLUE}*${NORM} Unmounting tmpfs... "
114 /bin
/busybox
--install -s /bin
121 echo -e "${BOLD}CRUX-ARM 2.7.1 - ${BLUE}http://crux-arm.nu/${NORM}"
124 exec >/dev
/console
</dev
/console
2>&1
126 echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting "
127 echo -e -n "${BOLD}${GREEN}/proc${NORM}"
128 mount
-t proc proc
/proc
130 PRINTK
="`cat /proc/sys/kernel/printk`"
131 echo "0" > /proc
/sys
/kernel
/printk
133 echo -e ", ${BOLD}${GREEN}/sys${NORM}."
134 mount
-t sysfs sysfs
/sys
136 echo -e -n " ${BOLD}${BLUE}*${NORM} Populating /dev via mdev... "
140 echo -e -n " ${BOLD}${BLUE}*${NORM} Registering mdev as hotplug agent... "
141 echo "/bin/mdev" > /proc
/sys
/kernel
/hotplug
144 if [ -d /lib
/modules
]
146 echo -e -n " ${BOLD}${BLUE}*${NORM} Loading modules... "
149 echo -e " ${BOLD}${YELLOW}*${NORM} No modules were found in the initial RAM filesystem."
152 grep -q "devicetimeout=*" /proc
/cmdline
155 for opt
in `cat /proc/cmdline`
157 echo "$opt" | grep -q "devicetimeout="
160 DEVTIMEOUT
=`echo $opt | cut -d'=' -f2`
166 echo -e " ${BOLD}${BLUE}*${NORM} Waiting $DEVTIMEOUT seconds for devices to settle..."
169 # if root=/dev/XXX was specified on the command line, use that as the new root
170 # instead of searching for the media and using it. if it fails, fall back to the media
171 grep -q "root=/dev/*" /proc
/cmdline
174 for opt
in `cat /proc/cmdline`
176 echo "$opt" | grep -q "root="
179 ROOTDEV
=`echo $opt | cut -d'=' -f2`
183 # check the specified root device to see if it has an init
184 mount
$ROOTDEV /newroot
187 echo -e " ${BOLD}${RED}*${NORM} Unable to mount the specified root device! Falling back to the live media."
190 if [ -x /newroot
/sbin
/init
]
192 echo -e " ${BOLD}${BLUE}*${NORM} Mounted root device $ROOTDEV."
194 echo -e " ${BOLD}${RED}*${NORM} The specified root device ($ROOTDEV) does not appear to be usable! Falling back to the live media."
203 echo -e "${BOLD}${BLUE}*${NORM} Switching root.\n"
204 echo "$PRINTK" > /proc
/sys
/kernel
/printk
205 echo > /proc
/sys
/kernel
/hotplug
208 exec /bin
/switch_root
/newroot
/sbin
/init
210 echo "Something's broken, here's a shell."