Guide Boot start and shutdown sequencing in Ubuntu

Status
Not open for further replies.
Hi all,
Ubuntu and Debian both use the sys V init boot sequence. First here is the list of the various boot sequences :-

Note:- This is on gutsy gibbon 7.10 so no idea if things have been added to the startup script or not. I

Debian -- bum

Code:
shirish@ubuntu:~$ ls -l /etc/rcS.d
total 4
-rw-r--r-- 1 root root 785 2007-06-28 19:22 README
lrwxrwxrwx 1 root root  24 2007-06-09 07:29 S01mountkernfs.sh -> ../init.d/mountkernfs.sh
lrwxrwxrwx 1 root root  19 2007-06-09 07:54 S01readahead -> ../init.d/readahead
lrwxrwxrwx 1 root root  21 2007-06-09 07:29 S02hostname.sh -> ../init.d/hostname.sh
lrwxrwxrwx 1 root root  24 2007-06-09 07:30 S06keyboard-setup -> ../init.d/keyboard-setup
lrwxrwxrwx 1 root root  41 2007-06-09 07:31 S07linux-restricted-modules-common -> ../init.d/linux-restricted-modules-common
lrwxrwxrwx 1 root root  18 2007-06-09 07:29 S08loopback -> ../init.d/loopback
lrwxrwxrwx 1 root root  14 2007-06-09 07:29 S10udev -> ../init.d/udev
lrwxrwxrwx 1 root root  20 2007-07-02 20:19 S11hwclock.sh -> ../init.d/hwclock.sh
lrwxrwxrwx 1 root root  26 2007-06-09 07:29 S11mountdevsubfs.sh -> ../init.d/mountdevsubfs.sh
lrwxrwxrwx 1 root root  21 2007-06-09 07:29 S13pcmciautils -> ../init.d/pcmciautils
lrwxrwxrwx 1 root root  27 2007-06-09 07:29 S15module-init-tools -> ../init.d/module-init-tools
lrwxrwxrwx 1 root root  19 2007-06-09 07:29 S17procps.sh -> ../init.d/procps.sh
lrwxrwxrwx 1 root root  22 2007-06-09 07:29 S20checkroot.sh -> ../init.d/checkroot.sh
lrwxrwxrwx 1 root root  17 2007-06-09 07:29 S22mtab.sh -> ../init.d/mtab.sh
lrwxrwxrwx 1 root root  16 2007-06-09 07:29 S23finish -> ../init.d/finish
lrwxrwxrwx 1 root root  16 2007-06-09 07:55 S25brltty -> ../init.d/brltty
lrwxrwxrwx 1 root root  20 2007-06-09 07:29 S30checkfs.sh -> ../init.d/checkfs.sh
lrwxrwxrwx 1 root root  19 2007-07-06 23:20 S31hibernate -> ../init.d/hibernate
lrwxrwxrwx 1 root root  21 2007-06-09 07:29 S35mountall.sh -> ../init.d/mountall.sh
lrwxrwxrwx 1 root root  31 2007-06-09 07:29 S36mountall-bootclean.sh -> ../init.d/mountall-bootclean.sh
lrwxrwxrwx 1 root root  26 2007-06-28 20:51 S37mountoverflowtmp -> ../init.d/mountoverflowtmp
lrwxrwxrwx 1 root root  27 2007-06-09 07:54 S39readahead-desktop -> ../init.d/readahead-desktop
lrwxrwxrwx 1 root root  20 2007-06-09 07:29 S40networking -> ../init.d/networking
lrwxrwxrwx 1 root root  20 2007-06-09 07:29 S45waitnfs.sh -> ../init.d/waitnfs.sh
lrwxrwxrwx 1 root root  31 2007-06-09 07:29 S46mountnfs-bootclean.sh -> ../init.d/mountnfs-bootclean.sh
lrwxrwxrwx 1 root root  20 2007-07-09 13:27 S47lm-sensors -> ../init.d/lm-sensors
lrwxrwxrwx 1 root root  23 2007-06-09 07:30 S49console-setup -> ../init.d/console-setup
lrwxrwxrwx 1 root root  19 2007-06-09 07:47 S55dns-clean -> ../init.d/dns-clean
lrwxrwxrwx 1 root root  18 2007-06-09 07:46 S55pppd-dns -> ../init.d/pppd-dns
lrwxrwxrwx 1 root root  16 2007-06-09 07:44 S70screen -> ../init.d/screen
lrwxrwxrwx 1 root root  20 2007-06-09 07:32 S70x11-common -> ../init.d/x11-common
lrwxrwxrwx 1 root root  21 2007-06-09 07:29 S80bootmisc.sh -> ../init.d/bootmisc.sh
lrwxrwxrwx 1 root root  17 2007-06-09 07:29 S85urandom -> ../init.d/urandom
lrwxrwxrwx 1 root root  27 2007-06-09 07:29 S90console-screen.sh -> ../init.d/console-screen.sh
shirish@ubuntu:~$

