免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: seer_lz
打印 上一主题 下一主题

系统启动脚本执行失败?求助! [复制链接]

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
11 [报告]
发表于 2008-06-30 11:04 |只看该作者
有可能是kernel要重新配置一下,然后才可以用,具体怎么做我也不知道了,得具体的看一看才知道

论坛徽章:
0
12 [报告]
发表于 2008-07-01 10:08 |只看该作者

回复 #10 seer_lz 的帖子

谁能先回答我:系统启动后是什么时候把文件系统copy到RAM里面的???

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
13 [报告]
发表于 2008-07-01 11:03 |只看该作者
Linux是这样的

先找harddisk然后启动kernel,然后挂fs,这个fs中有个init

论坛徽章:
0
14 [报告]
发表于 2008-07-01 11:54 |只看该作者

回复 #10 seer_lz 的帖子

谁能先告诉我:系统启动后是什么时候把文件系统拷贝到RAM里面的。

论坛徽章:
0
15 [报告]
发表于 2008-07-01 11:56 |只看该作者

回复 #13 T-bagwell 的帖子

虽然问题还没解决,还是很谢谢你!

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
16 [报告]
发表于 2008-07-01 13:35 |只看该作者
http://www.ibm.com/developerworks/cn/linux/l-linuxboot/

这个连接如果帮不了你,估计就没办法了

  1. Using the initial RAM disk (initrd)
  2. ===================================

  3. Written 1996,2000 by Werner Almesberger <[email]werner.almesberger@epfl.ch[/email]> and
  4.                      Hans Lermen <[email]lermen@fgan.de[/email]>


  5. initrd provides the capability to load a RAM disk by the boot loader.
  6. This RAM disk can then be mounted as the root file system and programs
  7. can be run from it. Afterwards, a new root file system can be mounted
  8. from a different device. The previous root (from initrd) is then moved
  9. to a directory and can be subsequently unmounted.

  10. initrd is mainly designed to allow system startup to occur in two phases,
  11. where the kernel comes up with a minimum set of compiled-in drivers, and
  12. where additional modules are loaded from initrd.

  13. This document gives a brief overview of the use of initrd. A more detailed
  14. discussion of the boot process can be found in [1].


  15. Operation
  16. ---------

  17. When using initrd, the system typically boots as follows:

  18.   1) the boot loader loads the kernel and the initial RAM disk
  19.   2) the kernel converts initrd into a "normal" RAM disk and
  20.      frees the memory used by initrd
  21.   3) if the root device is not /dev/ram0, the old (deprecated)
  22.      change_root procedure is followed. see the "Obsolete root change
  23.      mechanism" section below.
  24.   4) root device is mounted. if it is /dev/ram0, the initrd image is
  25.      then mounted as root
  26.   5) /sbin/init is executed (this can be any valid executable, including
  27.      shell scripts; it is run with uid 0 and can do basically everything
  28.      init can do).
  29.   6) init mounts the "real" root file system
  30.   7) init places the root file system at the root directory using the
  31.      pivot_root system call
  32.   8) init execs the /sbin/init on the new root filesystem, performing
  33.      the usual boot sequence
  34.   9) the initrd file system is removed

  35. Note that changing the root directory does not involve unmounting it.
  36. It is therefore possible to leave processes running on initrd during that
  37. procedure. Also note that file systems mounted under initrd continue to
  38. be accessible.


  39. Boot command-line options
  40. -------------------------

  41. initrd adds the following new options:

  42.   initrd=<path>    (e.g. LOADLIN)

  43.     Loads the specified file as the initial RAM disk. When using LILO, you
  44.     have to specify the RAM disk image file in /etc/lilo.conf, using the
  45.     INITRD configuration variable.

  46.   noinitrd

  47.     initrd data is preserved but it is not converted to a RAM disk and
  48.     the "normal" root file system is mounted. initrd data can be read
  49.     from /dev/initrd. Note that the data in initrd can have any structure
  50.     in this case and doesn't necessarily have to be a file system image.
  51.     This option is used mainly for debugging.

  52.     Note: /dev/initrd is read-only and it can only be used once. As soon
  53.     as the last process has closed it, all data is freed and /dev/initrd
  54.     can't be opened anymore.

  55.   root=/dev/ram0

  56.     initrd is mounted as root, and the normal boot procedure is followed,
  57.     with the RAM disk mounted as root.

  58. Compressed cpio images
  59. ----------------------

  60. Recent kernels have support for populating a ramdisk from a compressed cpio
  61. archive. On such systems, the creation of a ramdisk image doesn't need to
  62. involve special block devices or loopbacks; you merely create a directory on
  63. disk with the desired initrd content, cd to that directory, and run (as an
  64. example):

  65. find . | cpio --quiet -H newc -o | gzip -9 -n > /boot/imagefile.img

  66. Examining the contents of an existing image file is just as simple:

  67. mkdir /tmp/imagefile
  68. cd /tmp/imagefile
  69. gzip -cd /boot/imagefile.img | cpio -imd --quiet

  70. Installation
  71. ------------

  72. First, a directory for the initrd file system has to be created on the
  73. "normal" root file system, e.g.

  74. # mkdir /initrd

  75. The name is not relevant. More details can be found on the pivot_root(2)
  76. man page.

  77. If the root file system is created during the boot procedure (i.e. if
  78. you're building an install floppy), the root file system creation
  79. procedure should create the /initrd directory.

  80. If initrd will not be mounted in some cases, its content is still
  81. accessible if the following device has been created:

  82. # mknod /dev/initrd b 1 250
  83. # chmod 400 /dev/initrd

  84. Second, the kernel has to be compiled with RAM disk support and with
  85. support for the initial RAM disk enabled. Also, at least all components
  86. needed to execute programs from initrd (e.g. executable format and file
  87. system) must be compiled into the kernel.

  88. Third, you have to create the RAM disk image. This is done by creating a
  89. file system on a block device, copying files to it as needed, and then
  90. copying the content of the block device to the initrd file. With recent
  91. kernels, at least three types of devices are suitable for that:

  92. - a floppy disk (works everywhere but it's painfully slow)
  93. - a RAM disk (fast, but allocates physical memory)
  94. - a loopback device (the most elegant solution)

  95. We'll describe the loopback device method:

  96. 1) make sure loopback block devices are configured into the kernel
  97. 2) create an empty file system of the appropriate size, e.g.
  98.     # dd if=/dev/zero of=initrd bs=300k count=1
  99.     # mke2fs -F -m0 initrd
  100.     (if space is critical, you may want to use the Minix FS instead of Ext2)
  101. 3) mount the file system, e.g.
  102.     # mount -t ext2 -o loop initrd /mnt
  103. 4) create the console device:
  104.     # mkdir /mnt/dev
  105.     # mknod /mnt/dev/console c 5 1
  106. 5) copy all the files that are needed to properly use the initrd
  107.     environment. Don't forget the most important file, /sbin/init
  108.     Note that /sbin/init's permissions must include "x" (execute).
  109. 6) correct operation the initrd environment can frequently be tested
  110.     even without rebooting with the command
  111.     # chroot /mnt /sbin/init
  112.     This is of course limited to initrds that do not interfere with the
  113.     general system state (e.g. by reconfiguring network interfaces,
  114.     overwriting mounted devices, trying to start already running demons,
  115.     etc. Note however that it is usually possible to use pivot_root in
  116.     such a chroot'ed initrd environment.)
  117. 7) unmount the file system
  118.     # umount /mnt
  119. 8) the initrd is now in the file "initrd". Optionally, it can now be
  120.     compressed
  121.     # gzip -9 initrd

  122. For experimenting with initrd, you may want to take a rescue floppy and
  123. only add a symbolic link from /sbin/init to /bin/sh. Alternatively, you
  124. can try the experimental newlib environment [2] to create a small
  125. initrd.

  126. Finally, you have to boot the kernel and load initrd. Almost all Linux
  127. boot loaders support initrd. Since the boot process is still compatible
  128. with an older mechanism, the following boot command line parameters
  129. have to be given:

  130.   root=/dev/ram0 rw

  131. (rw is only necessary if writing to the initrd file system.)

  132. With LOADLIN, you simply execute

  133.      LOADLIN <kernel> initrd=<disk_image>
  134. e.g. LOADLIN C:\LINUX\BZIMAGE initrd=C:\LINUX\INITRD.GZ root=/dev/ram0 rw

  135. With LILO, you add the option INITRD=<path> to either the global section
  136. or to the section of the respective kernel in /etc/lilo.conf, and pass
  137. the options using APPEND, e.g.

  138.   image = /bzImage
  139.     initrd = /boot/initrd.gz
  140.     append = "root=/dev/ram0 rw"

  141. and run /sbin/lilo

  142. For other boot loaders, please refer to the respective documentation.

  143. Now you can boot and enjoy using initrd.


  144. Changing the root device
  145. ------------------------

  146. When finished with its duties, init typically changes the root device
  147. and proceeds with starting the Linux system on the "real" root device.

  148. The procedure involves the following steps:
  149. - mounting the new root file system
  150. - turning it into the root file system
  151. - removing all accesses to the old (initrd) root file system
  152. - unmounting the initrd file system and de-allocating the RAM disk

  153. Mounting the new root file system is easy: it just needs to be mounted on
  154. a directory under the current root. Example:

  155. # mkdir /new-root
  156. # mount -o ro /dev/hda1 /new-root

  157. The root change is accomplished with the pivot_root system call, which
  158. is also available via the pivot_root utility (see pivot_root(8) man
  159. page; pivot_root is distributed with util-linux version 2.10h or higher
  160. [3]). pivot_root moves the current root to a directory under the new
  161. root, and puts the new root at its place. The directory for the old root
  162. must exist before calling pivot_root. Example:

  163. # cd /new-root
  164. # mkdir initrd
  165. # pivot_root . initrd

  166. Now, the init process may still access the old root via its
  167. executable, shared libraries, standard input/output/error, and its
  168. current root directory. All these references are dropped by the
  169. following command:

  170. # exec chroot . what-follows <dev/console >dev/console 2>&1

  171. Where what-follows is a program under the new root, e.g. /sbin/init
  172. If the new root file system will be used with udev and has no valid
  173. /dev directory, udev must be initialized before invoking chroot in order
  174. to provide /dev/console.

  175. Note: implementation details of pivot_root may change with time. In order
  176. to ensure compatibility, the following points should be observed:

  177. - before calling pivot_root, the current directory of the invoking
  178.    process should point to the new root directory
  179. - use . as the first argument, and the _relative_ path of the directory
  180.    for the old root as the second argument
  181. - a chroot program must be available under the old and the new root
  182. - chroot to the new root afterwards
  183. - use relative paths for dev/console in the exec command

  184. Now, the initrd can be unmounted and the memory allocated by the RAM
  185. disk can be freed:

  186. # umount /initrd
  187. # blockdev --flushbufs /dev/ram0

  188. It is also possible to use initrd with an NFS-mounted root, see the
  189. pivot_root(8) man page for details.


  190. Usage scenarios
  191. ---------------

  192. The main motivation for implementing initrd was to allow for modular
  193. kernel configuration at system installation. The procedure would work
  194. as follows:

  195.   1) system boots from floppy or other media with a minimal kernel
  196.      (e.g. support for RAM disks, initrd, a.out, and the Ext2 FS) and
  197.      loads initrd
  198.   2) /sbin/init determines what is needed to (1) mount the "real" root FS
  199.      (i.e. device type, device drivers, file system) and (2) the
  200.      distribution media (e.g. CD-ROM, network, tape, ...). This can be
  201.      done by asking the user, by auto-probing, or by using a hybrid
  202.      approach.
  203.   3) /sbin/init loads the necessary kernel modules
  204.   4) /sbin/init creates and populates the root file system (this doesn't
  205.      have to be a very usable system yet)
  206.   5) /sbin/init invokes pivot_root to change the root file system and
  207.      execs - via chroot - a program that continues the installation
  208.   6) the boot loader is installed
  209.   7) the boot loader is configured to load an initrd with the set of
  210.      modules that was used to bring up the system (e.g. /initrd can be
  211.      modified, then unmounted, and finally, the image is written from
  212.      /dev/ram0 or /dev/rd/0 to a file)
  213.   8) now the system is bootable and additional installation tasks can be
  214.      performed

  215. The key role of initrd here is to re-use the configuration data during
  216. normal system operation without requiring the use of a bloated "generic"
  217. kernel or re-compiling or re-linking the kernel.

  218. A second scenario is for installations where Linux runs on systems with
  219. different hardware configurations in a single administrative domain. In
  220. such cases, it is desirable to generate only a small set of kernels
  221. (ideally only one) and to keep the system-specific part of configuration
  222. information as small as possible. In this case, a common initrd could be
  223. generated with all the necessary modules. Then, only /sbin/init or a file
  224. read by it would have to be different.

  225. A third scenario is more convenient recovery disks, because information
  226. like the location of the root FS partition doesn't have to be provided at
  227. boot time, but the system loaded from initrd can invoke a user-friendly
  228. dialog and it can also perform some sanity checks (or even some form of
  229. auto-detection).

  230. Last not least, CD-ROM distributors may use it for better installation
  231. from CD, e.g. by using a boot floppy and bootstrapping a bigger RAM disk
  232. via initrd from CD; or by booting via a loader like LOADLIN or directly
  233. from the CD-ROM, and loading the RAM disk from CD without need of
  234. floppies.


  235. Obsolete root change mechanism
  236. ------------------------------

  237. The following mechanism was used before the introduction of pivot_root.
  238. Current kernels still support it, but you should _not_ rely on its
  239. continued availability.

  240. It works by mounting the "real" root device (i.e. the one set with rdev
  241. in the kernel image or with root=... at the boot command line) as the
  242. root file system when linuxrc exits. The initrd file system is then
  243. unmounted, or, if it is still busy, moved to a directory /initrd, if
  244. such a directory exists on the new root file system.

  245. In order to use this mechanism, you do not have to specify the boot
  246. command options root, init, or rw. (If specified, they will affect
  247. the real root file system, not the initrd environment.)
  248.   
  249. If /proc is mounted, the "real" root device can be changed from within
  250. linuxrc by writing the number of the new root FS device to the special
  251. file /proc/sys/kernel/real-root-dev, e.g.

  252.   # echo 0x301 >/proc/sys/kernel/real-root-dev

  253. Note that the mechanism is incompatible with NFS and similar file
  254. systems.

  255. This old, deprecated mechanism is commonly called "change_root", while
  256. the new, supported mechanism is called "pivot_root".


  257. Mixed change_root and pivot_root mechanism
  258. ------------------------------------------

  259. In case you did not want to use root=/dev/ram0 to trigger the pivot_root
  260. mechanism, you may create both /linuxrc and /sbin/init in your initrd image.

  261. /linuxrc would contain only the following:

  262. #! /bin/sh
  263. mount -n -t proc proc /proc
  264. echo 0x0100 >/proc/sys/kernel/real-root-dev
  265. umount -n /proc

  266. Once linuxrc exited, the kernel would mount again your initrd as root,
  267. this time executing /sbin/init. Again, it would be the duty of this init
  268. to build the right environment (maybe using the root= device passed on
  269. the cmdline) before the final execution of the real /sbin/init.


  270. Resources
  271. ---------

  272. [1] Almesberger, Werner; "Booting Linux: The History and the Future"
  273.     [url]http://www.almesberger.net/cv/papers/ols2k-9.ps.gz[/url]
  274. [2] newlib package (experimental), with initrd example
  275.     [url]http://sources.redhat.com/newlib/[/url]
  276. [3] Brouwer, Andries; "util-linux: Miscellaneous utilities for Linux"
  277.     [url]ftp://ftp.win.tue.nl/pub/linux-local/utils/util-linux/[/url]
