Skip to main content

/sbin/init & rc.sysinit


The /sbin/init Program


The /sbin/init program (also called init) coordinates the rest of the boot process and configures the environment for the user.
When the init command starts, it becomes the parent or grandparent of all of the processes that start up automatically on the system. First, it runs the /etc/rc.d/rc.sysinit script, which sets the environment path, starts swap, checks the file systems, and executes all other steps required for system initialization. For example, most systems use a clock, so rc.sysinit reads the /etc/sysconfig/clock configuration file to initialize the hardware clock. Another example is if there are special serial port processes which must be initialized, rc.sysinit executes the /etc/rc.serial file.
The init command then runs the /etc/inittab script, which describes how the system should be set up in each SysV init runlevel. Runlevels are a state, or mode, defined by the services listed in the SysV /etc/rc.d/rc<x>.d/ directory, where <x> is the number of the runlevel. 
Next, the init command sets the source function library, /etc/rc.d/init.d/functions, for the system, which configures how to start, kill, and determine the PID of a program.
The init program starts all of the background processes by looking in the appropriate rcdirectory for the runlevel specified as the default in /etc/inittab. The rc directories are numbered to correspond to the runlevel they represent. For instance, /etc/rc.d/rc5.d/ is the directory for runlevel 5.
When booting to runlevel 5, the init program looks in the /etc/rc.d/rc5.d/ directory to determine which processes to start and stop.
Below is an example listing of the /etc/rc.d/rc5.d/ directory:
K05innd -> ../init.d/innd 
K05saslauthd -> ../init.d/saslauthd 
K10dc_server -> ../init.d/dc_server 
K10psacct -> ../init.d/psacct 
K10radiusd -> ../init.d/radiusd 
K12dc_client -> ../init.d/dc_client 
K12FreeWnn -> ../init.d/FreeWnn 
K12mailman -> ../init.d/mailman 
K12mysqld -> ../init.d/mysqld 
K15httpd -> ../init.d/httpd 
K20netdump-server -> ../init.d/netdump-server 
K20rstatd -> ../init.d/rstatd 
K20rusersd -> ../init.d/rusersd 
K20rwhod -> ../init.d/rwhod 
K24irda -> ../init.d/irda 
K25squid -> ../init.d/squid 
K28amd -> ../init.d/amd 
K30spamassassin -> ../init.d/spamassassin 
K34dhcrelay -> ../init.d/dhcrelay 
K34yppasswdd -> ../init.d/yppasswdd 
K35dhcpd -> ../init.d/dhcpd 
K35smb -> ../init.d/smb 
K35vncserver -> ../init.d/vncserver 
K36lisa -> ../init.d/lisa 
K45arpwatch -> ../init.d/arpwatch 
K45named -> ../init.d/named 
K46radvd -> ../init.d/radvd 
K50netdump -> ../init.d/netdump 
K50snmpd -> ../init.d/snmpd 
K50snmptrapd -> ../init.d/snmptrapd 
K50tux -> ../init.d/tux 
K50vsftpd -> ../init.d/vsftpd 
K54dovecot -> ../init.d/dovecot 
K61ldap -> ../init.d/ldap 
K65kadmin -> ../init.d/kadmin 
K65kprop -> ../init.d/kprop 
K65krb524 -> ../init.d/krb524 
K65krb5kdc -> ../init.d/krb5kdc 
K70aep1000 -> ../init.d/aep1000 
K70bcm5820 -> ../init.d/bcm5820 
K74ypserv -> ../init.d/ypserv 
K74ypxfrd -> ../init.d/ypxfrd 
K85mdmpd -> ../init.d/mdmpd 
K89netplugd -> ../init.d/netplugd 
K99microcode_ctl -> ../init.d/microcode_ctl 
S04readahead_early -> ../init.d/readahead_early 
S05kudzu -> ../init.d/kudzu 
S06cpuspeed -> ../init.d/cpuspeed 
S08ip6tables -> ../init.d/ip6tables 
S08iptables -> ../init.d/iptables 
S09isdn -> ../init.d/isdn 
S10network -> ../init.d/network 
S12syslog -> ../init.d/syslog 
S13irqbalance -> ../init.d/irqbalance 
S13portmap -> ../init.d/portmap 
S15mdmonitor -> ../init.d/mdmonitor 
S15zebra -> ../init.d/zebra 
S16bgpd -> ../init.d/bgpd 
S16ospf6d -> ../init.d/ospf6d 
S16ospfd -> ../init.d/ospfd 
S16ripd -> ../init.d/ripd 
S16ripngd -> ../init.d/ripngd 
S20random -> ../init.d/random 
S24pcmcia -> ../init.d/pcmcia 
S25netfs -> ../init.d/netfs 
S26apmd -> ../init.d/apmd 
S27ypbind -> ../init.d/ypbind 
S28autofs -> ../init.d/autofs 
S40smartd -> ../init.d/smartd 
S44acpid -> ../init.d/acpid 
S54hpoj -> ../init.d/hpoj 
S55cups -> ../init.d/cups 
S55sshd -> ../init.d/sshd 
S56rawdevices -> ../init.d/rawdevices 
S56xinetd -> ../init.d/xinetd 
S58ntpd -> ../init.d/ntpd 
S75postgresql -> ../init.d/postgresql 
S80sendmail -> ../init.d/sendmail 
S85gpm -> ../init.d/gpm 
S87iiim -> ../init.d/iiim 
S90canna -> ../init.d/canna 
S90crond -> ../init.d/crond 
S90xfs -> ../init.d/xfs 
S95atd -> ../init.d/atd 
S96readahead -> ../init.d/readahead 
S97messagebus -> ../init.d/messagebus 
S97rhnsd -> ../init.d/rhnsd 
S99local -> ../rc.local
As illustrated in this listing, none of the scripts that actually start and stop the services are located in the /etc/rc.d/rc5.d/ directory. Rather, all of the files in /etc/rc.d/rc5.d/ are symbolic links pointing to scripts located in the /etc/rc.d/init.d/ directory. Symbolic links are used in each of the rc directories so that the runlevels can be reconfigured by creating, modifying, and deleting the symbolic links without affecting the actual scripts they reference.
The name of each symbolic link begins with either a K or an S. The K links are processes that are killed on that runlevel, while those beginning with an S are started.
The init command first stops all of the K symbolic links in the directory by issuing the /etc/rc.d/init.d/<command> stop command, where <command> is the process to be killed. It then starts all of the S symbolic links by issuing /etc/rc.d/init.d/<command> start.
Note
After the system is finished booting, it is possible to log in as root and execute these same scripts to start and stop services. For instance, the command /etc/rc.d/init.d/httpd stop stops the Apache HTTP Server.
Each of the symbolic links are numbered to dictate start order. The order in which the services are started or stopped can be altered by changing this number. The lower the number, the earlier it is started. Symbolic links with the same number are started alphabetically.
Note
One of the last things the init program executes is the /etc/rc.d/rc.localfile. This file is useful for system customization. Refer online for more information about using the rc.local file.
After the init command has progressed through the appropriate rc directory for the runlevel, the /etc/inittab script forks an /sbin/mingetty process for each virtual console (login prompt) allocated to the runlevel. Runlevels 2 through 5 have all six virtual consoles, while runlevel 1 (single user mode) has one, and runlevels 0 and 6 have none. The /sbin/mingetty process opens communication pathways to tty devices, sets their modes, prints the login prompt, accepts the user's username and password, and initiates the login process.
In runlevel 5, the /etc/inittab runs a script called /etc/X11/prefdm. The prefdm script executes the preferred X display manager— gdmkdm, or xdm, depending on the contents of the /etc/sysconfig/desktop file.
Once finished, the system operates on runlevel 5 and displays a login screen.
The /etc/rc.d/rc.sysinit script performs many tasks to initialize Linux. rc.sysinit is run by init and is the first step of the startup process. The tasks performed by rc.sysinit include:
  • Sets the hostname.
  • Mounts the proc and system filesystems.
  • Activates SELinux if it is set to enforcing or permissive.
  • Initializes hardware using modprobe to load device drivers.
  • Starting the udev device manager.
  • Sets kernel parameters as defined in /etc/sysctl.conf.
  • Starts RAID arrays and device mapper for LVM devices.
  • Checks the root filesystem and remounts it as read/write.
  • Enables disk quotas if they are defined.
  • Forces fsck to run if the system was shut down uncleanly or if a filesystem has exceeded the time or number of mounts since it was last checked.
  • Mounts the other filesystems defined in /etc/fstab.
  • Starts swapping.
  • Dumps the current contents of the syslog ring buffer into /var/log/dmesg so it will be available later.
