blob: d09bbb8bed4dfd8eae29b2152e4857a054e31641 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/bin/sh
2# Copyright (C) 2011 O.S. Systems Software LTDA.
3# Licensed on MIT
4
5finish_enabled() {
6 return 0
7}
8
9finish_run() {
10 if [ -n "$ROOTFS_DIR" ]; then
11 if [ -n "$bootparam_rootdelay" ]; then
12 debug "Sleeping for $rootdelay second(s) to wait root to settle..."
13 sleep $bootparam_rootdelay
14 fi
15
16 if [ -n "$bootparam_root" ]; then
17 debug "No e2fs compatible filesystem has been mounted, mounting $bootparam_root..."
18
19 if [ "`echo ${bootparam_root} | cut -c1-5`" = "UUID=" ]; then
20 root_uuid=`echo $bootparam_root | cut -c6-`
21 bootparam_root="/dev/disk/by-uuid/$root_uuid"
22 fi
23
24 if [ -e "$bootparam_root" ]; then
25 flags=""
26 if [ -n "$bootparam_ro" ]; then
27 if [ -n "$bootparam_rootflags" ]; then
28 bootparam_rootflags="$bootparam_rootflags,"
29 fi
30 bootparam_rootflags="${bootparam_rootflags}ro"
31 fi
32 if [ -n "$bootparam_rootflags" ]; then
33 flags="$flags -o$bootparam_rootflags"
34 fi
35 if [ -n "$bootparam_rootfstype" ]; then
36 flags="$flags -t$bootparam_rootfstype"
37 fi
38 mount $flags $bootparam_root $ROOTFS_DIR
39 else
Patrick Williamsf1e5d692016-03-30 15:21:19 -050040 msg "root '$bootparam_root' doesn't exist."
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041 fi
42 fi
43
44 if [ ! -d $ROOTFS_DIR/dev ]; then
45 fatal "ERROR: There's no '/dev' on rootfs."
46 fi
47
48 info "Switching root to '$ROOTFS_DIR'..."
49
50 debug "Moving /dev, /proc and /sys onto rootfs..."
51 mount --move /dev $ROOTFS_DIR/dev
52 mount --move /proc $ROOTFS_DIR/proc
53 mount --move /sys $ROOTFS_DIR/sys
54
55 cd $ROOTFS_DIR
56 exec switch_root -c /dev/console $ROOTFS_DIR ${bootparam_init:-/sbin/init}
57 else
58 debug "No rootfs has been set"
59 fi
60}