#!/bin/sh

msg='Moving /dev to the real filesystem...'
run() {
	# Move /dev created in initramfs to the real filesystem if this is enabled
	# in the udev configuration.
	[ -n "$INITRAMFS_DEV" ] ||
		return 0

	# Pass udev version from initramfs to the real system.
	udev_version="$(/sbin/udevd --version 2>/dev/null)"
	printf '%s\n' "${udev_version:-105}" >/dev/.initramfs/udev_version

	# Optionally move the real filesystem's /dev to beneath our tmpfs
	if [ -z "$no_static_dev" ]; then
		mkdir -m 0700 /dev/.static/
		mkdir /dev/.static/dev/
		mount -o bind $rootmnt/dev /dev/.static/dev
	fi

	# Now move it all to the real filesystem
	mount -o move /dev $rootmnt/dev

	# create a temporary symlink to the final /dev for other initramfs
	# scripts
	nuke /dev
	ln -s $rootmnt/dev /dev
}
