97e513
#!/bin/sh
97e513
export PATH=/usr/bin:/usr/sbin
97e513
export SYSTEMD_IN_INITRD=lenient
97e513
97e513
[ -e /proc/mounts ] ||
97e513
	(mkdir -p /proc && mount -t proc -o nosuid,noexec,nodev proc /proc)
97e513
97e513
grep -q '^sysfs /sys sysfs' /proc/mounts ||
97e513
	(mkdir -p /sys && mount -t sysfs -o nosuid,noexec,nodev sysfs /sys)
97e513
97e513
grep -q '^none / ' /proc/mounts || grep -q '^rootfs / ' /proc/mounts && ROOTFS_IS_RAMFS=1
97e513
97e513
if [ -f /proc/device-tree/rtas/ibm,kernel-dump ] || [ -f /proc/device-tree/ibm,opal/dump/mpipl-boot ]; then
97e513
	mkdir /newroot
97e513
	mount -t ramfs ramfs /newroot
97e513
97e513
	if [ $ROOTFS_IS_RAMFS ]; then
97e513
		for FILE in $(ls -A /fadumproot/); do
97e513
			mv /fadumproot/$FILE /newroot/
97e513
		done
97e513
		exec switch_root /newroot /init
97e513
	else
97e513
		mkdir /newroot/sys /newroot/proc /newroot/dev /newroot/run /newroot/oldroot
97e513
97e513
		grep -q '^devtmpfs /dev devtmpfs' /proc/mounts && mount --move /dev /newroot/dev
97e513
		grep -q '^tmpfs /run tmpfs' /proc/mounts && mount --move /run /newroot/run
97e513
		mount --move /sys /newroot/sys
97e513
		mount --move /proc /newroot/proc
97e513
97e513
		cp --reflink=auto --sparse=auto --preserve=mode,timestamps,links -dfr /fadumproot/. /newroot/
97e513
		cd /newroot && pivot_root . oldroot
97e513
97e513
		loop=1
97e513
		while [ $loop ]; do
97e513
			unset loop
97e513
			while read -r _ mp _; do
97e513
				case $mp in
97e513
				/oldroot/*) umount -d "$mp" && loop=1 ;;
97e513
				esac
97e513
			done 
97e513
		done
97e513
		umount -d -l oldroot
97e513
97e513
		exec /init
97e513
	fi
97e513
else
97e513
	exec /init.dracut
97e513
fi