复制代码

这个是Linux 里自己带的

[ 本帖最后由 T-bagwell 于 2008-7-1 13:39 编辑 ]

评分

参与人数 1可用积分 +15 收起 理由
bitmilong + 15 不錯不錯鼓勵多多發言交流

查看全部评分

论坛徽章:
0
17 [报告]
发表于 2008-07-01 21:55 |只看该作者
这个问题目前感觉是烧写flash部分和制作cramfs映像的工具的问题。

论坛徽章:
0
18 [报告]
发表于 2008-07-11 09:58 |只看该作者

回复 #17 creatorwu 的帖子

谢谢各位的帮忙,问题已经解决了。其实弄了这么久,结果发现还是时序的问题。对整个系统,就只换了一个型号不一样的nandflash,所以在程序中也只需改动相关的读写nandflash的程序,这里主要有两个地方涉及到读写nandflash:一是CPU在启动后从flash中读取u-boot,另外一个就是驱动mtd从nandflash中读取文件系统,这两部分修改的方法差不多,除了要把地址周期改对外,另外就是要确保读取数据过程中各时序是否工作正常,如果不正常怎会造成读取数据的错误,所以这很重要。这些差不多就是我的总结了,其实说到底还是没有把资料看好。之前所参考的资料和使用的nandflash的类型有些不一致。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP