/init:
#!/bin/sh
/bin/busybox echo "start initramfs do any init"
/bin/busybox mount -t proc none /proc
/bin/busybox mount -t sysfs none /sys
/bin/busybox mount -t tmpfs none /dev
/bin/busybox mount -t tmpfs none /var
/bin/busybox mount -t tmpfs none /tmp
/bin/busybox mkdir -p /sys_root
/bin/busybox mdev -s
REAL_BOOTINIT=init
for arg in $(/bin/busybox cat /proc/cmdline); do
case $arg in
boot=*)
REAL_ROOT="${arg#*=}"
;;
bootfstype=*)
REAL_ROOTTYPE="${arg#*=}"
;;
bootinit=*)
REAL_BOOTINIT="${arg#*=}"
;;
bootinitarg=*)
REAL_BOOTINIT_ARG="${arg#*=}"
;;
bootinitunit=*)
REAL_BOOTINIT_UNIT="${arg#*=}"
;;
esac
done
if [ ! -z $REAL_ROOT ] && [ ! -z $REAL_ROOTTYPE ]; then
/bin/busybox mount -t $REAL_ROOTTYPE $REAL_ROOT /sys_root
if [ -e /sys_root/$REAL_BOOTINIT ]; then
/bin/busybox mount --move /dev /sys_root/dev
/bin/busybox mount --move /proc /sys_root/proc
/bin/busybox mount --move /tmp /sys_root/tmp
/bin/busybox mount --move /sys /sys_root/sys
/bin/busybox mount --move /var /sys_root/var
# exec /bin/busybox switch_root /sys_root $REAL_BOOTINIT $REAL_BOOTINIT_ARG $REAL_BOOTINIT_UNIT
exec /bin/busybox switch_root /sys_root $REAL_BOOTINIT $REAL_BOOTINIT_ARG $REAL_BOOTINIT_UNIT
fi
fi
/bin/busybox echo "switch root error!!!"
exec /bin/busybox init
执行流程是从这个脚本去挂载实际的分区 然后再找分区的可执行文件 switch root
找不到就切回自己的busybox
uboot的环境变量记得要把几个参数设置进去
我是在 bootargs 里加了 boot=/dev/mmcblk0p2 bootfstype=ext4 bootinit=lib/systemd/systemd
bootinit需要换成你自己的根文件系统的init
离线