您尚未登录。

楼主 #1 2019-11-01 19:15:16

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

@assert 给我的 initramfs 切换到 真实rootfs 切换脚本

/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





离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn