现在的位置: 首页 > 综合 > 正文

init脚本

2012年10月24日 ⁄ 综合 ⁄ 共 676字 ⁄ 字号 评论关闭

#!/bin/sh
echo "init..."
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mdev -s

newroot=`findfs LABEL=ROOT`

cleanmntdir()
{
    rm -rf /mnt/*
}

copyroot()
{
    FILES=`ls /`
    for F in $FILES
    do
        [ $F != 'mnt' ] && [ $F != 'proc' ] && [ $F != 'sys' ] && cp -a $F /mnt
    done
}

if [ "$?" = 0 ]
then
    echo "findfs find newroot=$newroot"
    mount $newroot /mnt
    if [ "$?" = 0 ]
    then
        echo "mount $newroot on /mnt"
        #if [ ! -x "/mnt/linuxrc" ]; then
        #   echo "No init found. cp rootfs..."
    #       copyroot
        #fi
        cleanmntdir
        copyroot
        umount /proc
        umount /sys
        echo "switch_root..."
#       exec /sbin/switch_root /mnt /linuxrc -c /dev/tty1
        exec /bin/sh
    fi
fi

echo "no ROOT found! enter factory boot..."
exec /linuxrc

抱歉!评论已关闭.