-
Notifications
You must be signed in to change notification settings - Fork 0
/
init
executable file
·95 lines (80 loc) · 2.39 KB
/
init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/sh
echo "Welcome to Vogue Linux"
mkdir -m 0755 /proc
mount -t proc proc /proc
mkdir -m 0755 /sys
mount -t sysfs sys /sys
#Configure Devices
MAKEDEVS
fail() {
echo "Failed"
echo "$1"
exec /bin/sh
}
while [ ! -d /sys/block/mmcblk0 ] ; do
echo "Waiting for SD Card"
sleep 1
done
#Wait a bit once mmcblk0 appears
#Reading partition table could take some time
sleep 1
#Call it ... root= ?
#I don't do that because I don't want to interfer in any way with kernel
root_partition=`/bin/grep -o "root_partition=.*" /proc/cmdline | /bin/sed -e "s/.*root_partition=//g" -e "s/ .*//g"`
if ! [ "$root_partition" = "" ];then
mkdir /rfs
mount -t ext2 $root_partition /rfs
mount -t tmpfs -o size=100K tmpfs /rfs/dev
cp -a /dev/* /rfs/dev
exec switch_root /rfs /init
fi
partition=`/bin/grep -o "loop_partition=.*" /proc/cmdline | /bin/sed -e "s/.*loop_partition=//g" -e "s/ .*//g"`
if [ "$partition" = "" ];then
partition="mmcblk0p1"
fi
# Try unpartitioned card
if [ ! -d /sys/block/mmcblk0/$partition ] ; then
partition=mmcblk0
fi
mkdir -m 0777 /card0
echo "Running an fsck on the SD card"
dosfsck -y /dev/block/$partition
mount -t vfat -o fmask=0000,dmask=0000,utf8,rw,flush,noatime,nodiratime /dev/block/$partition /card0
[ $? -eq 0 ] || fail "Failed to mount the SD card. Cannot continue."
CARD_PATH=`/bin/grep -o "rel_path=.*" /proc/cmdline | /bin/sed -e "s/.*rel_path=//g" -e "s/ .*//g"`
if [ "$CARD_PATH" = "" ];then
CARD_PATH="andboot"
fi
if [ -d /card0/$CARD_PATH ] ; then
card=/card0/$CARD_PATH
else
card=/card0
fi
if [ -f $card/rootfs.img ] ; then
root="$card/rootfs.img"
SQUASHFS=0
elif [ -f $card/rootfs.sqsh ]; then
root="$card/rootfs.sqsh"
SQUASHFS=1
else
fail "Failed to find rootfs on SD Card. You need to unzip a rootfs zip file to the root of your SD card."
fi
mkdir -m 0755 /rfs
losetup /dev/block/loop2 $root
[ $? -eq 0 ] || fail "Failed to mount rootfs on SD Card."
if [ $SQUASHFS -eq 0 ]; then
e2fsck -y /dev/block/loop2
mount -t ext2 -o noatime,nodiratime,sync,ro /dev/block/loop2 /rfs
[ $? -eq 0 ] || fail "Failed to mount rootfs"
else
mount -t squashfs -o noatime,nodiratime,sync,ro /dev/block/loop2 /rfs
[ $? -eq 0 ] || fail "Failed to mount rootfs"
fi
#mkdir /rfs/dev
mount -t tmpfs -o size=100K tmpfs /rfs/dev
cp -a /dev/* /rfs/dev
echo "Cleaning up..."
umount -l /proc
umount -l /sys
echo "Switching to rootfs..."
exec switch_root /rfs /init