As mentioned above rc.sysinit is a script, written in BASH, and that allows you to look at it and analyze the tasks it performs. I suggest that you do so in order to fully understand this part of the startup sequence.

  • rc.sysinit seems to be Red Hat specific and is executed very early in the process. It is executed as one of the first scripts while rc.local is executed later.

Comments

Popular posts from this blog

Interpreting the output of lspci

On Linux, the lspci command lists all PCI devices connected to a host (a computer). Modern computers and PCI devices communicate with each other via PCI Express buses instead of the older Conventional PCI and PCI-X buses since the former buses offer many advantages such as higher throughput rates, smaller physical footprint and native hot plugging functionality. The high performance of the PCI Express bus has also led it to take over the role of other buses such as AGP ; it is also expected that SATA buses too will be replaced by PCI Express buses in the future as solid-state drives become faster and therefore demand higher throughputs from the bus they are attached to (see this article for more on this topic). As a first step, open a terminal and run lspci without any flags (note: lspci may show more information if executed with root privileges): lspci   This is the output I get on my laptop: 00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Co

Boot process hangs at dracut: Switching root

Environment Red Hat Enterprise Linux 6 Issue When server is booting the boot process hangs at  dracut: Switching root , and never displays anything else. Raw device-mapper: ioctl: 4.33.1-ioctl (2015-8-18) initialised: xx-xxxx@redhat.com udev: starting version 147 dracut: Starting plymouth daemon dracut: rd_NO_DM: removing DM RAID activation dracut: rd_NO_MD: removing MD RAID activation scsi0 : ata_piix scsi1 : ata_piix ata1: PATA max MWDMA2 cmd 0x1f0 ctl 0x3f6 bmdma 0xc120 irq 14 ata2: PATA max MWDMA2 cmd 0x170 ctl 0x376 bmdma 0xc128 irq 15 Refined TSC clocksource calibration: 2599.999 MHz. virtio-pci 0000:00:03.0: PCI INT A -> Link[LNKC] -> GSI 11 (level, high) -> IRQ 11 virtio-pci 0000:00:05.0: PCI INT A -> Link[LNKA] -> GSI 10 (level, high) -> IRQ 10 virtio-pci 0000:00:07.0: PCI INT A -> Link[LNKC] -> GSI 11 (level, high) -> IRQ 11 virtio-pci 0000:00:08.0: PCI INT A -> Link[LNKD] -> GSI 11 (level, high) -> IRQ 11 input: ImExPS/2 Gener

How to get the SAN environment information and statistics on AIX, HP-UX, Linux, Solaris, and Windows

How to get the SAN environment information and statistics on AIX, HP-UX, Linux, Solaris, and Windows Description NetBackup SAN Client is supported on the Linux , Solaris, Windows, HP-UX and AIX operating systems.  These environments provide the initiator device driver which can login to the SAN client media server and mount an pseudo   target device “ARCHIVE PYTHON” so that the backup or restore can be use the fiber transport (FT).  If there is an issue in the SAN environment, it is necessary to get the information/statistics from the SAN fabric for analysis.  The commands below can be used, on the respective operating system, to gather the necessary information. If the outputs show many or steadily increasing error counts, that indicates one or more issues with  the fabric  infrastructure. The issue(s) can be caused by cabling, SFP, san switch, DWDM, HBA or ISL and those components will need to be analyzed and evaluated.  Linux Get the hardware information fo