From Power Up To Bash Prompt

notes from power2bash by Greg O’Keefe.

” This is a brief description of what happens in a Linux system, from the time that you turn on the power, to the time that you log in and get a bash prompt. Understanding this will be helpful when you need to solve problems or configure your system.”

Introduction

My journey into learning about operating systems and linux started with the selection task I did for KOSS

gateway to LFS

Hardware

  • POST
  • bootstrap loader
    • boot sector magic number
    • loads to memory
    • passes control to OS loader

Configuration

Firmware Stored directly in motherboards CMOS (interesting)

make a hello world boot disk for Unios

LILO

discuss about GRUB and its comparisions

(LInux LOader) is a bootloader

first stage load second stage boot loader present boot menu/os chooser load kernel

make a boot loop

/etc/grub.d/README (interesting)

The Linux Kernel

The main OS: makes the hardware do what the processes want

  • scheduling
  • virtual mem management
  • concurrency

once it is loaded it looks for an init program to run

can configure from your bootloader

mentions a System.map

Think about this: /dev/hda3 is a special type of file that describes a hard disk partition. But it lives on a file system just like all other files. The kernel wants to know which partition to mount as the root filesystem - it doesn’t have a file system yet. So how can it read /dev/hda3 to find out which partition to mount?

The GNU C Library

init is loaded and run as PID 1

but it uses functions from libraries (obv)

ldd

Init

kernel loads and runs /sbin/init (confirm this)

  • makes everything run as it should
  • reads /etc/inittab (???) initialisation script
    • probably means /etc/fstab or something similar
    • checks file systems and mounts them (didn’t know init does this)
    • starts daemons
  • starts getty for login this is respawned

talk about runit run levels

  • ABI
  • System V
  • looks statically compiled
  • calls /sbin/runit

try chaning the number of gettys

The Filesystem

init scripts check and mount the filesystem with fschk and mount

fschk attempts to detect and repair inode discrepancies etc mount mounts

root fs first r-- then fschk then mount rwx

there is a Virtual File System (VFS)

crazy stuff happens in /proc

make a small filesystem (btrfs)

Kernel Daemons

 ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   1016   584 ?        Ss   Jun12   0:00 runit
root         2  0.0  0.0      0     0 ?        S    Jun12   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Jun12   0:00 [pool_workqueue_release]
root         4  0.0  0.0      0     0 ?        I<   Jun12   0:00 [kworker/R-rcu_gp]
root         5  0.0  0.0      0     0 ?        I<   Jun12   0:00 [kworker/R-sync_wq]

notice kernel processes take no virtual size or real storage size ps works by parsing /proc and that doesn’t contain info on kernel daemons

System Logger

klogd and syslogd in /var/log/

I DON’T HAVE LOGGING SETUP :sob:

Getty and Login

getty takes username, and calls login with that username

/etc/passwd /etc/shadow

address Display Managers

Bash

if passwdchk succeeds then login spawns a shell for you

a shell is a

  • user interface
  • prgamming language interpreter at the same time

bash has built in internals, or could call external commands

checkout /etc/profile