2

我有一个嵌入式设备,我想在其中覆盖 rootfs。到目前为止,我的 initramfs 脚本如下所示:

#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
mount -t proc proc /proc
mount -t devtmpfs none /dev
mount -t sysfs sysfs /sys

rootdev_ro=""
rootdev_rw=""
factory_reset=""

[ ! -f /etc/platform-preboot ] || . /etc/platform-preboot

if [ -z "$rootdev_ro" ]; then
    for bootarg in `cat /proc/cmdline`; do
    echo "${bootarg}"
    arg=`expr "x$bootarg" : 'x[^=]*=\(.*\)' || echo ''`

    case "$bootarg" in
        root=*) rootdev_ro="${arg}" ;;
        rootrw=*) rootdev_rw="${arg}" ;;
        factoryreset=*) factory_reset="yes";;
    esac
    done
fi

mkdir -p /mnt/lowerdev
mkdir -p /mnt/overlaydev
mkdir -p /mnt/overlay

mount -t ext4 -o "ro" "${rootdev_ro}" /mnt/lowerdev
mount -t ext4 -o "rw" "${rootdev_rw}" /mnt/overlaydev

# Here's factory reset
if [ "$factoryreset" == "yes" ]; then
    echo "Applying factory defaults..."    
    rm -fr /mnt/overlaydev/*
fi

# Upper and work folders must be on the same mount
mkdir -p /mnt/overlaydev/upper
mkdir -p /mnt/overlaydev/work

mount -t overlay overlay -o lowerdir=/mnt/lowerdev,upperdir=/mnt/overlaydev/upper,workdir=/mnt/overlaydev/work /mnt/overlay

echo "Switching to rootfs on overlay..."
mount --move /sys  /mnt/overlay/sys
mount --move /proc /mnt/overlay/proc
mount --move /dev  /mnt/overlay/dev

exec switch_root /mnt/overlay /sbin/init 

覆盖在那里工作得很好,但我希望能够更改lowerdir文件/boot/extlinux/extlinux.conf上的内核初始化引导参数,以便在需要时添加factoryreset参数。

如果我在系统运行修改文件时尝试挂载lowerdir分区,我得到一个错误

already mounted or mount point busy

是否可以指定 lowerdir 以排除 /boot 目录,还是必须一一覆盖文件夹?

4

0 回答 0