The above is the general startup script.

Code:
shirish@ubuntu:~$ ls -la /etc/rc2.d
total 20
drwxr-xr-x   2 root root  4096 2007-07-03 17:12 .
drwxr-xr-x 135 root root 12288 2007-07-11 07:05 ..
-rw-r--r--   1 root root   556 2007-06-28 19:22 README
lrwxrwxrwx   1 root root    17 2007-06-09 07:47 S05vbesave -> ../init.d/vbesave
lrwxrwxrwx   1 root root    15 2007-06-09 07:31 S10acpid -> ../init.d/acpid
lrwxrwxrwx   1 root root    25 2007-06-09 07:54 S10powernowd.early -> ../init.d/powernowd.early
lrwxrwxrwx   1 root root    18 2007-06-09 07:29 S10sysklogd -> ../init.d/sysklogd
lrwxrwxrwx   1 root root    34 2007-06-09 07:32 S10xserver-xorg-input-wacom -> ../init.d/xserver-xorg-input-wacom
lrwxrwxrwx   1 root root    15 2007-06-09 07:29 S11klogd -> ../init.d/klogd
lrwxrwxrwx   1 root root    14 2007-06-09 07:44 S12dbus -> ../init.d/dbus
lrwxrwxrwx   1 root root    13 2007-06-09 07:47 S13gdm -> ../init.d/gdm
lrwxrwxrwx   1 root root    16 2007-06-09 07:47 S19cupsys -> ../init.d/cupsys
lrwxrwxrwx   1 root root    15 2007-06-09 07:47 S19hplip -> ../init.d/hplip
lrwxrwxrwx   1 root root    14 2007-07-01 10:00 S19lirc -> ../init.d/lirc
lrwxrwxrwx   1 root root    14 2007-06-09 07:47 S20apmd -> ../init.d/apmd
lrwxrwxrwx   1 root root    16 2007-06-09 07:47 S20apport -> ../init.d/apport
lrwxrwxrwx   1 root root    17 2007-07-02 00:26 S20hddtemp -> ../init.d/hddtemp
lrwxrwxrwx   1 root root    22 2007-06-09 07:53 S20hotkey-setup -> ../init.d/hotkey-setup
lrwxrwxrwx   1 root root    17 2007-06-09 07:29 S20makedev -> ../init.d/makedev
lrwxrwxrwx   1 root root    23 2007-06-09 07:31 S20nvidia-kernel -> ../init.d/nvidia-kernel
lrwxrwxrwx   1 root root    19 2007-06-09 07:54 S20powernowd -> ../init.d/powernowd
lrwxrwxrwx   1 root root    15 2007-06-09 07:44 S20rsync -> ../init.d/rsync
lrwxrwxrwx   1 root root    13 2007-07-01 10:00 S20vdr -> ../init.d/vdr
lrwxrwxrwx   1 root root    22 2007-06-09 07:47 S24avahi-daemon -> ../init.d/avahi-daemon
lrwxrwxrwx   1 root root    16 2007-06-12 23:04 S24dhcdbd -> ../init.d/dhcdbd
lrwxrwxrwx   1 root root    13 2007-07-03 17:12 S24hal -> ../init.d/hal
lrwxrwxrwx   1 root root    19 2007-06-09 07:47 S25bluetooth -> ../init.d/bluetooth
lrwxrwxrwx   1 root root    17 2007-06-09 07:45 S89anacron -> ../init.d/anacron
lrwxrwxrwx   1 root root    13 2007-06-09 07:44 S89atd -> ../init.d/atd
lrwxrwxrwx   1 root root    14 2007-06-09 07:45 S89cron -> ../init.d/cron
lrwxrwxrwx   1 root root    17 2007-06-09 07:55 S98usplash -> ../init.d/usplash
lrwxrwxrwx   1 root root    22 2007-06-09 07:47 S99acpi-support -> ../init.d/acpi-support
lrwxrwxrwx   1 root root    18 2007-06-09 07:29 S99rc.local -> ../init.d/rc.local
lrwxrwxrwx   1 root root    19 2007-06-09 07:29 S99rmnologin -> ../init.d/rmnologin
lrwxrwxrwx   1 root root    24 2007-06-09 07:54 S99stop-readahead -> ../init.d/stop-readahead

