0

I have a few questions that I have tried to google to find out but in vain. Hence, posting it here. Thanks in advance for your time.

  1. Where are the C files available in linux(I use Ubuntu) that generate init executable? 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?

  2. 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.

  3. 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.

Please help me point out to relevant links if necessary. Few links that I already referred are:

But the way they explain are very abstract.

Tlacenka
  • 520
  • 9
  • 15
Adit Ya
  • 731
  • 1
  • 8
  • 19
  • 2
    This question is way too broad. Consider splitting it into multiple questions in order to get better answers. – larsks Aug 28 '15 at 13:22
  • Almost every query is covered below, I shall start other thread for the last query as suggested. Marking it as closed with the last updated answer as complete. – Adit Ya Sep 04 '15 at 07:06

2 Answers2

0

Where are the C files available in linux(I use Ubuntu) that generate init executable?

It depends which package provides the init executable. In a default Ubuntu Utopic install, /sbin/init is a symlink to /sbin/upstart, so you would want to find the source to upstart. A simple search with your favorite search engine will probably point you to the Upstart page, which includes links to source downloads and the VCS repository.

You can also use the apt-get source command to download the sources for a particular package. You also need the dpkg-dev package installed (apt-get install dpkg-dev), after which you can run:

apt-get source upstart

After which you will have:

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

On Ubuntu Vivid, /sbin/init is a symlink to /lib/systemd/systemd, so you will want to get the systemd sources.

Note that both upstart and systemd operate very different from the legacy /sbin/init system. The documentation at the above links describes how each system operates.

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?

The bootloader doesn't call init. The bootloader loads and executes the kernel.

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.

I'm not clear what you're trying to do here. The kernel calls /sbin/init. Maybe this question is relevant.

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.

As I said earlier, systemd didn't replace init, it replaced upstart, and upstart replaced init. Hopefully the documentation available at the systemd web site is able to help you understand how things work. If not, you will probably get better answers if you ask questions about specific things that are unclear or not behaving as you think they should.

Community
  • 1
  • 1
larsks
  • 277,717
  • 41
  • 399
  • 399
  • Thanks a ton for getting clarity in few of the topics mentioned. @larsks .. Regarding, "The bootloader doesn't call init. The bootloader loads and executes the kernel." -> My question then turns out to be; after kernel gets executed; when is the init binary called. What all gets initiated in the process to invoke init and other userspace applications. If possible please explain it w.r.t. systemd initialization. – Adit Ya Aug 29 '15 at 02:02
0

I'm a little confused by your question since you are referring to the "init function" and the "init elf executable".

I'll give you references to the linux kernel source code, since those kind of questions have easy answers in code: init is called directly by the kernel at boot time start_kernel which then calls 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 which calls do_execve(the kernel equivalent of execve). After the call to do_execve the init process has been started.

borisp
  • 180
  • 6