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