That is for the single user startup script. This is without Xserver hence no. of things started are less.

Code:
shirish@ubuntu:~$ ls -la /etc/rc6.d
total 20
drwxr-xr-x   2 root root  4096 2007-07-03 17:12 .
drwxr-xr-x 135 root root 12288 2007-07-11 07:05 ..
lrwxrwxrwx   1 root root    13 2007-06-09 07:47 K01gdm -> ../init.d/gdm
lrwxrwxrwx   1 root root    17 2007-06-09 07:55 K01usplash -> ../init.d/usplash
lrwxrwxrwx   1 root root    22 2007-06-09 07:47 K16avahi-daemon -> ../init.d/avahi-daemon
lrwxrwxrwx   1 root root    16 2007-06-12 23:04 K16dhcdbd -> ../init.d/dhcdbd
lrwxrwxrwx   1 root root    13 2007-07-03 17:12 K16hal -> ../init.d/hal
lrwxrwxrwx   1 root root    15 2007-06-09 07:47 K19hplip -> ../init.d/hplip
lrwxrwxrwx   1 root root    14 2007-07-01 10:00 K19lirc -> ../init.d/lirc
lrwxrwxrwx   1 root root    16 2007-06-09 07:47 K20apport -> ../init.d/apport
lrwxrwxrwx   1 root root    17 2007-07-02 00:26 K20hddtemp -> ../init.d/hddtemp
lrwxrwxrwx   1 root root    13 2007-07-01 10:00 K20vdr -> ../init.d/vdr
lrwxrwxrwx   1 root root    20 2007-07-02 20:19 K25hwclock.sh -> ../init.d/hwclock.sh
lrwxrwxrwx   1 root root    20 2007-06-09 07:29 K50alsa-utils -> ../init.d/alsa-utils
lrwxrwxrwx   1 root root    26 2007-06-28 20:51 K59mountoverflowtmp -> ../init.d/mountoverflowtmp
-rw-r--r--   1 root root   353 2007-06-28 19:22 README
lrwxrwxrwx   1 root root    41 2007-06-09 07:31 S01linux-restricted-modules-common -> ../init.d/linux-restricted-modules-common
lrwxrwxrwx   1 root root    22 2007-06-09 07:29 S15wpa-ifupdown -> ../init.d/wpa-ifupdown
lrwxrwxrwx   1 root root    18 2007-06-09 07:29 S20sendsigs -> ../init.d/sendsigs
lrwxrwxrwx   1 root root    17 2007-06-09 07:29 S30urandom -> ../init.d/urandom
lrwxrwxrwx   1 root root    22 2007-06-09 07:29 S31umountnfs.sh -> ../init.d/umountnfs.sh
lrwxrwxrwx   1 root root    18 2007-06-09 07:29 S40umountfs -> ../init.d/umountfs
lrwxrwxrwx   1 root root    20 2007-06-09 07:29 S60umountroot -> ../init.d/umountroot
lrwxrwxrwx   1 root root    16 2007-06-09 07:29 S90reboot -> ../init.d/reboot

That is for rebooting as well as halt. Some notes :-

  • Start first all scripts in /etc/rcS.d/
  • For the runlevel 2, first all K##scripts in /etc/rc2.d/, next all S##script.
  • All .sh scripts are sourced, the rest are exec-ed
  • Almost everything is symlinked to /etc/init.d

Now one can edit any of the .sh boot files & update so the next boot it reflects in the boot. Sample of a script file.

