blob: ac0de9f996f83a1b7aae88ef5f61c7e6c43995d0 [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
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011 if [ ! -d $ROOTFS_DIR/dev ]; then
12 fatal "ERROR: There's no '/dev' on rootfs."
13 fi
14
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000015 # Unmount anything that was automounted by busybox via mdev-mount.sh.
16 # We're about to switch_root, and leaving anything mounted will prevent
17 # the next rootfs from modifying the block device. Ignore ROOT_DISK,
18 # if it was set by setup-live, because it'll be mounted over loopback
19 # to ROOTFS_DIR.
20 local dev
21 for dev in /run/media/*; do
22 if mountpoint -q "${dev}" && [ "${dev##*/}" != "${ROOT_DISK}" ]; then
23 umount -f "${dev}" || debug "Failed to unmount ${dev}"
24 fi
25 done
26
Patrick Williamsc124f4f2015-09-15 14:41:29 -050027 info "Switching root to '$ROOTFS_DIR'..."
28
Andrew Geissler615f2f12022-07-15 14:00:58 -050029 debug "Moving basic mounts onto rootfs"
30 for dir in `awk '/\/dev.* \/run\/media/{print $2}' /proc/mounts`; do
31 # Parse any OCT or HEX encoded chars such as spaces
32 # in the mount points to actual ASCII chars
33 dir=`printf $dir`
34 mkdir -p "${ROOTFS_DIR}/media/${dir##*/}"
35 mount -n --move "$dir" "${ROOTFS_DIR}/media/${dir##*/}"
36 done
37
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038 debug "Moving /dev, /proc and /sys onto rootfs..."
39 mount --move /dev $ROOTFS_DIR/dev
40 mount --move /proc $ROOTFS_DIR/proc
41 mount --move /sys $ROOTFS_DIR/sys
42
43 cd $ROOTFS_DIR
44 exec switch_root -c /dev/console $ROOTFS_DIR ${bootparam_init:-/sbin/init}
45 else
46 debug "No rootfs has been set"
47 fi
48}