summaryrefslogtreecommitdiffstats
path: root/2020-09-29.md
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2020-10-13 14:46:56 +0200
committerMinijackson <minijackson@riseup.net>2020-10-13 14:46:56 +0200
commit65149417e1deb23f83726edfd41f3215ae0591e0 (patch)
tree90c6bcb4ad6dd9c597d04b51845e02d63c450237 /2020-09-29.md
parentc9e775a44cb316d578827f333531f5101aa29658 (diff)
downloadwtf-is-linux-slides-master.tar.gz
wtf-is-linux-slides-master.zip
add 2020-09-29 and 2020-10-{06,13} slidesHEADmaster
Diffstat (limited to '2020-09-29.md')
-rw-r--r--2020-09-29.md387
1 files changed, 387 insertions, 0 deletions
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 @@
1---
2title: WTF is Linux
3author: Rémi Nicole <remi.nicole@smile.fr>
4date: 2020-09-29
5slide-level: 2
6aspectratio: 169
7
8theme: metropolis
9colortheme: owl
10beameroption: "show notes on second screen=right"
11
12toc: true
13highlightstyle: breezedark
14lang: en-US
15
16bibliography: ../bibliography.bib
17---
18
19# Before we get started
20
21## Reminder
22
23- Please fill the [form](https://mensuel.framapad.org/p/zufgimy2yy-9j3n)
24- Please have a GNU/Linux system with an SD card reader
25
26
27## Where were we
28
29::: notes
30
31- We managed to boot the system!
32- What we needed was:
33 - A file system to store files, and to be used as the root directory
34 - An init program in this file system, and started by the kernel
35
36:::
37
38
39# It works but...
40
41
42## The init problem
43
44- init is a shell
45- we want to automate some tasks:
46 - re-mounting the `/` directory in read-write mode
47 - networking?
48 - anything our system should do
49
50
51## The networking problem
52
53- We want to access the network:
54 - get updates
55 - execute our primary function
56
57
58## The user problem
59
60users, anyone?
61
62::: notes
63
64- At no point in our creation of a system we had to create a user, or add
65 a password
66
67:::
68
69
70# Automating tasks
71
72## Goal
73
74We want to execute programs or code when the system is starting
75
76
77## Attempt number 1
78
79Let's make a shell script
80
81::: notes
82
83- Instead of just launching a command-line as first program, let's execute some
84 commands automatically before, and *then* launch the command-line
85
86:::
87
88
89## Attempt number 2
90
91Let's use SysV-style init
92
93
94## SysV-style init
95
96- The init process reads `/etc/inittab`
97- Starts processes as specified by this configuration
98
99
100## inittab
101
102This file is a series of files in this format:
103
104```ini
105<id>:<runlevels>:<action>:<process>
106```
107
108::: notes
109
110Busybox does not support each of these features
111
112:::
113
114## inittab (Busybox version)
115
116```ini
117# ,-- out of scope
118# |
119# vvv
120 <tty>::<action>:<process>
121```
122
123`action` can be one of:
124
125- sysinit
126: normal process started at boot
127- shutdown
128: process started before shutting down
129- reboot
130: process started before rebooting
131- ...
132
133## inittab example
134
135```ini
136# Mount /proc and /sys, and remount / in read-write mode
137::sysinit:/etc/init.d/mount-special-filesystems
138
139# Setup the network
140::sysinit:/etc/init.d/setup-network start
141
142# Start additional services
143::sysinit:/etc/init.d/miniserve start
144
145# ...
146```
147
148::: notes
149
150- Note the start argument in the two last services
151
152:::
153
154## Changing to SysV-style init
155
156We just have to change the `init=` kernel parameter to Busybox's `init`.
157
158## The long-running processes problem
159
160- We need to launch long-running processes in the background
161- We also need a way to stop them
162
163::: notes
164
165- We might want to stop a process if something goes wrong, if we want to modify
166 the configuration, etc.
167
168:::
169
170
171## The `start-stop-daemon` command
172
173Can do multiple things:
174
175- Start a process in a background
176- Start a process as a different user
177- Write the PID of the launched process into a file (called a "PID file")
178- Kill a process with a PID file
179
180:::notes
181
182- We don't have our users figured out yet
183- Reminder, this is still the old/light way of doing things, so you might not
184 have this command on your Linux
185
186:::
187
188
189## Example service script
190
191```sh
192#!/bin/sh
193
194PIDFILE="/var/run/myprogram.pid"
195
196case "$1" in
197 start)
198 start-stop-daemon -S -p "$PIDFILE" -m -b \
199 -x myprogram -- args...
200 ;;
201 stop)
202 start-stop-daemon -K -p "$PIDFILE"
203 ;;
204esac
205```
206
207# Networking
208
209## What's in an IP packet
210
211![Anatomy of an IP packet[@corkami:rfc791]](../res/rfc791.png){ height=80% }
212
213::: notes
214
215- From this, we can conclude that we need an IP address for every packet sent
216 over IP
217
218- Also, we see that we cannot contact a server through it's domain name (like
219 google.com), we have to use IP addresses
220
221:::
222
223## A home network
224
225![Home network example[@wikimedia:network1]](../res/home-network.jpg){ height=80% }
226
227## Some definitions
228
229- IP address
230: Identifier that allows you to get messages/packets
231- Subnet
232: A defined subset of all IP addresses. For example 192.168.1.0/24 means all IP
233 addresses from 192.168.1.0 to 192.168.1.255
234- Router
235: Machine that connects one subnet to another. Usually, it is the subnet of
236 your home, to the global internet
237- Gateway
238: A machine where you send your internet packets, so that they are transferred
239 to the "real" recipient. It is usually your router.
240
241::: notes
242
243- The `/24` in the example subnet is what we call a "mask"
244
245It is nice to have a postal mail analogy. In this case:
246
247- IP address is your home address
248- Subnet is your town name, street name
249- Router and gateway would be your postman company (La Poste, UPS, Fedex, or
250 whatever)
251
252:::
253
254## Network interfaces
255
256- Represent a way to connect to a network
257- Stores each:
258 - One or more IP address
259 - A subnet
260
261::: notes
262
263- If you have two Ethernet ports, you could connect to two different networks
264- In this example you would have one interface for each of your Ethernet port
265- And maybe one more interface for your WiFi connection, if you have the
266 hardware for it
267
268:::
269
270## What you need to connect to a network
271
272- An IP address
273- The subnet of your network
274- A gateway, if you want to connect your network to other networks, like the
275 world wide web
276- A DNS server's IP address, if you want to resolve host names, like
277 <http://example.com>
278
279## Configuring a network interface
280
281- The static way
282- The dynamic way
283
284::: notes
285
286- The static way is simpler to configure, but you have to know in advance the
287 device that are going to connect to your network, and have a static IP
288 address for all of them
289 - You also have to know in advance the subnet and IP address of your router
290
291- The dynamic way is the one that you use on your personal computers
292 - This is the mode were you try to ask for all these parameters
293
294:::
295
296## The static way
297
298```sh
299# Set the IP address and subnet
300ip addr add $ip/$mask dev $interface
301# Activate this interface
302ip link set $interface up
303# Set the default gateway
304ip route add default via $gateway dev $interface
305# Add the default DNS server
306echo "nameserver $nameserver_ip" >> /etc/resolv.conf
307```
308
309::: notes
310
311For QEMU's defaults:
312
313- `busybox ip addr add 10.0.2.42/24 dev eth0`
314- `busybox ip link set eth0 up`
315- `busybox ip route add default via 10.0.2.2 dev eth0`
316- `echo "nameserver 10.0.2.3" >> /etc/resolv.conf`
317
318:::
319
320## The dynamic way
321
322- DHCP for the win!
323- meaning Dynamic Host Configuration Protocol
324
325. . .
326
327- we need a DHCP client on our machine and a DHCP server on the network
328
329::: notes
330
331DHCP is a protocol that allows us to get all of this information:
332
333- A new, unused IP address
334- The subnet of the network
335- The address of the gateway
336- The address of the DNS server
337
338:::
339
340## DHCP overview
341
342![DHCP overview[@wikimedia:dhcp]](../res/DHCP_session.png){ height=80% }
343
344## Implementation
345
346- Here we can use the `udhcpc` command of Busybox
347
348# Users
349
350## Current status
351
352Right now we have none
353
354::: notes
355
356Do a `ls -l` on the machine
357
358:::
359
360
361## The passwd file
362
363Each line of `/etc/passwd` contains:
364
365- Login name (what we were missing)
366- Field unused today (was the password, but it got moved to another file)
367- Numerical ID of the user
368- Numerical ID of the main group for user
369- User name or comment
370- Home directory
371- Optional default shell
372
373## Example
374
375```ini
376# ,--- tells that the password is in another file
377# |
378# v
379root:x:0:0:System administrator:/root:/bin/sh
380```
381
382## Login "screen"
383
384- Now we can add one to the `inittab`
385- This is the `getty` command of `busybox`
386
387# References