forked from mer-hybris/hybris-initrd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jolla-init
executable file
·103 lines (83 loc) · 2.84 KB
/
jolla-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
96
97
98
99
100
101
102
103
#!/bin/sh
# Generic ramdisk init process for booting a device. Based Marko Saukko's
# initrd for Galaxy Note GT-i9250.
#
# Copyright (C) 2014 Jolla Ltd.
# Copyright (C) 2012 Marko Saukko
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# IRC: Sage @ #mer & #nemomobile @ Freenode
# Location of the device init script, if not set, few defaults are tried.
INITBIN=/sbin/preinit
# Where to mount the rootfs
ROOTMNTDIR="/rootfs"
# With MNTSCRIPT, you can use your own mounting script and bypass the default
# root mounting. The script should take $ROOTMNTDIR as parameter
# for where to mount the root.
MNTSCRIPT="/sbin/root-mount"
fail()
{
echo "initrd: Failed" > /dev/kmsg
echo "initrd: $1" > /dev/kmsg
reboot2 recovery
}
mkdir -p /proc
mount -t proc proc /proc
mkdir -p /sys
mount -t sysfs sys /sys
mkdir -p /dev
mount -t devtmpfs devtmpfs /dev
echo "initrd: Starting ramdisk.." > /dev/kmsg
# Reset watchdog timer
echo "V" > /dev/watchdog
# Some filesystem tools may need mtab to work
cat /proc/mounts > /etc/mtab
mkdir -p $ROOTMNTDIR
# Mount the root filesystem
if [ -e $MNTSCRIPT ]; then
$MNTSCRIPT $ROOTMNTDIR
if [ $? -eq 0 ]; then
echo "initrd: Mounting root succeeded" > /dev/kmsg
else
fail "Mouting root failed"
fi
else
fail "$MNTSCRIPT does not exist, cannot mount root!"
fi
echo "initrd: Searching for init process..." > /dev/kmsg
if [ -n $INITBIN ] || [ -e $ROOTMNTDIR/$INITBIN ]; then
echo "initrd: Found $INITBIN" > /dev/kmsg
elif [ -e ${ROOTMNTDIR}/usr/sbin/init ]; then
INITBIN="/usr/sbin/init"
elif [ -e ${ROOTMNTDIR}/sbin/init ]; then
INITBIN="/sbin/init"
elif [ -e ${ROOTMNTDIR}/init ]; then
INITBIN="/init"
else
fail "Unable to find init process from rootfs."
fi
# umount everything before doing switch root as the init process
# is responsible of doing these inside the final boot env.
umount -l /dev
umount -l /sys
umount -l /proc
# Old preinit ( < 1.0.4.* Sailfish releases) does not mount /dev so let's mount
# it here.
mkdir -p ${ROOTMNTDIR}/dev
mount -t devtmpfs devtmpfs ${ROOTMNTDIR}/dev
echo "initrd: Switching to rootfs at ${ROOTMNTDIR}, with init ${INITBIN}" > ${ROOTMNTDIR}/dev/kmsg
# usage: switch_root <newrootdir> <init> <args to init>
exec switch_root ${ROOTMNTDIR} ${INITBIN}