• switch_root 过程错误分析


    ~ # switch_root
    BusyBox v1.18.3 (2011-02-23 16:15:41 CST) multi-call binary.

    Usage: switch_root [-c /dev/console] NEW_ROOT NEW_INIT [ARGS]

    Free initramfs and switch to another root fs:
    chroot to NEW_ROOT, delete all in /, move NEW_ROOT to /,
    execute NEW_INIT. PID must be 1. NEW_ROOT must be a mountpoint.

    Options:
            -c DEV  Reopen stdio to DEV after switch

    /下什么都删除了
    proc都没有
    手动执行mount

    / # exec /sbin/switch_root /mnt /linuxrc
    -------------------rcS---------------------
    pwd is /
    mount: no /proc/mounts
    ls: /mnt/dev/pts: No such file or directory
    mount: mounting none on /dev/shm failed: No such file or directory
    mount: mounting none on /dev/pts failed: No such file or directory
    ------------------set runtime env------------------
    1)insmod
    -------------------module.sh---------------------
    r8168 Gigabit Ethernet driver 8.023.00-NAPI loaded
    r8168: mcfg == RTL8168E/8111E (0014)
    r8168 0000:00:01.0: no MSI. Back to INTx.
    eth%d: RTL8168B/8111B at 0xc098c000, 00:00:00:00:00:00, IRQ 9
    r8168: This product is covered by one or more of the following patents: US5,307,459, US5,434,872, US5,732,094, US6,570,884, US6,115,776, and US6,327,625.
    r8168: lzm: eth1: Identified chip type is 'RTL8168E/8111E'.
    r8168  Copyright (C) 2011  Realtek NIC software team <nicfae@realtek.com>
    This program comes with ABSOLUTELY NO WARRANTY; for details, please see <http://www.gnu.org/licenses/>.
    This is free software, and you are welcome to redistribute it under certain conditions; see <http://www.gnu.org/licenses/>.
    r8168: eth1: link down
    -------------------module.sh end---------------------------
    2)net
    -------------------net.sh---------------------
    configuring Ethernet...
    -------------------net.sh end---------------------------
    3)start telnetd
    -------------------netfactory.sh---------------------
    downloading mvqt.zip...
    Connecting to 192.168.73.13 (192.168.73.13:80)
    wget: can't connect to remote host (192.168.73.13): Connection refused
    Connecting to 192.168.12.104 (192.168.12.104:80)
    wget: can't connect to remote host (192.168.12.104): No route to host
    download failed!
    reload inittab
    -------------------------------------------------
    -------------------sata.sh---------------------
    mount: mounting none on /proc/bus/usb failed: Device or resource busy
    PART is sda
    mount device /dev/sda1 !
    mount: mounting /dev/sda1 on /opt/qtmarvell failed: No such file or directory
    mount device /dev/sda1 failed!
    dummy
    dummy not exit!
    -------------------------------------------------
    ------------------rcS end---------------------
    can't open /dev/tty1: No such file or directory
    can't open /dev/tty2: No such file or directory
    can't open /dev/tty3: No such file or directory
    can't open /dev/tty4: No such file or directory
    can't open /dev/tty5: No such file or directory
    can't open /dev/tty6: No such file or directory
    can't open /dev/ttyS0: No such file or directory

    switchroot之前 exec进入sh看:
    / # cat /proc/sys/kernel/hotplug
    /sbin/hotplug

    mount
    rootfs on / type rootfs (rw)
    proc on /proc type proc (rw,relatime)
    sysfs on /sys type sysfs (rw,relatime)
    /dev/sda1 on /mnt type ext3 (rw,relatime,errors=continue,data=writeback)

    插入u盘
    fdisk 看不到sdb相关
    dev节点也没有sdb
    但是mdev -s之后都出现了

    / # mdev
    BusyBox v1.18.3 (2011-02-23 16:15:41 CST) multi-call binary.

    Usage: mdev [-s]

            -s      Scan /sys and populate /dev during system boot

    It can be run by kernel as a hotplug helper. To activate it:
    echo /sbin/mdev > /proc/sys/kernel/hotplug
    It uses /etc/mdev.conf with lines
    [-]DEVNAME UID:GID PERM [>|=PATH] [@|$|*PROG]

    echo /sbin/mdev > /proc/sys/kernel/hotplug 之后,拔插会自动创建删除sdb节点
    echo /sbin/hotplug > /proc/sys/kernel/hotplug之后,再把u盘拔了, fdisk -l看不到,但是/dev/sdb节点还在,猜测fdisk读的是/sys目录

    看busybox的util-linux中fdisk和switchroot
    发现fdisk -l读取的是/proc/partitions

    ---------------------------------------------------------------------------------------

    switchroot之后exec进入sh看:
    发现进入了新的根文件系统
    / # mount
    mount: no /proc/mounts
    / # mount -t proc proc /proc
    mount: mounting proc on /proc failed: No such file or directory
    所以rcS中必须创建相应目录
    / # mount -a
    mount: mounting none on /dev/shm failed: No such file or directory
    mount: mounting none on /dev/pts failed: No such file or directory
    分析原因:fstab按顺挂载,挂载到/dev目录时候把/dev下的shm和pts覆盖了,所以最好不用mount -a,而用手动创建目录并挂载,比较保险。
    / # cat etc/fstab
    #dev mount-point type   opt
    proc    /proc   proc    defaults    0   0
    tmpfs   /tmp    tmpfs   defaults    0   0
    sysfs   /sys    sysfs   defaults    0   0
    tmpfs   /dev    tmpfs   defaults        0       0
    none    /proc/bus/usb   usbfs   defaults        0       0
    none    /dev/shm        tmpfs   defaults        0       0
    none    /dev/pts        devpts  defaults        0   0

    todo:http://wolfwings.livejournal.com/228442.html

    /bin/busybox umount /proc
    /bin/busybox umount /sys
    
    # And finally... switch to the new root filesystem:
    exec /bin/busybox switch_root /newroot /sbin/init
    
    # Oh-shit panic code, to drop us to a minimal busybox shell to examine the wreckage:
    echo Failure! Press enter to boot a shell instead...
    read
    exec /bin/busybox sh > /dev/tty1 < /dev/tty1 2>&1
  • 相关阅读:
    软件工程个人作业02
    第三周学习进度条
    《构建之法》阅读笔记01
    第二周学习进度条
    软件工程个人作业01
    大道至简第三章读后感
    动手动脑课后实践
    JAVA数字想加并输出
    大道至简第二章读后感
    大道至简读后感
  • 原文地址:https://www.cnblogs.com/cute/p/2096297.html
Copyright © 2020-2023  润新知