System V Init Startup

Overview of SysVinit

Sys Vinit scripts have started Linux since its early days but is widely superseded now by systemd in the lastes versions archlinux, SUSE , Debian and Red Hat

 

SysVinit

Kernel will start /sbin/init as PID 1

Subsequently reads /etc/inittab

Initial start in S mode (single user) to inizialize the system loading consoles

Then targets runlevel from initdefault

Serial boot process

LSB scripts in /etc/init.d linked to runlevels in /etc/rcX.d

inittab

RHEL6 and Centos uses Upstart a hybrid somewhere between SysVinit and systemd

 

Understanding the /etc/inittab File

CentOS

less /etc/inittab

inittab centos

ps -elf | grep init

PS1 is  /sbin/init

 

Raspberrypi

tabinit raspberry pi

si::sysinit:/etc/init.d/rcS

~~:S:wait:/sbin/sulogin

raspberry inittab1

raspberry inittab2

less /etc/inittab

ps -elf | grep init

raspberry inittab3

 

Understanding Runlevels

Runlevels

The current runlevel is read from /var/run/utmp by the command who -r  and runlevel

Changing Runlevels

/sbin/telinit

/sbin/init

 

Controlling Runlevels in CentOS and the Raspberry Pi

 who -r

 runlevel

who runlevel

file /var/run/utmp

/var/run/utmp: data

 telinit

telinit:missing runlevel

strings /sbin/telinit

strings /sbin/telinit | grep init

strings sbin telinit  grep init

sudo telinit 3    – text mod logon

 

What Makes up an Init Script

 LBS Stanza in SysVinit Scripts

###BEGIN INIT INFO

#Provides: rmnologin

#Required-Start: $ remote_fs $ all

Required-Stop

LBS Stanza in SysVinit Scripts

SysVinit Scripts Actions

SysVinit Scripts Actions

Creating Your Own Init Scripts

sudo -i

cd /etc/init.d

ls

cp rmnologin myservice

vi myservice

Creating Your Own Init Scripts

 

dadd some message

Creating Your Own Init Scripts 2

 

Creating Your Own Init Scripts 3

ls -l myservice

./myservice status

service myservice status

cd /etc/init.d

cd ../rc2.d/

ls

 

Understanding chkconfig and update-rc.d

Creating Links to Scripts

chkconfig    

update-rc.d

 

sudo chkconfig   –list

sudo chkconfig –list ntpd

sudo chkconfig  ntpd on

sudo chkconfig  ntpd off

sudo chkconfig –level 3 ntpd on

sudo chkconfig –level 3 ntpd off

chkconfig

cd /etc/init.d/

head ntpd

chkconfig

chkconfig 2

Debian base system

update-rc.d

service –status-all

sudo update-rc.d ntp defaults

sudo update.rc.d -f ntp remove

sudo update-rc.d ntp defaults 20 80

sudo update-rc.d ntp start 20 80 2 3 . \

stop 80 0 1 4 5 6 .

service umountfs status

Organizing Service Start-up from the Command Line