init脚本

#!/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

posted on 2011-07-02 15:39  katago  阅读(323)  评论(0编辑  收藏  举报