chroot

  1. /*********************************************************************************
  2. * Linux chroot 并使用之前系统设备节点
  3. * 说明:
  4. * 直接使用chroot结果/dev下没有设备,所有有些东西需要提前挂载,在进入chroot。
  5. *
  6. * 2016-12-30 深圳 南山平山村 曾剑锋
  7. ********************************************************************************/
  8.  
  9. 一、参考文档:
  10. . mount dev, proc, sys in a chroot environment?
  11. http://superuser.com/questions/165116/mount-dev-proc-sys-in-a-chroot-environment
  12.  
  13. 二、主要Linux Shell命令:
  14. . mount /dev/mmcblk0p2 /mnt
  15. . mount -t proc proc /mnt/proc
  16. . mount -t sysfs sys /mnt/sys
  17. . mount -o bind /dev /mnt/dev
  18. . chroot /mnt/
  19.  
  20. 三、实际操作及数据:
  21. [zengjf@root ~]# df
  22. Filesystem 1K-blocks Used Available Use% Mounted on
  23. /dev/root % /
  24. tmpfs % /dev/shm
  25. tmpfs % /tmp
  26. tmpfs % /run
  27. [zengjf@root ~]# mount /dev/mmcblk0p2 /mnt
  28. EXT3-fs: barriers not enabled
  29. kjournald starting. Commit interval seconds
  30. EXT3-fs (mmcblk0p2): warning: checktime reached, running e2fsck is recommended
  31. EXT3-fs (mmcblk0p2): using internal journal
  32. EXT3-fs (mmcblk0p2): recovery complete
  33. EXT3-fs (mmcblk0p2): mounted filesystem with writeback data mode
  34. [zengjf@root ~]# mount -t proc proc /mnt/proc
  35. [zengjf@root ~]# mount -t sysfs sys /mnt/sys
  36. [zengjf@root ~]# mount -o bind /dev /mnt/dev
  37. [zengjf@root ~]# chroot /mnt/
  38.  
  39. BusyBox v1.20.2 () built-in shell (ash)
  40. Enter ‘help’ for a list of built-in commands.
  41.  
  42. [zengjf@root /]# ls /dev/
  43. alarm ptyr8 tty26 ttyr1
  44. apm_bios ptyr9 tty27 ttyr2
  45. buzzer ptyra tty28 ttyr3
  46. console ptyrb tty29 ttyr4
  47. cpu_dma_latency ptyrc tty3 ttyr5
  48. fb0 ptyrd tty30 ttyr6
  49. fb1 ptyre tty31 ttyr7
  50. fb2 ptyrf tty32 ttyr8
  51. full ptys0 tty33 ttyr9
  52. galcore ptys1 tty34 ttyra
  53. i2c- ptys2 tty35 ttyrb
  54. i2c- ptys3 tty36 ttyrc
  55. i2c- ptys4 tty37 ttyrd
  56. i2c- ptys5 tty38 ttyre
  57. input ptys6 tty39 ttyrf
  58. kmem ptys7 tty4 ttys0
  59. kmsg ptys8 tty40 ttys1
  60. log ptys9 tty41 ttys2
  61. mem ptyt2 tty5 ttysb
  62. mmcblk0 ptyt3 tty50 ttysc
  63. mmcblk0boot0 ptyt4 tty51 ttysd
  64. mmcblk0boot1 ptyt5 tty52 ttyse
  65. mmcblk0p1 ptyt6 tty53 ttysf
  66. mmcblk0p2 ptyt7 tty54 ttyt0
  67. mx6check ptyt8 tty55 ttyt1
  68. mxc_asrc ptyt9 tty56 ttyt2
  69. mxc_ipu ptyta tty57 ttyt3
  70. mxc_vpu ptytb tty58 ttyt4
  71. mxs_viim ptytc tty59 ttyt5
  72. network_latency ptytd tty6 ttyt6
  73. network_throughput ptyte tty60 ttyt7
  74. null ptytf tty61 ttyt8
  75. [zengjf@root /]# ls sys
  76. block class devices fs kernel power
  77. bus dev firmware fsl_otp module
  78. [zengjf@root /]# ls proc
  79. cpuinfo mounts
  80. crypto mtd
  81. devices net
  82. diskstats pagetypeinfo
  83. dri partitions
  84. driver scsi
  85. execdomains self
  86. fb slabinfo
  87. filesystems softirqs
  88. fs stat
  89. interrupts swaps
  90. iomem sys
  91. ioports sysrq-trigger
  92. irq sysvipc
  93. kallsyms timer_list
  94. apm kmsg tty
  95. asound kpagecount uptime
  96. buddyinfo kpageflags version
  97. bus loadavg vmallocinfo
  98. cmdline locks vmstat
  99. config.gz meminfo zoneinfo
  100. consoles misc
  101. cpu modules
  102. [zengjf@root /]# df
  103. Filesystem 1K-blocks Used Available Use% Mounted on
  104. /dev/root % /
  105. devpts % /dev/pts
  106. tmpfs % /dev/shm
  107. tmpfs % /tmp
  108. df: /run: No such file or directory
  109. /dev/mmcblk0p2 % /
  110. /dev/root % /dev
  111. [zengjf@root /]# exit
  112. [zengjf@root ~]# df
  113. Filesystem 1K-blocks Used Available Use% Mounted on
  114. /dev/root % /
  115. tmpfs % /dev/shm
  116. tmpfs % /tmp
  117. tmpfs % /run
  118. /dev/mmcblk0p2 % /mnt
  119. /dev/root % /mnt/dev
  120. [zengjf@root ~]#

把/etc/default/grub 中上面红框中的内容去掉,再执行grub2-mkconfig -o /boot/grub2/grub.cfg。
在grub启动命令行中把resume=xxxxxx去掉。

Leave a Reply

Your email address will not be published. Required fields are marked *