初始化ELF可执行文件的C文件?
C files for init ELF executable?
我有几个问题试图 google 找出答案,但没有成功。因此,将其张贴在这里。预先感谢您的宝贵时间。
linux(我使用 Ubuntu)中生成 init
可执行文件的 C 文件在哪里? init
是如何从内核模块调用的;在到达内核 /boot/vmlinuz
文件后,引导加载程序如何调用 init
模块?
有没有办法追踪哪个函数调用了init
函数?
到目前为止我尝试了什么:试图通过 readelf 和 nm 但无法使用它们追溯到被调用者。
systemd
替换 init
后的引导程序。我了解到首先调用与 udev 和 d-bus 相关的监听套接字;然后每个进程启动并连接到这些套接字。但我需要清楚地了解系统的工作原理。
如有需要请帮我指出相关链接。我已经提到的几个链接是:
- https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/s2-boot-init-shutdown-init.html
- https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Installation_Guide/ch-boot-init-shutdown.html
但是他们解释的方式很抽象
Where are the C files available in linux(I use Ubuntu) that generate init executable?
这取决于哪个包提供了 init
可执行文件。在默认的 Ubuntu Utopic 安装中,/sbin/init
是指向 /sbin/upstart
的符号链接,因此您需要找到 upstart
的源代码。使用您最喜欢的搜索引擎进行简单搜索可能会将您指向 the Upstart page,其中包括指向源下载和 VCS 存储库的链接。
您还可以使用 apt-get source
命令下载特定包的源代码。您还需要安装 dpkg-dev
软件包 (apt-get install dpkg-dev
),之后您可以 运行:
apt-get source upstart
之后你将拥有:
root@ubuntu:~# ls upstart-1.13.2/
ABOUT-NLS config.guess contrib extra ltmain.sh po TODO
aclocal.m4 config.h.in COPYING HACKING m4 README util
AUTHORS config.rpath dbus init Makefile.am README.tests
ChangeLog config.sub debian INSTALL Makefile.in scripts
compile configure depcomp install-sh missing test
conf configure.ac doc lib NEWS test-driver
在 Ubuntu Vivid 上,/sbin/init
是 /lib/systemd/systemd
的符号链接,因此您需要获得 systemd sources.
请注意,upstart 和 systemd 的运行方式与旧版 /sbin/init
系统有很大不同。上述链接中的文档描述了每个系统的运行方式。
How is the init called from the kernel module; how does the bootloader call init module after reaching out to the kernel /boot/vmlinuz file?
引导加载程序不调用 init
。引导加载程序加载并执行内核。
Is there a way to trace which function calls init function? What I tried so far: Tried to go through readelf and nm but couldn't trace back to the callee using them.
我不清楚你想在这里做什么。内核调用 /sbin/init
。也许 this question 是相关的。
Boot procedure after systemd replacing init. I came to an understanding that the listening sockets are invoked first related to udev and d-bus; and then every process kick starts and get connections to these sockets. But I needed clarity in understanding how the system works.
正如我之前所说,systemd 并没有取代 init,而是取代了 upstart,以及 upstart 替换了 init。希望 systemd 网站上提供的文档能够帮助您了解其工作原理。如果不是,如果您针对不清楚或未按您认为应有的行为提出问题,您可能会得到更好的答案。
我对你的问题有点困惑,因为你指的是 "init function" 和 "init elf executable"。
我会给你参考 linux 内核源代码,因为这些问题在代码中很容易回答:
init 在启动时由内核直接调用 start_kernel
然后调用 rest_init which creates the init process execution thread and the init process task structure. The init thread begins execution in the kernel at kernel_init which quickly calls run_init_process 调用 do_execve(相当于 execve 的内核)。在调用 do_execve 之后,init 进程已经启动。
我有几个问题试图 google 找出答案,但没有成功。因此,将其张贴在这里。预先感谢您的宝贵时间。
linux(我使用 Ubuntu)中生成
init
可执行文件的 C 文件在哪里?init
是如何从内核模块调用的;在到达内核/boot/vmlinuz
文件后,引导加载程序如何调用init
模块?有没有办法追踪哪个函数调用了
init
函数? 到目前为止我尝试了什么:试图通过 readelf 和 nm 但无法使用它们追溯到被调用者。systemd
替换init
后的引导程序。我了解到首先调用与 udev 和 d-bus 相关的监听套接字;然后每个进程启动并连接到这些套接字。但我需要清楚地了解系统的工作原理。
如有需要请帮我指出相关链接。我已经提到的几个链接是:
- https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/s2-boot-init-shutdown-init.html
- https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Installation_Guide/ch-boot-init-shutdown.html
但是他们解释的方式很抽象
Where are the C files available in linux(I use Ubuntu) that generate init executable?
这取决于哪个包提供了 init
可执行文件。在默认的 Ubuntu Utopic 安装中,/sbin/init
是指向 /sbin/upstart
的符号链接,因此您需要找到 upstart
的源代码。使用您最喜欢的搜索引擎进行简单搜索可能会将您指向 the Upstart page,其中包括指向源下载和 VCS 存储库的链接。
您还可以使用 apt-get source
命令下载特定包的源代码。您还需要安装 dpkg-dev
软件包 (apt-get install dpkg-dev
),之后您可以 运行:
apt-get source upstart
之后你将拥有:
root@ubuntu:~# ls upstart-1.13.2/
ABOUT-NLS config.guess contrib extra ltmain.sh po TODO
aclocal.m4 config.h.in COPYING HACKING m4 README util
AUTHORS config.rpath dbus init Makefile.am README.tests
ChangeLog config.sub debian INSTALL Makefile.in scripts
compile configure depcomp install-sh missing test
conf configure.ac doc lib NEWS test-driver
在 Ubuntu Vivid 上,/sbin/init
是 /lib/systemd/systemd
的符号链接,因此您需要获得 systemd sources.
请注意,upstart 和 systemd 的运行方式与旧版 /sbin/init
系统有很大不同。上述链接中的文档描述了每个系统的运行方式。
How is the init called from the kernel module; how does the bootloader call init module after reaching out to the kernel /boot/vmlinuz file?
引导加载程序不调用 init
。引导加载程序加载并执行内核。
Is there a way to trace which function calls init function? What I tried so far: Tried to go through readelf and nm but couldn't trace back to the callee using them.
我不清楚你想在这里做什么。内核调用 /sbin/init
。也许 this question 是相关的。
Boot procedure after systemd replacing init. I came to an understanding that the listening sockets are invoked first related to udev and d-bus; and then every process kick starts and get connections to these sockets. But I needed clarity in understanding how the system works.
正如我之前所说,systemd 并没有取代 init,而是取代了 upstart,以及 upstart 替换了 init。希望 systemd 网站上提供的文档能够帮助您了解其工作原理。如果不是,如果您针对不清楚或未按您认为应有的行为提出问题,您可能会得到更好的答案。
我对你的问题有点困惑,因为你指的是 "init function" 和 "init elf executable"。
我会给你参考 linux 内核源代码,因为这些问题在代码中很容易回答: init 在启动时由内核直接调用 start_kernel 然后调用 rest_init which creates the init process execution thread and the init process task structure. The init thread begins execution in the kernel at kernel_init which quickly calls run_init_process 调用 do_execve(相当于 execve 的内核)。在调用 do_execve 之后,init 进程已经启动。