Before Explaining why there is no inittab file in /etc dir in ubuntu, Its better to memorize some basic concepts related to linux. Lets have a look into it.
- BIOS: The Basic Input/Output System is the lowest level interface between the computer and peripherals.
The BIOS performs integrity checks on memory and seeks instructions on the Master Boor Record (MBR) on the floppy drive or hard drive. - The MBR points to the boot loader (GRUB or LILO: Linux boot loader).
- Boot loader (GRUB or LILO) will then ask for the OS label which will
identify which kernel to run and where it is located (hard drive and partition specified).
The installation process requires to creation/identification of partitions and
where to install the OS. GRUB/LILO are also configured during this process.
The boot loader then loads the Linux operating system.
- See the YoLinux tutorial on creating a boot disk for more information on GRUB and LILO and also to learn how to put the MBR and boot loader on a floppy for system recovery.
- The first thing the kernel does is to execute init program. Init is the root/parent of all processes executing on Linux.
- The first processes that init starts is a script /etc/rc.d/rc.sysinit
- Based on the appropriate run-level, scripts are executed to start various processes to run the system and make it functional.
The initab file was not intensionally removed or no magic. Your PC is using the latest version of ubuntu and which is systemd/upstart as a startup init service.
The Linux and Unix SysV heritage began with the "sysvinit" process which used the /etc/inittab configuration file to drive the execution of init scripts and configuration of terminal and GUI interfaces.
Ubuntu 12.04+, 14.04 uses a hybrid system called upstart which includes SysV runlevel specific start scripts in /etc/rc.#/
Systemd is used in later versions of Linux (Fedora 15+, RHEL 7, OpenSUSE 12.1+, ...) which is compatible with Unix SysV and Linux Standard Base (LSB) init scripts. Systemd supports parallelization (faster boot), socket management, process tracking, mounting of file systems and dependency-based service control. Daemon processes are categorized into "cgroups" which have categorized resource limits.
Now all the latest versions of ubuntu as 16.04 using systemd as a init service.
Typical run levels include:
- 0 — Halt
- 1 — Single-user text mode
- 2 — Not used (user-definable)
- 3 — Full multi-user text mode
- 4 — Not used (user-definable)
- 5 — Full multi-user graphical mode (with an X-based login screen)
- 6 — Reboot
Fedora 15-19:
- Set run level 3 (multi-user with networking and console only login):
rm /etc/systemd/system/default.target
ln -sf /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target - Set run level 5 (graphic mode):
rm /etc/systemd/system/default.target
ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
- Run level defined by the services in directory /etc/systemd/system/multi-user.target.wants/
ls -l /etc/systemd/system/multi-user.target.wants/
This will show symbolic links to service files defined in /lib/systemd/system/
Runlevel "3" will boot to text or console mode and "5" will boot to the graphical login mode.
Runlevel Scripts Directory
(Fedora: /lib/systemd/system/)State 0 runlevel0.target , poweroff.target shutdown/halt system 1 runlevel1.target, rescue.target Single user mode 2 runlevel2.target Multiuser with no network services exported 3 runlevel3.target , multi-user.target Default text/console only start. Full multiuser 4 runlevel4.target Reserved for local use. Also X-windows (Slackware/BSD) 5 runlevel5.target, graphical.target XDM X-windows GUI mode 6 runlevel6.target, reboot.target Reboot - Note that the user friendly name is just a symbolic link to the runlevel name:# ls -l /lib/systemd/system/runlevel3.target
lrwxrwxrwx. 1 root root 17 May 24 10:55 /lib/systemd/system/runlevel3.target -> multi-user.target Ubuntu names the directories with an additionaol suffix: ".wants". For example multi-user.target on Fedora would be named multi-user.target.wants for an Ubuntu system.
SysV run levels:
The Linux boot process has six states of operation of which "0" is the shutdown state and "3" and above are fully operational with all essential processes running for user interaction. Upon system boot the LINUX system /sbin/init program starts other processes by performing the following:- Init will bring up the machine by starting processes
as defined in the /etc/inittab file.
- The computer will be booted to the runlevel as defined by the
initdefault directive in the /etc/inittab file.
id:5:initdefault:
- One of these process started by init is /sbin/rc.
This script runs a series of scripts in the directories
/etc/rc.d/rc0.d/, /etc/rc.d/rc1.d/,
/etc/rc.d/rc2.d/, etc
- Scripts in these directories are executed for each boot state of operation until it becomes fully operational. Scripts beginning with S denote startup scripts while scripts beginning with K denote shutdown (kill) scripts. Numbers follow these letters to denote the order of execution. (lowest to highest)
Runlevel "3" will boot to text or console mode and "5" will boot to the graphical login mode ( "4" for slackware)
Runlevel Scripts Directory
(Red Hat/Fedora Core)State 0 /etc/rc.d/rc0.d/ shutdown/halt system 1 /etc/rc.d/rc1.d/ Single user mode 2 /etc/rc.d/rc2.d/ Multiuser with no network services exported 3 /etc/rc.d/rc3.d/ Default text/console only start. Full multiuser 4 /etc/rc.d/rc4.d/ Reserved for local use. Also X-windows (Slackware/BSD) 5 /etc/rc.d/rc5.d/ XDM X-windows GUI mode (Redhat/System V) 6 /etc/rc.d/rc6.d/ Reboot s or S Single user/Maintenance mode (Slackware) M Multiuser mode (Slackware)
The scripts for a given run level are run during boot and shutdown. The scripts are found in the directory /etc/rc.d/rc#.d/ where the symbol # represents the run level. i.e. the run level "3" will run all the scripts in the directory /etc/rc.d/rc3.d/ which start with the letter "S" during system boot. This starts the background processes required by the system. During shutdown all scripts in the directory which begin with the letter "K" will be executed. This system provides an orderly way to bring the system to different states for production and maintenance modes.
If you installed all demons (background processes), Linux will run them all. To avoid slowing down your machine, remove unneeded services from the start-up procedure. You can start/stop individual demons by running service init scripts located in the /etc/init.d/ directory:
- /etc/rc.d/init.d/ (Red Hat/Fedora) Also /etc/init.d/ which is linked to /etc/rc.d/init.d/
- /etc/init.d/ (S.u.s.e.)
- /etc/init.d/ (Ubuntu / Debian)
- /etc/init.d/httpd stop
TIP: List state and run level of all services which can be started by init: chkconfig --list
or
service --status-all | grep running (Red Hat/Fedora Core based systems)
Adding a script to the /etc/rc.d/rc#.d/ directory with either an S or K prefix, adds the script to the boot or shutdown process. The scripts are run in numerical order. S20abc is run before S30xyz. The extensibility to the boot and shutdown procedures of the operating system is one of the strengths of UNIX. The orderly sequential initiation of processes can be coordinated for dependent processes. The orderly shutdown of processes is often required of complex programs such as databases. This is how it is done. Individual processes may be monitored, shutdown and started at any time using these scripts. i.e. /etc/rc.d/rc2.d/httpd start. The modifiers start, stop or status may be used.
The start/stop/status scripts actually reside in the directory:
- /etc/rc.d/init.d/ (Red Hat/Fedora) Also /etc/init.d/ which is linked to /etc/rc.d/init.d/
- /etc/init.d/ (S.u.s.e. and Ubuntu / Debian)
Ubuntu 14.04:
Init scripts are found in /etc/init/ List services which are to be turned on at boot time: grep "start on" /etc/init/*Also see man upstart-events to view events which can be configured.
A single copy of the script is located in the directory: /etc/rc.d/init.d/script-name (Red Hat/Fedora) or /etc/init.d/script-name (Ubuntu / Debian).
Use the command chkconfig to generate soft links to the appropriate directories for the various run levels.
Example: Red Hat
#!/bin/sh # # Startup script for program # # chkconfig: 345 85 15 - start or stop process definition within the boot process # description: Description of program # processname: process-name # pidfile: /var/run/process-name.pid # Source function library.
# This creates the operating environment for the process to be started . /etc/rc.d/init.d/functions case "$1" in start) echo -n "Starting process-name: " daemon process-name - Starts only one process of a given name. echo touch /var/lock/subsys/process-name ;; stop) echo -n "Shutting down process-name: " killproc process-name echo rm -f /var/lock/subsys/process-name rm -f /var/run/process-name.pid - Only if process generates this file ;; status) status process-name ;; restart) $0 stop $0 start ;; reload) echo -n "Reloading process-name: " killproc process-name -HUP echo ;; *) echo "Usage: $0 {start|stop|restart|reload|status}" exit 1 esac exit 0
The bash script functions daemon, killproc and status can all be found in the script /etc/rc.d/init.d/functions. (Red Hat/Fedora distributions)
Example: Ubuntu 14.04
#!/bin/sh ### BEGIN INIT INFO # Provides: apache2 # Required-Start: $local_fs $remote_fs $network $syslog $named # Required-Stop: $local_fs $remote_fs $network $syslog $named # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # X-Interactive: true # Short-Description: Start/stop apache2 web server # Description: Start the web server and associated helpers # This script will start apache2, and possibly all associated instances. # Moreover, it will set-up temporary directories and helper tools such as # htcacheclean when required by the configuration. ### END INIT INFO DESC="description goes here" NAME=provess-name DAEMON=/usr/sbin/$NAME case "$1" in start) log_daemon_msg "Starting $DESC" "$NAME" initctl start provess-name RET_STATUS=$? case "$RET_STATUS" in 0|1) log_success_msg [ $RET_STATUS = 1 ] && log_warning_msg "Server was already running" ;; 2) log_failure_msg print_error_msg exit 1 ;; esac ;; stop|graceful-stop) log_daemon_msg "Stopping $DESC" "$NAME" initctl stop provess-name RET_STATUS=$? case "$RET_STATUS" in 0|1) log_success_msg [ $RET_STATUS = 1 ] && log_warning_msg "Process was not running" ;; 2) log_failure_msg print_error_msg exit 1 ;; esac print_error_msg ;;
See examples in /etc/init.d/ for examples onm how to support start, stop, status, restart, reload, etc.
The script must be executable to work. (chmod +x script-name).
The script may be used to start and stop processes. i.e.:
- /etc/rc.d/init.d/httpd restart
(Ubuntu / Debian / S.u.s.e.: /etc/init.d/apache2 restart) - /etc/rc.d/init.d/httpd stop
- /etc/rc.d/init.d/httpd start
- service httpd restart
- service httpd stop
- service httpd start
# chkconfig: 345 85 15 # description: Description of program
Upstart init config files (Ubuntu 14.04 example): /etc/init/*
SysV init files are still in /etc/init.d/*.
The two systems cohabitate on Ubuntu 12.04 and 14.04.
- File: /etc/init/service-name.conf
description "service-name" start on runlevel [2345] stop on runlevel [!2345] respawn respawn limit 10 5 umask 022 env SSH_SIGSTOP=1 expect stop console none pre-start script test -x /usr/sbin/service-name || { stop; exit 0; } mkdir -p -m0755 /var/run/service-name end script exec /usr/sbin/service-name -D
- Start a specified service: systemctl start name.service
- Stop a specified service: systemctl stop name.service
- Restart a specified service: systemctl restart name.service
- Show status of a specified service: systemctl status name.service
- Enable a specified service to be started upon boot: systemctl enable name.service
- Disable a specified service to NOT be started upon boot: systemctl disable name.service
- Check if a specified service is to be started upon boot: systemctl is-enabled name.service; echo $?
The command "echo $?" shows the return code of the previous command:- 0: enabled
- 1: disabled
- List all active boot services: systemctl list-units --type=target
chkconfig [--level <levels>] <name> <on | off | reset > chkconfig --list chkconfig --list [name] chkconfig --add <name> chkconfig --del <name> chkconfig --level 0123456 <name> off
Examples:
- chkconfig --level 345 httpd on - forces apache to be invoked for run levels 3, 4 and 5.
- chkconfig --add httpd - Start the web server daemon upon system boot.
- chkconfig --del sendmail - Do not start the sendmail daemon upon system boot.
- chkconfig --list - List all services and init levels.
- chkconfig --list | grep on - List all services to be started upon system boot.
- chkconfig wu-ftpd on - Turn on FTP service managed by xinetd.
- chkconfig ipop3 off - Turn off POP3 service managed by xinetd.
No comments:
Post a Comment