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