Code:
shirish@ubuntu:~$ cat /etc/init.d/bootmisc.sh
#!/bin/sh
### BEGIN INIT INFO
# Provides:          bootmisc
# Required-Start:    $local_fs hostname $remote_fs
# Required-Stop:     $local_fs
# Default-Start:     S
# Default-Stop:
# Short-Description: Miscellaneous things to be done during bootup.
# Description:
### END INIT INFO

PATH=/usr/sbin:/usr/bin:/sbin:/bin
[ "$DELAYLOGIN" ] || DELAYLOGIN=yes
. /lib/init/vars.sh

do_start () {
        #
        # If login delaying is enabled then create the flag file
        # which prevents logins before startup is complete
        #
        case "$DELAYLOGIN" in
          Y*|y*)
                echo "System bootup in progress - please wait" > /var/lib/initscripts/nologin
                ;;
        esac

        # Create /var/run/utmp so we can login.
        : > /var/run/utmp
        if grep -q ^utmp: /etc/group
        then
                chmod 664 /var/run/utmp
                chgrp utmp /var/run/utmp
        fi

        # Set pseudo-terminal access permissions.
        if [ ! -e /dev/.devfsd ] && [ -c /dev/ttyp0 ]
        then
                chmod -f 666 /dev/tty[p-za-e][0-9a-f]
                chown -f root:tty /dev/tty[p-za-e][0-9a-f]
        fi

        # Update motd
        uname -snrvm > /var/run/motd
        [ -f /etc/motd.tail ] && cat /etc/motd.tail >> /var/run/motd

        # Save kernel messages in /var/log/dmesg
        if which dmesg >/dev/null 2>&1
        then
                savelog -q -p -c 5 /var/log/dmesg
                dmesg -s 524288 > /var/log/dmesg
                chgrp adm /var/log/dmesg || :
        elif [ -c /dev/klog ]
        then
                savelog -q -p -c 5 /var/log/dmesg
                dd if=/dev/klog of=/var/log/dmesg &
                sleep 1
                kill $!
                [ -f /var/log/dmesg ] && { chgrp adm /var/log/dmesg || : ; }
        fi

        #
        #       Save udev log in /var/log/udev
        #
        if [ -e /dev/.udev.log ]
        then
                mv -f /dev/.udev.log /var/log/udev
        fi
        # Remove bootclean's flag files.
        # Don't run bootclean again after this!
        rm -f /tmp/.clean
}

case "$1" in
  start|"")
        do_start
        ;;
  restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
  stop)
        # No-op
        ;;
  *)
        echo "Usage: bootmisc.sh [start|stop]" >&2
        exit 3
        ;;
esac

:

While I'm no scripter/programmer it would be cool for some of the programmers to give us some cool tips.

No. of scripts which one can play with.

