switch_root 過程錯誤分析

來源:互聯網
上載者:User

~ # 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...readexec /bin/busybox sh > /dev/tty1 < /dev/tty1 2>&1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.