From 65149417e1deb23f83726edfd41f3215ae0591e0 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Tue, 13 Oct 2020 14:46:56 +0200 Subject: add 2020-09-29 and 2020-10-{06,13} slides --- 2020-09-29.md | 387 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 387 insertions(+) create mode 100644 2020-09-29.md (limited to '2020-09-29.md') diff --git a/2020-09-29.md b/2020-09-29.md new file mode 100644 index 0000000..8aa0608 --- /dev/null +++ b/2020-09-29.md @@ -0,0 +1,387 @@ +--- +title: WTF is Linux +author: Rémi Nicole +date: 2020-09-29 +slide-level: 2 +aspectratio: 169 + +theme: metropolis +colortheme: owl +beameroption: "show notes on second screen=right" + +toc: true +highlightstyle: breezedark +lang: en-US + +bibliography: ../bibliography.bib +--- + +# Before we get started + +## Reminder + +- Please fill the [form](https://mensuel.framapad.org/p/zufgimy2yy-9j3n) +- Please have a GNU/Linux system with an SD card reader + + +## Where were we + +::: notes + +- We managed to boot the system! +- What we needed was: + - A file system to store files, and to be used as the root directory + - An init program in this file system, and started by the kernel + +::: + + +# It works but... + + +## The init problem + +- init is a shell +- we want to automate some tasks: + - re-mounting the `/` directory in read-write mode + - networking? + - anything our system should do + + +## The networking problem + +- We want to access the network: + - get updates + - execute our primary function + + +## The user problem + +users, anyone? + +::: notes + +- At no point in our creation of a system we had to create a user, or add + a password + +::: + + +# Automating tasks + +## Goal + +We want to execute programs or code when the system is starting + + +## Attempt number 1 + +Let's make a shell script + +::: notes + +- Instead of just launching a command-line as first program, let's execute some + commands automatically before, and *then* launch the command-line + +::: + + +## Attempt number 2 + +Let's use SysV-style init + + +## SysV-style init + +- The init process reads `/etc/inittab` +- Starts processes as specified by this configuration + + +## inittab + +This file is a series of files in this format: + +```ini +::: +``` + +::: notes + +Busybox does not support each of these features + +::: + +## inittab (Busybox version) + +```ini +# ,-- out of scope +# | +# vvv + ::: +``` + +`action` can be one of: + +- sysinit +: normal process started at boot +- shutdown +: process started before shutting down +- reboot +: process started before rebooting +- ... + +## inittab example + +```ini +# Mount /proc and /sys, and remount / in read-write mode +::sysinit:/etc/init.d/mount-special-filesystems + +# Setup the network +::sysinit:/etc/init.d/setup-network start + +# Start additional services +::sysinit:/etc/init.d/miniserve start + +# ... +``` + +::: notes + +- Note the start argument in the two last services + +::: + +## Changing to SysV-style init + +We just have to change the `init=` kernel parameter to Busybox's `init`. + +## The long-running processes problem + +- We need to launch long-running processes in the background +- We also need a way to stop them + +::: notes + +- We might want to stop a process if something goes wrong, if we want to modify + the configuration, etc. + +::: + + +## The `start-stop-daemon` command + +Can do multiple things: + +- Start a process in a background +- Start a process as a different user +- Write the PID of the launched process into a file (called a "PID file") +- Kill a process with a PID file + +:::notes + +- We don't have our users figured out yet +- Reminder, this is still the old/light way of doing things, so you might not + have this command on your Linux + +::: + + +## Example service script + +```sh +#!/bin/sh + +PIDFILE="/var/run/myprogram.pid" + +case "$1" in + start) + start-stop-daemon -S -p "$PIDFILE" -m -b \ + -x myprogram -- args... + ;; + stop) + start-stop-daemon -K -p "$PIDFILE" + ;; +esac +``` + +# Networking + +## What's in an IP packet + +![Anatomy of an IP packet[@corkami:rfc791]](../res/rfc791.png){ height=80% } + +::: notes + +- From this, we can conclude that we need an IP address for every packet sent + over IP + +- Also, we see that we cannot contact a server through it's domain name (like + google.com), we have to use IP addresses + +::: + +## A home network + +![Home network example[@wikimedia:network1]](../res/home-network.jpg){ height=80% } + +## Some definitions + +- IP address +: Identifier that allows you to get messages/packets +- Subnet +: A defined subset of all IP addresses. For example 192.168.1.0/24 means all IP + addresses from 192.168.1.0 to 192.168.1.255 +- Router +: Machine that connects one subnet to another. Usually, it is the subnet of + your home, to the global internet +- Gateway +: A machine where you send your internet packets, so that they are transferred + to the "real" recipient. It is usually your router. + +::: notes + +- The `/24` in the example subnet is what we call a "mask" + +It is nice to have a postal mail analogy. In this case: + +- IP address is your home address +- Subnet is your town name, street name +- Router and gateway would be your postman company (La Poste, UPS, Fedex, or + whatever) + +::: + +## Network interfaces + +- Represent a way to connect to a network +- Stores each: + - One or more IP address + - A subnet + +::: notes + +- If you have two Ethernet ports, you could connect to two different networks +- In this example you would have one interface for each of your Ethernet port +- And maybe one more interface for your WiFi connection, if you have the + hardware for it + +::: + +## What you need to connect to a network + +- An IP address +- The subnet of your network +- A gateway, if you want to connect your network to other networks, like the + world wide web +- A DNS server's IP address, if you want to resolve host names, like + + +## Configuring a network interface + +- The static way +- The dynamic way + +::: notes + +- The static way is simpler to configure, but you have to know in advance the + device that are going to connect to your network, and have a static IP + address for all of them + - You also have to know in advance the subnet and IP address of your router + +- The dynamic way is the one that you use on your personal computers + - This is the mode were you try to ask for all these parameters + +::: + +## The static way + +```sh +# Set the IP address and subnet +ip addr add $ip/$mask dev $interface +# Activate this interface +ip link set $interface up +# Set the default gateway +ip route add default via $gateway dev $interface +# Add the default DNS server +echo "nameserver $nameserver_ip" >> /etc/resolv.conf +``` + +::: notes + +For QEMU's defaults: + +- `busybox ip addr add 10.0.2.42/24 dev eth0` +- `busybox ip link set eth0 up` +- `busybox ip route add default via 10.0.2.2 dev eth0` +- `echo "nameserver 10.0.2.3" >> /etc/resolv.conf` + +::: + +## The dynamic way + +- DHCP for the win! +- meaning Dynamic Host Configuration Protocol + +. . . + +- we need a DHCP client on our machine and a DHCP server on the network + +::: notes + +DHCP is a protocol that allows us to get all of this information: + +- A new, unused IP address +- The subnet of the network +- The address of the gateway +- The address of the DNS server + +::: + +## DHCP overview + +![DHCP overview[@wikimedia:dhcp]](../res/DHCP_session.png){ height=80% } + +## Implementation + +- Here we can use the `udhcpc` command of Busybox + +# Users + +## Current status + +Right now we have none + +::: notes + +Do a `ls -l` on the machine + +::: + + +## The passwd file + +Each line of `/etc/passwd` contains: + +- Login name (what we were missing) +- Field unused today (was the password, but it got moved to another file) +- Numerical ID of the user +- Numerical ID of the main group for user +- User name or comment +- Home directory +- Optional default shell + +## Example + +```ini +# ,--- tells that the password is in another file +# | +# v +root:x:0:0:System administrator:/root:/bin/sh +``` + +## Login "screen" + +- Now we can add one to the `inittab` +- This is the `getty` command of `busybox` + +# References -- cgit v1.2.3