summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/initrdscripts/initramfs-framework/finish
blob: f08a9208675307d7ae0ed06aa1c1d9b892d1b5cd (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
#!/bin/sh
# Copyright (C) 2011 O.S. Systems Software LTDA.
# Licensed on MIT

finish_enabled() {
	return 0
}

finish_run() {
	if [ -n "$ROOTFS_DIR" ]; then
		if [ ! -d $ROOTFS_DIR/dev ]; then
			fatal "ERROR: There's no '/dev' on rootfs."
		fi

		# Unmount anything that was automounted by busybox via mdev-mount.sh.
		# We're about to switch_root, and leaving anything mounted will prevent
		# the next rootfs from modifying the block device.  Ignore ROOT_DISK,
		# if it was set by setup-live, because it'll be mounted over loopback
		# to ROOTFS_DIR.
		local dev
		for dev in /run/media/*; do
			if mountpoint -q "${dev}" && [ "${dev##*/}" != "${ROOT_DISK}" ]; then
				umount -f "${dev}" || debug "Failed to unmount ${dev}"
			fi
		done

		info "Switching root to '$ROOTFS_DIR'..."

		debug "Moving /dev, /proc and /sys onto rootfs..."
		mount --move /dev $ROOTFS_DIR/dev
		mount --move /proc $ROOTFS_DIR/proc
		mount --move /sys $ROOTFS_DIR/sys

		cd $ROOTFS_DIR
		exec switch_root -c /dev/console $ROOTFS_DIR ${bootparam_init:-/sbin/init}
	else
		debug "No rootfs has been set"
	fi
}