免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3024 | 回复: 2
打印 上一主题 下一主题

[文件系统] linuxrc疑问 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-04-10 14:27 |只看该作者 |倒序浏览
这个文件是编译busybox产生的,链接到busybox,我想知道这个文件到底做了什么,对应busybox里的哪块源码?我在网上找到了这段话:
摘自linux kernel Documentation:
When using initrd, the system typically boots as follows:
  1) the boot loader loads the kernel and the initial RAM disk
  2) the kernel converts initrd into a "normal" RAM disk and
     frees the memory used by initrd
  3) initrd is mounted read-write as root
  4) /linuxrc is executed (this can be any valid executable, including
     shell scripts; it is run with uid 0 and can do basically everything
     init can do)
  5) linuxrc mounts the "real" root file system
  6) linuxrc places the root file system at the root directory using the
     pivot_root system call
  7) the usual boot sequence (e.g. invocation of /sbin/init) is performed
     on the root file system

我不理解其中的“linuxrc mounts the "real" root file system”,可能这是老的内核里linuxrc的作用。我看了一下2.6的内核源码,无论是initrd方式还是initramfs方式启动,都是由虚拟文件系统去挂载了真正的文件系统之后,再把linuxrc当做一个文件去执行,可以说是它是文件系统最早执行的文件,但这么做的目的是什么,虽然我们可以自己改写linuxrc,可这个文件最初是由busybox生成的,busybox想拿它来做什么。网上有人说它的作用相当于/sbin/init,但/sbin/init是在内核挂载了真正的文件系统之后启动的应用程序,linuxrc是的执行在这之前,两者的作用不应该一样吧?
而且我试着把yaffs2文件系统的linuxrc文件给删除了,文件系统照样能正常启动。后来我又看了一下ubi的文件系统,压根就没有linuxrc这个文件了。为什么会这样?是不是新的内核和文件系统已经不需要这个文件了

说的比较多,也比较凌乱,求知道的大神给解释一下。

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:58:11
2 [报告]
发表于 2015-04-10 16:26 |只看该作者
本帖最后由 arm-linux-gcc 于 2015-04-10 17:03 编辑

/sbin/init也是在initramfs或initrd里,整个busybox全都在里面

linuxrc会被当作init来使用,在busybox中有
./include/applets.h:92:IF_FEATURE_INITRD(APPLET_ODDNAME(linuxrc, init, BB_DIR_ROOT, BB_SUID_DROP, linuxrc))
所以有没有linuxrc都没有关系,反正只要有/sbin/init就行了


要使用linuxrc,就必须在cmdline里添加init=/linuxrc,如果有了这个,就不会再去执行/sbin/init了
所以不存在你说的先执行linuxrc再执行init的情况



linuxrc mounts the "real" root file system,这句话的意思是/sbin/init会去读取fstab,fstab里面就是有/dev/mmcblk0p2

论坛徽章:
0
3 [报告]
发表于 2015-04-11 23:29 |只看该作者
回复 2# arm-linux-gcc
兄弟太强大了,几句话就把让我抓耳挠腮的疑问解决了

   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP