Search This Blog


RHEL 6 Booting and Runlevels

RHEL 6 Booting and Runlevels
RHEL6 upstart init
RHEL7 systemd

bios > boot loader (mbr > grub) > kernel > init pid1 ppid0 > run levels (single, multi, X11, etc) > user space

BIOs contained in well known location
X86 and X64 know the location and when they boot they execute these from that address

MBR - stage 1 boot loader located in MBR (446 bytes is the stage1 boot loader)

GRUB2 - fedora and more modern OSes, older OSes dedicated to stability still use GRUB

From MBR stage 1 boot loader we load stage 2 boot loader which loads initramfs which has utilities required for the boot process to continue and the kernel to load.

initramfs just gives the kernel access to additional device drives and utilities it might require during boot process. During normal install this initramfs is pared down and doesn’t include all device drivers but if you’re doing an initial install from disc the disc has to have all of the device drivers in it so using that initramfs is the most flexible method of booting on any system and once the drivers are loaded and initramfs created you’ll be able to continue to boot using the initramfs on that device from then on.

Kernel is loaded and grabs a bunch of memory for kernel processes. Kernel probes for attached devices and initializes the ones that it has device drivers for. It has initramfs as the root filesystem currently.

The kernel then runs init in /sbin/init which is the first user space program. Gets the process ID of 1. With a parent of 0 (indicating the kernel sort of)

init process
1. reads /etc/inittab to determine default runlevel of the system
2. runs the rc.sysinit script which sets hostname and creates /procfs and /sysfs virtual filesystems
3. Runs scripts in /etc/rc.d/rc#.d/
4. Init then spawns login prompts and waits for login at all login prompts

Stage 1: MBR ~400bytes
Stage 1.5: located in either the boot partition or space between MBR and first partition on the drive. ~30KB - small device drivers to read filesystems
ls -lh /boot/grub/grub | grep 1_5 will show all of the filesystem specific stage 1.5 boot loaders

Will access all ext2,3,and 4 filesystems with the same e2fs drivers and ignores advanced journaling technologies of future filesystems

Stage 2: Can be called within a filesystem and you will have access to the rest of the HDD /boot/grub/grub.conf

PXE Boot:
pxelinux.0 acts as the boot loader and tells the system what to do next in the boot process

Grub Parameters:
default=0 will boot first OS without prompt
timeout=10 gives you 10 seconds to make a choice
hiddenmenu - hides menu for OS selection until you break into it

Need 3 options required:
root - grub addresses disks differently than linux
(hd0,2) - grub doesn’t care what type of drive it is all of them will be addressed with the “hd” parameter
0 - device number (first disk)
2 - partition number (2 is the 3rd partition)
/vmlinuz-#… - kernel image is called vmlinuz
vm when system supported virtual memory
the z means the kernel is compressed
ro root=/dev/… - by default root filesystem mounted read only later it is mounted read-write
rd _NO_LUKS - disables detection of LUKS encrypted partitions

/initramfs - initial ramdisk is a disk image thats loaded with drivers and modules
initramfs is really an improved form of initrd before initrd would load the image into ram and cache to ram as well. Now initramfs just pulls from cache

Linux is loaded in a Direct fashion. Windows is indirect and uses a “chain loader”

good idea to install windows first because it has a history of wiping out all other partitions
also good to install to the first partition of the first drive as historically it had problems loading from anywhere but there.

title Windows
rootnoverify (hd0,0) - don’t mount the partition and test it
chainloader +1 - pass control to the thing that exists in the first sector of the partition hd0,0

Modifying Kernel line in Grub.
quiet - hides kernel boot process data
rhgb - hides the entire kernel process in favor of the progress bar

single - adding single to the end will punt you to single user mode immediately
confirm - will confirm the load of every rc script after the kernel is loaded
init=/bin/bash - will punt you to /bin/bash without loading any init processes so you have a very basic login prompt

mount -o remount,rw / - remounts the root filesystem as read write so you can restore files
mount /dev/mapper/vg/lv / -o remount,rw - incase you’re missing a valid /etc/fstab you might need to be very specific as to which filesystem is actually your root fs

Startup manager - runs startup scripts and initializes user-space and creates user-space processes
Session Manager - maintains system run level, and manages user-space processes

sysvinit - initial iteration of init
upstart init - from canonical ubuntu - didn’t turn out so well so switch to the next
systemd - newest init process

kthreadd - is the parent of all kernel processes and is given the PID of 2
• everything with the PPID of 2 aren’t really user space processes they’re kernel threads made to look like processes for architectural reasons

User space processes are generally above PID 1000
Kernel are below 1000

bootloader > rc.sysinit (hostname, environment path, clock, /procfs, sysfs, mounts, swapping) > init scripts

don’t actually edit the rc.sysinit file only edit the /etc/rc.d/rc.local which is actually a startup script with the name starting with S99

Runlevels - end state that we want to boot linux to

each run level has scripts that it needs to run in the /etc/rc#.d/ directory before loading into that run level is determined to be complete.

The only reason K is run first is because of alphabetical order
K##script - are kill scripts that are run in order before the starts scripts
S##script - are run after the kill scripts

All of the scripts files are symlinks to /etc/rc.d/init.d/ so you just need to change the scripts from init.d

All run levels are configurable but not recommended to change
0 system shutdown
1 is single user mode
2 not used
3 is command line normal
4 not used
5 is gui normal
6 system reboot

Changing run levels
runlevel - determine current run level and previous
# previous # current

telinit 5 - change to gui init

• no parallel instantiation
◦ for example if no dhcp request the boot process will continue to wait until we get dhcp before starting anything else
• allows us to start devices after boot process instead of waiting for things like bluetooth devices to instantiate during boot process

• has better service dependency for boot process
• RHEL 7 is going systemd

Backwards compatibility with sysvinit
/etc/rc.d/rc $RUNLEVEL - will execute scripts from the run level that it receives from inittab

upstart works on run level events to invoke specific run level tasks. conveniently enough telinit is a run level event that will tell it to invoke a specific run level which will then run the run level scripts you want

1 comment:

  1. This comment has been removed by a blog administrator.