projects/aports·blob v1.5.1 · refs

173 lines · 3.8 KiB

1#!/bin/sh
2
3VERSION=1.9.1-pre0
4NEWROOT=/newroot
5SINGLEMODE=no
6
7# basic environment
8export PATH=/usr/bin:/bin:/usr/sbin:/sbin
9
10# basic mounts
11mount -t proc -o noexec,nosuid,nodev proc /proc
12mount -t sysfs -o noexec,nosuid,nodev sysfs /sys
13
14# some helpers
15ebegin() {
16 echo -n " * $*: "
17}
18eend() {
19 local msg
20 if [ "$1" = 0 ] || [ $# -lt 1 ] ; then
21 echo "ok."
22 else
23 shift
24 echo "failed. $*"
25 echo "initramfs emergency recovery shell launched"
26 exec /bin/busybox sh
27 fi
28}
29
30scan_drivers() {
31 if [ "$AUTODETECT" != no ] ; then
32 find /sys -name modalias | xargs sort | while read a ; do
33 modprobe $a 2>/dev/null \
34 || echo $a >> /tmp/hwdrivers.failed
35 done
36 fi
37}
38
39find_ovl() {
40 local mnt="$1"
41 local ovl
42 local lines
43
44 # look for apkovl's on mounted media
45 ovl=$( ls -1 "$mnt"/*.apkovl.tar.gz* 2>/dev/null ) || return 1
46 lines=$(echo "$ovl" | wc -l)
47
48 if [ $lines -gt 1 ] ; then
49 echo "ERROR: More than one apkovl file was found on $(basename $mnt). None will be read." >&2
50 return 1
51 fi
52 echo "$ovl"
53}
54
55# gotta start from somewhere :)
56echo "Starting Alpine $VERSION"
57
58# read the kernel options
59for i in `cat /proc/cmdline` ; do
60 case $i in
61 s|single|1)
62 SINGLEMODE=yes ;;
63 modules=*)
64 MODULES="`echo ${i#modules=} | tr ',' ' '`";;
65 noautodetect)
66 AUTODETECT=no;;
67 *=*) eval KOPT_$i ;;
68 *) eval KOPT_$i=yes ;;
69 esac
70done
71
72ALPINE_DEV=${KOPT_alpine_dev%%:*}
73ALPINE_MNT=/media/$ALPINE_DEV
74
75# hide kernel messages
76dmesg -n 1
77
78# setup /dev
79ebegin "Starting mdev"
80mount -t tmpfs -o exec,nosuid,mode=0755 mdev /dev
81mknod -m 666 /dev/null c 1 3
82ln -s sr0 /dev/cdrom
83echo "/sbin/mdev" > /proc/sys/kernel/hotplug
84mdev -s
85RC=$?
86[ -d /dev/pts ] || mkdir -m 755 /dev/pts
87[ -c /dev/ptmx ] || mknod -m 666 /dev/ptmx c 5 2
88mount -t devpts -o gid=5,mode=0620,noexec,nosuid devpts /dev/pts
89[ -d /dev/shm ] || mkdir /dev/shm
90mount -t tmpfs -o nodev,nosuid,noexec shm /dev/shm
91eend $RC
92
93# load available drivers to get access to modloop media
94ebegin "Loading boot drivers"
95[ "$MODULES" ] && modprobe $MODULES 2> /dev/null
96if [ -f /etc/modules ] ; then
97 sed 's/\#.*//g' < /etc/modules |
98 while read module args; do
99 modprobe -q $module $args
100 done
101fi
102scan_drivers
103scan_drivers
104eend 0
105
106# locate boot media and mount it
107ebegin "Mounting boot media"
108mount $ALPINE_MNT >/dev/null 2>&1
109eend $?
110ebegin "Mounting loopback device for kernel modules"
111modprobe loop
112mount -o loop,ro -t cramfs /media/$ALPINE_DEV/$(dirname ${KOPT_BOOT_IMAGE:-""})/modloop.cmg /.modloop
113rc=$?
114if [ "$rc" = 0 ]; then
115 rm -rf /lib/modules
116 ln -sf /.modloop/modules /lib
117fi
118if [ -d $ALPINE_MNT/firmware ]; then
119 mkdir -p /lib/firmware
120 cp -a $ALPINE_MNT/firmware/* /lib/firmware/
121fi
122eend $?
123
124# early console?
125if [ "$SINGLEMODE" = "yes" ]; then
126 echo "Entering single mode. Type 'exit' to continue booting."
127 sh
128fi
129
130# more drivers
131ebegin "Loading hardware drivers"
132scan_drivers
133eend 0
134
135# look for apkovl
136for i in usb floppy cdrom; do
137 mount /media/$i 2>/dev/null || continue
138 ovl=$(find_ovl /media/$i)
139 [ -f "$ovl" ] && break
140 umount /media/$i 2>/dev/null
141done
142
143if [ -f "$ovl" ]; then
144 ebegin "Loading user settings from $ovl"
145 tar -C $NEWROOT -zxf "$ovl"
146 eend $?
147 umount /media/$i 2>/dev/null
148 pkgs=$(sed 's/\#.*//' $NEWROOT/etc/lbu/packages.list 2>/dev/null)
149fi
150
151# install new root
152ebegin "Installing packages to root filesystem"
153mount -t tmpfs -o size=50M tmpfs $NEWROOT
154apk add --root /newroot --repository /media/cdrom/apks \
155 --initdb --quiet --progress $pkgs
156eend $?
157
158# switch over to new root
159cat /proc/mounts | while read DEV DIR TYPE OPTS ; do
160 if [ "$DIR" != "/" -a "$DIR" != "$NEWROOT" -a -d "$DIR" ]; then
161 mkdir -p $NEWROOT/$DIR
162 mount -o move $DIR $NEWROOT/$DIR
163 fi
164done
165sync
166
167if [ -x $NEWROOT/sbin/init ]; then
168 exec /bin/busybox switch_root $NEWROOT /sbin/init $KOPT_init_args
169fi
170
171echo "initramfs emergency recovery shell launched"
172exec /bin/busybox sh
173reboot