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