linux

References

Things to Learn

Summary

Filesystem Hierarchy Standard (FHS)

bin

Bin stands for binaries

Essential command binaries that need to be available in single-user mode

cat ls cp

boot

Boot loaders

Kernels Initrd

dev

Device files

null

random

disk0

sda1

dev

tty

etc

System-wide config files

opt

Config files for add-ons in opt

sgm1

Config files for softare that processes SGML

xml

Config files for software that processes XML

home

Home directors for the user

This can be used for whatever you want, but I've found that it's actually nicer to use your /home directory as something like /etc, but for different kinds of things.

Whereas the root version of /etc has configurations for the root, /home has configurations for the user

Then you create a separate /data directory or partition, and use that for your actual files

lib

Libraries essential for the binaries in bin and sbin

media

Mount points for removable media

mnt

Temporarily mounted filesystems

opt

Add-on packages

proc

Virtual filesystem providing process and kernel info as files

In linux it corresponds to a procfs mount

root

Home directory for the root user

run

Run-time variable data

sbin

Essential system binaries

fsck init route

srv

Site-specific data like data and scripts for web servers

sys

Info about devices, drivers, and some kernel features

tmp

usr

var

Variable files

cache

Application cache data

lib

State information

lock

Lock files

log

Log files

auth.log

syslog

mail

Mailbox files

opt

Variable data from add-ons that are stored in opt

run

Run-time variable data

spool

For tasks waiting to be processed

tmp

Temporary files to be preserved during reboots

X Windows

Window Managers

KDE

GNOME

Bootloader

When you install an OS, the installer writes the bootloader onto the hard drive

Firmware

Modern motherboards come preloaded with public keys from the manufacturer

The bootloader needs to be digitally signed with a matching private key

Machine Owner Key

One-Time Programmable Memory

The private key is

Pre-bootloader

SHIM

UEFI

This allows software to register its bootloader with the firmware

  1. NVRAM Boot Entries

    Non-volatile random access memory

  2. Fallback Path

    If there are no entries, it looks for a file with a specific name

BIOS

Can't read files It always looks at the first 512 bytes of a disk

  1. Master Boot Record

    If the first sector (512 bytes) ends in the bytes 0x55 and 0xAA, the BIOS recognizes it as a bootloader

    1. Insecure

      You can just write a malicious program in assembly and end it with 0x55AA

      These kinds of malware are called Bootkits

Kernel

Coding

It's primarily written in C (GNU C) With a bit of Assembly and Rust

Socket Buffer