Code:
shirish@ubuntu:~$ ls -l /etc/init.d/*.sh
-rwxr-xr-x 1 root root 1883 2007-04-11 03:15 /etc/init.d/bootmisc.sh
-rwxr-xr-x 1 root root 2887 2007-04-11 03:15 /etc/init.d/checkfs.sh
-rwxr-xr-x 1 root root 9875 2007-04-11 03:15 /etc/init.d/checkroot.sh
-rwxr-xr-x 1 root root 6355 2007-05-30 17:59 /etc/init.d/console-screen.sh
-rwxr-xr-x 1 root root 5781 2007-07-10 22:41 /etc/init.d/glibc.sh
-rwxr-xr-x 1 root root  909 2007-04-11 03:15 /etc/init.d/hostname.sh
-rwxr-xr-x 1 root root 3886 2007-05-15 03:19 /etc/init.d/hwclock.sh
-rwxr-xr-x 1 root root  617 2007-04-11 03:15 /etc/init.d/mountall-bootclean.sh
-rwxr-xr-x 1 root root 2354 2007-04-11 03:15 /etc/init.d/mountall.sh
-rwxr-xr-x 1 root root 1491 2007-04-11 03:15 /etc/init.d/mountdevsubfs.sh
-rwxr-xr-x 1 root root 1464 2007-06-13 21:14 /etc/init.d/mountkernfs.sh
-rwxr-xr-x 1 root root  615 2007-04-11 03:15 /etc/init.d/mountnfs-bootclean.sh
-rwxr-xr-x 1 root root 2689 2007-04-11 03:15 /etc/init.d/mtab.sh
-rwxr-xr-x 1 root root 1208 2007-06-01 01:12 /etc/init.d/procps.sh
-rwxr-xr-x 1 root root 1833 2007-04-11 03:15 /etc/init.d/umountnfs.sh
-rwxr-xr-x 1 root root 1939 2007-04-11 03:15 /etc/init.d/waitnfs.sh

Note that mountntfs is because I have used the ntfs-3g driver hence its there.

To do any changes , do the following (an e.g.) :-

Code:
shirish@ubuntu:~$ gksudo gedit /etc/init.d/bootmisc.sh

Make your changes. Save changes. Now run

Code:
shirish@ubuntu:~$ sudo updaterc*.d/Nname

Now * is replaced by the run-level where the script occurs (the symlinked) and give Nname . The whole thing is explained pretty nicely in

Code:
 man update-rc.d

Changing/stopping runlevels in startup script

shirish@ubuntu:~$ cat /etc/rc5.d/README
The scripts in this directory are executed each time the system enters
this runlevel.

The scripts are all symbolic links whose targets are located in
/etc/init.d/ .

To disable a service in this runlevel, rename its script in this directory
so that the new name begins with a 'K' and a two-digit number, where the
number is the difference between the two-digit number following the 'S'
in its current name, and 100. To re-enable the service, rename the script
back to its original name beginning with 'S'.

For a more information see /etc/init.d/README.

Now simplify your life by using boot up manager :bleh:

[BREAK=BUM=Boot Up Manager]

Install user friendly boot-up manager to do your dirty work.

Code:
shirish@ubuntu:~$ sudo aptitude install bum

To run it do :-

Code:
shirish@ubuntu:~$ gksudo bum

The below images tell everything










As one can see its pretty pretty cool. Gives detailed info. of each service. Do your changes, click apply & then shut down either now or on next boot. On next boot those services are not started. Simple isn't it :)

[BREAK=Upstart]

Upstart​

wikipedia said:
In Unix computing, Upstart is an event-based replacement for the init daemon, written by Scott James Remnant, an employee of Canonical Ltd. Upstart operates asynchronously — as well as handling the starting of tasks and services during boot and stopping them during shutdown, it supervises them while the system is running.

As easy transition and perfect backwards compatibility with sysvinit were explicit design goals, upstart's code is based on the existing sysvinit code-base.

The most simplest way to say it will be dynamic so depending on hardware which is there or not, the services would be booted or not.

states.png


This is how it is going to be in the future.
For Ubuntu 7.04 a lot of the job of mounting filesystems, especially those using software raid (mdadm), devmapper, LVM or EVMS has been made event-based. It also replaced cron, atd, anacron and inetd.

References & stuff to read :-

 
  • Like
Reactions: 1 person
Code:
shirish@ubuntu:~$ dpkg -S /sbin/init
upstart: /sbin/init

Upstart For Ubuntu 7.04 does a lot of the job of mounting filesystems, especially those using software raid (mdadm), devmapper, LVM or EVMS has been made event-based. For the remaining it still uses old stuff. They would be trying to make the other services to move to upstart as well but that should take some more time. So eventually something in 7.10 or 7.10 + 1.
 
:O Huge .. Gr8 work there,,WIll install BUM and will tell u how it results :) Btw whats the advantage of BUM over default Boot Manage :ashamed: .. Nice work as usual Reps on your way :hap2:
 
Dark Star said:
:O Huge .. Gr8 work there,,WIll install BUM and will tell u how it results :) Btw whats the advantage of BUM over default Boot Manage :ashamed: .. Nice work as usual Reps on your way :hap2:

erhm.... its nothing to do with boot manager as in if you are thinking of booting different Oses like Super GRUB, GRUB, LILO etc . Here booting means booting/starting of services in Ubuntu. What BUM does is just put a GUI on top otherwise one would have to do things manually. The possibility of making silly mistakes is made less by using BUM. Of course it goes without saying that turning off essential services would render your system in an unusable state.
 
What BUM does is just put a GUI on top otherwise one would have to do things manually. The possibility of making silly mistakes is made less by using BUM. Of course it goes without saying that turning off essential services would render your system in an unusable state.
Cool thanks again :) WIll install as soon as I can :D :hap2:
 
Status
Not open for further replies.