Linux chroot 并使用之前系统设备节点

/*********************************************************************************
 *                    Linux chroot 并使用之前系统设备节点
 * 说明:
 *     直接使用chroot结果/dev下没有设备,所有有些东西需要提前挂载,在进入chroot。
 *
 *                                       2016-12-30 深圳 南山平山村 曾剑锋
 ********************************************************************************/

一、参考文档:
    1. mount dev, proc, sys in a chroot environment?
        http://superuser.com/questions/165116/mount-dev-proc-sys-in-a-chroot-environment

二、主要Linux Shell命令:
    1. mount /dev/mmcblk0p2 /mnt
    2. mount -t proc proc /mnt/proc
    3. mount -t sysfs sys /mnt/sys
    4. mount -o bind /dev /mnt/dev
    5. chroot /mnt/

三、实际操作及数据:
    [zengjf@root ~]#  df
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/root              3096336    492148   2446904  17% /
    tmpfs                   423848         0    423848   0% /dev/shm
    tmpfs                   423848        32    423816   0% /tmp
    tmpfs                   423848        28    423820   0% /run
    [zengjf@root ~]#  mount /dev/mmcblk0p2 /mnt
    EXT3-fs: barriers not enabled
    kjournald starting.  Commit interval 5 seconds
    EXT3-fs (mmcblk0p2): warning: checktime reached, running e2fsck is recommended
    EXT3-fs (mmcblk0p2): using internal journal
    EXT3-fs (mmcblk0p2): recovery complete
    EXT3-fs (mmcblk0p2): mounted filesystem with writeback data mode
    [zengjf@root ~]#  mount -t proc proc /mnt/proc
    [zengjf@root ~]#  mount -t sysfs sys /mnt/sys
    [zengjf@root ~]#  mount -o bind /dev /mnt/dev
    [zengjf@root ~]#  chroot /mnt/


    BusyBox v1.20.2 () built-in shell (ash)
    Enter 'help' for a list of built-in commands.

    [zengjf@root /]#  ls /dev/
    alarm               ptyr8               tty26               ttyr1
    apm_bios            ptyr9               tty27               ttyr2
    buzzer              ptyra               tty28               ttyr3
    console             ptyrb               tty29               ttyr4
    cpu_dma_latency     ptyrc               tty3                ttyr5
    fb0                 ptyrd               tty30               ttyr6
    fb1                 ptyre               tty31               ttyr7
    fb2                 ptyrf               tty32               ttyr8
    full                ptys0               tty33               ttyr9
    galcore             ptys1               tty34               ttyra
    i2c-0               ptys2               tty35               ttyrb
    i2c-1               ptys3               tty36               ttyrc
    i2c-2               ptys4               tty37               ttyrd
    i2c-3               ptys5               tty38               ttyre
    input               ptys6               tty39               ttyrf
    kmem                ptys7               tty4                ttys0
    kmsg                ptys8               tty40               ttys1
    log                 ptys9               tty41               ttys2
    mem                 ptyt2               tty5                ttysb
    mmcblk0             ptyt3               tty50               ttysc
    mmcblk0boot0        ptyt4               tty51               ttysd
    mmcblk0boot1        ptyt5               tty52               ttyse
    mmcblk0p1           ptyt6               tty53               ttysf
    mmcblk0p2           ptyt7               tty54               ttyt0
    mx6check            ptyt8               tty55               ttyt1
    mxc_asrc            ptyt9               tty56               ttyt2
    mxc_ipu             ptyta               tty57               ttyt3
    mxc_vpu             ptytb               tty58               ttyt4
    mxs_viim            ptytc               tty59               ttyt5
    network_latency     ptytd               tty6                ttyt6
    network_throughput  ptyte               tty60               ttyt7
    null                ptytf               tty61               ttyt8
    ...
    [zengjf@root /]#  ls sys
    block     class     devices   fs        kernel    power
    bus       dev       firmware  fsl_otp   module
    [zengjf@root /]#  ls proc
    1              1474           517            cpuinfo        mounts
    10             1483           524            crypto         mtd
    11             1618           526            devices        net
    1104           1623           530            diskstats      pagetypeinfo
    1198           1624           539            dri            partitions
    1273           1630           540            driver         scsi
    1309           1634           591            execdomains    self
    1315           1637           6              fb             slabinfo
    1320           2              607            filesystems    softirqs
    1321           3              613            fs             stat
    1322           338            639            interrupts     swaps
    1361           340            641            iomem          sys
    1362           342            7              ioports        sysrq-trigger
    1363           376            8              irq            sysvipc
    1382           380            9              kallsyms       timer_list
    1394           391            apm            kmsg           tty
    1395           4              asound         kpagecount     uptime
    1398           414            buddyinfo      kpageflags     version
    1407           415            bus            loadavg        vmallocinfo
    1410           428            cmdline        locks          vmstat
    1455           430            config.gz      meminfo        zoneinfo
    1462           5              consoles       misc
    1469           516            cpu            modules
    [zengjf@root /]#  df
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/root                99150     16976     77054  18% /
    devpts                 3096336    492148   2446904  17% /dev/pts
    tmpfs                  3096336    492148   2446904  17% /dev/shm
    tmpfs                    99150     16976     77054  18% /tmp
    df: /run: No such file or directory
    /dev/mmcblk0p2           99150     16976     77054  18% /
    /dev/root              3096336    492148   2446904  17% /dev
    [zengjf@root /]#  exit
    [zengjf@root ~]#  df
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/root              3096336    492148   2446904  17% /
    tmpfs                   423848         0    423848   0% /dev/shm
    tmpfs                   423848        32    423816   0% /tmp
    tmpfs                   423848        28    423820   0% /run
    /dev/mmcblk0p2           99150     16976     77054  18% /mnt
    /dev/root              3096336    492148   2446904  17% /mnt/dev
    [zengjf@root ~]# 

 

上一篇:Linux虚拟文件系统(节点路径搜索)


下一篇:老话重提:i节点导致系统无法写入