Linux : Booting and runlevels

14
Booting Linux & Runlevels Understanding the Boot Process & the different runlevels. By John Troon

Transcript of Linux : Booting and runlevels

Page 1: Linux : Booting and runlevels

Booting Linux & Runlevels

Understanding the Boot Process & the different runlevels.

By John Troon

Page 2: Linux : Booting and runlevels

Extracting Information about the Boot Process

● To view information logged by the Linux kernel and modules stored in the kernel ring buffer.

● dmesg● dmesg | less● dmesg > boot.messages● cat /var/log/dmesg● system logger ( syslogd )

Page 3: Linux : Booting and runlevels

Locating & Interpreting Boot Messages

● Use less and Its search functions● Look for Hardware type names (SCSI/USB etc)● Look for Hardware Chipset names● Study the output from a working System

Page 4: Linux : Booting and runlevels

The Boot Process Going to the nitty gritty details of the boot process is complex.

Below is a high-level view of the boot process.● Power the machine & CPU runs the firmware.● The firmware performs some tasks.● Boot-loader takes over from the firmware & loads a kernel.● Linux kernel takes over,initializing devices, mounting the root

partition & executes /sbin/init● The initial program gets the process ID (PID) of 1. Commonly,

/sbin/init reads the /etc/inittab

http://www.linuxdevcenter.com/pub/a/linux/excerpts/linux_kernel/how_computer_boots.html

Page 5: Linux : Booting and runlevels

Dealing with Runlevels and theInitialization Process

● Linux relies on runlevels (0-6) to determine what features are available.● 0 - A transitional runlevel, on/off (shuts down).● 1,s, or S - Single-user mode. Used for low-level system maintenance● 2 - On Debian and its derivatives, a full multi-user mode with X.

Undefined in others. ● 3 – In most distributions, a full multi-user mode with a console.● 4 - Usually undefined by default and therefore available for

customization.● 5 – In most distributions, the same behavior as runlevel 3 with the

addition of having X.● 6 - Also a transitional runlevel. Used to reboot the system.

Page 6: Linux : Booting and runlevels

Identifying the Services in a Runlevel● There are two main ways to affect what

programs run when you enter a new SysV runlevel.

1) add or delete entries in your /etc/inittab file

2) the SysV Startup Scripts

Distributions based on Upstart and systemd often provide startup scripts that are named and work much like on SysV-based computers; however, when the computer boots, it may use other startup methods, as described later, in “Using Alternative Boot Systems.”

Page 7: Linux : Booting and runlevels

Managing Runlevel Services● # chkconfig –list● # chkconfig --list nfs-common● # chkconfig --level 23 nfs-common on● # chkconfig --add nfs-common

Page 8: Linux : Booting and runlevels

Checking Your Runlevel

1) Checking and changingyour default runlevel.

# grep :initdefault: /etc/inittab

Edit the initdefault line in /etc/inittab & change the runlevel field to the value you want.

2) Determining Your Current Runlevel : # runlevel

The fi rst character is the previous runlevel. When the character is N , this means the system hasn’t switched runlevels since booting.

Page 9: Linux : Booting and runlevels

Changing Runlevels on a Running System

● Changing Runlevels with init or telinit

The init process is the fi rst process run by the Linux kernel, but you can also use it to have the system reread the /etc/inittab fi le and implement changes it fi nds there or to changeto a new runlevel.

● # init 1 - reserved for single-user mode● # init 6 - reboot the system

Page 10: Linux : Booting and runlevels

A variant of init is telinit ● This program can take a runlevel number just like init to

change to that runlevel.● It can also take the Q or q option to have the tool reread

/etc/inittab and implement any changes it finds there.● Thus, if you’ve made a change to the runlevel in

/etc/inittab, you can immediately implement that change by typing telinit q .

● The Upstart and systemd tools provide init and telinit commands that work much as they do on SysV-based computers.

Page 11: Linux : Booting and runlevels

Changing Runlevels with shutdown● shutdown is invoked with a time:

# shutdown now● The now parameter causes the change to occur

immediately. Other possible time formats include hh:mm , for a time in 24-hour format.

● -r reboots, -H halts, -P powers it off● shutdown -r +10 to reboot the system in 10 min● shutdown -h +15 “system going down for maintenance”● shutdown -c “never mind” -c option to cancel it.

Page 12: Linux : Booting and runlevels

halt, reboot, and powerof

Three additional shortcut commands are halt , reboot , and poweroff .

In reality, reboot and poweroff are usually symbolic links to halt . This command behaves differently depending on the name with which it’s called.

As you might expect, these commands halt the system (shut it down without powering it off), reboot it, or shut it down and (on hardware that supports this feature) turn off the power, respectively.

Page 13: Linux : Booting and runlevels

EXERCISE 5.1● Page 248● Changing Runlevels

Page 14: Linux : Booting and runlevels

Question(s)?

John Troon

Email: [email protected]

Twitter: @johntroony