summaryrefslogtreecommitdiff
path: root/scripts/init.sh
blob: 7b884de1fee08967b16cef3605876eea26830206 (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/sh
mount -o nosuid,strictatime,mode=755 -t devtmpfs devtmpfs /dev
mount -o nosuid,noexec,nodev -t sysfs sysfs /sys
mount -o nosuid,noexec,nodev -t proc proc /proc

/bin/mkdir /sysroot
/bin/mkdir /opt

ROOTFS=`/sbin/blkid -L rootfs`
if [ x$ROOTFS = "x" ]
then
    ROOTFS=`/sbin/blkid -t PARTLABEL=rootfs -o device`
fi

MODULES=`/sbin/blkid -L modules`
if [ x$MODULES = "x" ]
then
    MODULES=`/sbin/blkid -t PARTLABEL=module -o device`
fi

DATAFS=`/sbin/blkid -L system-data`
if [ x$DATAFS = "x" ]
then
    DATAFS=`/sbin/blkid -t PARTLABEL=system-data -o device`
fi

USERFS=`/sbin/blkid -L user`
if [ x$USERFS = "x" ]
then
    USERFS=`/sbin/blkid -t PARTLABEL=user -o device`
fi

NEED_RESIZEFS=1
USERFS_ENCRYPTED=0
if [ x"$DATAFS" != "x" ]
then
    /sbin/fsck -y $DATAFS
    /bin/mount $DATAFS /opt

    # The device is being encrypted or encrypted.
    if [ -e /opt/etc/.odeprogress -o -e /opt/etc/.ode_* ]
    then
        USERFS_ENCRYPTED=1
    fi

    if [ -e /opt/var/.resizefs_done ]
    then
        NEED_RESIZEFS=0
    else
        /bin/umount /opt
    fi
fi

if [ x$ROOTFS != "x" ]
then
    if [ "$NEED_RESIZEFS" = "1" ]
    then
        /sbin/resize2fs -f $ROOTFS
    fi
    /sbin/fsck -y $ROOTFS
    /bin/mount $ROOTFS /sysroot -o rw
else
    echo "WARNING : THERE IS NO ROOTFS."
    exec /bin/sh
fi

if [ x"$DATAFS" != "x" ]
then
    if [ "$NEED_RESIZEFS" = "1" ]
    then
        /sbin/resize2fs -f $DATAFS
        /sbin/fsck -y $DATAFS
        /bin/mount $DATAFS /sysroot/opt
    else
        /bin/mount -M /opt /sysroot/opt
    fi
fi

if [ x"$USERFS" != "x" -a "$USERFS_ENCRYPTED" = "0" ]
then
    if [ "$NEED_RESIZEFS" = "1" ]
    then
        /sbin/resize2fs -f $USERFS
    fi
    /sbin/fsck -y $USERFS
fi

if [ -e /sysroot/opt/sqsh_usr.img ]
then
    if [ ! -d /sysroot/usr ]
    then
        /bin/mkdir /sysroot/usr
    fi
    echo "Mounting Squash FS to /usr..."
    /bin/mount /sysroot/opt/sqsh_usr.img /sysroot/usr
fi

if [ x$MODULES != "x" ]
then
    if [ "$NEED_RESIZEFS" = "1" ]
    then
        /sbin/resize2fs -f $MODULES
    fi
    /sbin/fsck -y $MODULES
    /bin/mount $MODULES /sysroot/usr/lib/modules
fi

if [ x"$DATAFS" != "x" -a "$NEED_RESIZEFS" = "1" ]
then
    echo " " > /sysroot/opt/var/.resizefs_done
fi

cd /sysroot
mkdir -p ./dev ./sys ./proc ./initrd
/sbin/pivot_root . ./initrd
/bin/mount -M ./initrd/dev /dev
/bin/mount -M ./initrd/sys /sys
/bin/mount -M ./initrd/proc /proc
/bin/umount -l ./initrd
/bin/rm -rf ./initrd
/bin/mount -o remount,ro .

INIT=/sbin/init
if [ $$ = 1 ]
then
    exec chroot . $INIT $@
fi
exec /bin/sh