linuxkurs/14.html

403 lines
15 KiB
HTML

<!doctype html>
<html lang="de">
<meta charset="utf-8">
<title>Einführung in Linux</title>
<meta name="description" content="YALC - Yet Another Linux Course ">
<meta name="author" content="Daniel Schubert">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/league.css" id="theme">
<link rel="icon" href="img/openlogo-nd-25.png" type="img/png">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<style type="text/css">
.reveal img{ max-height: 60vh}
</style>
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section data-transition="slide" data-background="#4d7e65" data-background-transition="zoom">
<h1>LINUX</h1>
<h3>Das universelle Betriebssystem</h3>
<p>Eine Einführung - Teil 14
<p> <small>Deutsche Angestellten Akademie</small> </p>
<aside class="notes">
Frage: Fragen zur letzten Stunde?
</aside>
</section>
<section data-transition="slide" data-background="#b5533c" data-background-transition="convex"> <h3>Der Boot Prozess</h3> </section>
<section>
<h4>Boot Ablauf</h4>
<ul>
<li class="fragment ">efi ( bios ) lädt bootloader ( grub2 )</li>
<li class="fragment ">bootloader lädt kernel</li>
<li class="fragment ">Kernel ist modularisiert -> Keine Dateisystemtreiber!!</li>
<li class="fragment ">Lösung: Kernel bindet initrd als RAM-Disk ein</li>
<li class="fragment ">initrd -> enthält zum Systemstart notwendige Module ( zB Dateisystemtreiber, damit Kernel root Partition einbinden kann )</li>
<li class="fragment ">System startet.</li>
</ul>
</section>
<section>
<pre><code class="bash">~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 223,6G 0 disk
├─sda1 8:1 0 245M 0 part /boot/efi
├─sda2 8:2 0 511M 0 part /boot
└─sda3 8:3 0 222,9G 0 part
└─sda3_crypt 253:0 0 222,8G 0 crypt
├─xubuntu--vg-root 253:1 0 215,1G 0 lvm /
└─xubuntu--vg-swap_1 253:2 0 7,7G 0 lvm
</code></pre>
<p>Der Bootloader wohnt in /boot/efi
</section>
<section>
<p>Inhalt von /boot
<pre><code class="bash">
root@workhorse:/boot# ls
config-4.9.0-7-amd64 initrd.img-4.9.0-7-amd64 System.map-4.9.0-8-amd64
config-4.9.0-8-amd64 initrd.img-4.9.0-8-amd64 vmlinuz-4.9.0-7-amd64
grub System.map-4.9.0-7-amd64 vmlinuz-4.9.0-8-amd64
</code></pre>
<p>initrd angucken:<pre><code class="bash">~$ lsinitramfs /boot/initrd.img-$(uname -r)</code></pre>
</section>
<section>
<h3>grub - Grand Unified Boot Loader</h3>
<ul style="font-size: .6em"><li>Liest verschiedene <a href="/wiki/Dateisystem" title="Dateisystem">Dateisysteme</a>:
<ul><li>GRUB Legacy (bis GRUB 0.9x): <a href="/wiki/Ext2" title="Ext2">ext2</a>, <a href="/wiki/Ext3" title="Ext3">ext3</a>, <a href="/wiki/Unix_File_System" title="Unix File System">UFS</a>, <a href="/wiki/Unix_File_System" title="Unix File System">UFS2</a>, <a href="/wiki/Reiser_File_System" title="Reiser File System">ReiserFS</a>, <a href="/wiki/File_Allocation_Table" title="File Allocation Table">FAT</a>, <a href="/wiki/Journaled_File_System" title="Journaled File System">JFS</a>, <a href="/wiki/Minix-Dateisystem" title="Minix-Dateisystem">Minix</a>, <a href="/wiki/Berkeley_Fast_File_System" class="mw-redirect" title="Berkeley Fast File System">FFS</a>, <a href="/wiki/XFS_(Dateisystem)" title="XFS (Dateisystem)">XFS</a>, mit distributionsspezifischen Erweiterungen auch weitere;</li>
<li>GRUB2 (ab GRUB 1.9x) zusätzlich <a href="/wiki/Ext4" title="Ext4">ext4</a>, <a href="/wiki/ZFS_(Dateisystem)" title="ZFS (Dateisystem)">ZFS</a> und <a href="/wiki/Btrfs" title="Btrfs">btrfs</a>.</li></ul></li>
<li>Bootet verschiedene Betriebssysteme per Auswahlmenü und automatischem Zeitablauf (Linux und Windows als <a href="/wiki/Multi-Boot-System" title="Multi-Boot-System">Multi-Boot-System</a>).</li>
<li>Bootet Betriebssysteme von Festplatten, Disketten, CD- und DVD-Laufwerken sowie Flash-Disks.</li>
<li>Verfügt über einen eingebauten <a href="/wiki/Kommandozeileninterpreter" title="Kommandozeileninterpreter">Kommandozeileninterpreter</a> (Shell).</li>
<li>Ist relativ einfach konfigurierbar (Farben, Hintergrundbild, Struktur usw.).</li>
<li>Kann mit einem <a href="/wiki/Passwort" title="Passwort">Passwort</a> gesichert werden.</li>
<li>Kann über <a href="/wiki/Trivial_File_Transfer_Protocol" title="Trivial File Transfer Protocol">TFTP</a> bereitgestellte <a href="/wiki/Linux_(Kernel)" title="Linux (Kernel)">Linux-Kernel</a> booten.</li></ul>
<aside class="notes">
https://de.wikipedia.org/wiki/Grand_Unified_Bootloader
</aside>
</section>
<section>
Interessante Dateien:
<p>/etc/default/grub -> Anpassungen
<p>/etc/grub.d/ -> scripts die boot.cfg generieren
<pre><code class="bash">00_header*
05_debian_theme*
10_linux*
20_linux_xen*
20_memtest86+*
30_os-prober*
30_uefi-firmware*
40_custom*
41_custom*
</code></pre>
<p>/boot/grub/grub.cfg -> nicht bearbeiten!
</section>
<section>
<p>/etc/default/grub
<pre><code class="bash">
GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
GRUB_BACKGROUND="/usr/share/images/grub/050817-N-3488C-028.tga"
</code></pre>
<a href="https://wiki.ubuntuusers.de/GRUB_2/Aussehen_-_einfache_Konfiguration/">Aussehen verändern</a>
<p>nach Änderung: <pre><code>sudo update-grub</code></pre>
</section>
<section>
optional: grub-customizer
<p><a href="https://answers.launchpad.net/grub-customizer/+faq/1397">grub-customizer aus quellen bauen</a>
<p><a href="https://launchpad.net/~danielrichter2007/+archive/ubuntu/grub-customizer">grub-customizer ppa</a>
</section>
<section>
<img src="img/uefi-vs-bios.png">
<small style="font-size: .4em">Quelle: https://www.makeuseof.com/tag/bootkit-nemesis-genuine-threat/</small>
</section>
<section>
<h4>Secure Boot</h4>
<ul>
<li class="fragment">bootet ausschliesslich Signierte Kernel. Einzige mögliche Signatur: kommt von Microsoft......
<li class="fragment">Microsoft stellt Linux-Distributoren Key zur Verfügung -> ein paar Distrib. unterstützen Secure Boot.
<li class="fragment">Debian zur Zeit nicht.
<li class="fragment">Secure Boot verhindert Starten von selbst kompilierten Kerneln
<li class="fragment">Microsoft kontrolliert also auf ALLEN Mainboards welche Betriebssysteme bei aktiviertem Secure Boot starten können. Auf ALLEN.
</ul>
</section>
<section data-transition="slide" data-background="#b5533c" data-background-transition="convex"> <h3>C und C-Compiler</h3> </section>
<section>
Ein einfaches C-Programm
<pre><code class="c">
#include&lt;stdio.h&gt;
int main() {
printf("Hello World\n");
return 0;
}
</code></pre>
</section>
<section>
<img src="img/Compiler.gif">
</section>
<section>
<p>Wir benötigen:
<ul>
<li class="fragment ">einen C-Compiler</li>
<li class="fragment ">diverse Bibliotheken</li>
<li class="fragment "><pre><code class="bash">~$ sudo apt install build-essential</code></pre></li>
<li class="fragment"><a href="https://packages.debian.org/stretch/build-essential">https://packages.debian.org/stretch/build-essential</a></li>
</ul>
</section>
<section>
Code compilieren:
<pre><code class="bash">~$ gcc hello.c -o hello
# Programm ausführen
~$ ./hello
</code></pre>
</section>
<section style="font-size: .6em">
<h3>Begriffe</h3>
<table>
<tr>
<td>C</td>
<td>Programmiersprache - Der Linux-Kernel ist in „C“ geschrieben</td>
</tr>
<tr>
<td>Compiler</td>
<td>Übersetzt den Quellcode in Maschinencode</td>
</tr>
<tr>
<td>gcc</td>
<td>Gnu C-Compiler Collection</td>
</tr>
<tr>
<td>Bibliotheken</td>
<td>Fertige Funktionen, die in andere Programme eingebunden werden ( unter Windoes oft *.dll-Dateien )</td>
</tr>
<tr>
<td>make</td>
<td>arbeitet Regeln und Abhängigkeitsdefinitionen in „Makefile“ ab -> startet den gcc</td>
</tr>
</table>
</section>
<section data-transition="slide" data-background="#b5533c" data-background-transition="convex"> <h3>der Linux Kernel</h3></section>
<section> <img src="img/Kernel_Layout.svg.png"> </section>
<section>
<p>Befehle
<ul>
<li class="fragment ">lsusb</li>
<li class="fragment ">lscpu</li>
<li class="fragment ">lspci</li>
<li class="fragment ">lsmem</li>
<li class="fragment ">lshw</li>
<h5 class="fragment ">Kernelmodule</h5>
<li class="fragment ">lsmod - listet geladene KM</li>
<li class="fragment ">modprobe - laden und löschen v. KM</li>
<li class="fragment ">insmod - lädt KM ohne Abhängigkeiten</li>
<li class="fragment ">rmmod - löscht KM ohne Abhängigkeiten</li>
</ul>
</section>
<section>
<h4>Was zum?? ist ein Kernel Modul??</h4>
<ul>
<li class="fragment ">ein Stück kompilierten Codes, der zur Laufzeit in den Kernel eingefügt werden kann ( zb Treiber )</li>
<li class="fragment ">Erweitert d. Funktionalität d. Kernels</li>
<li class="fragment ">Reboot de Systems nicht nötig</li>
<li class="fragment ">Ohne Module müsste man Monolithische Kernel bauen und neue Funktionalität direkt ins Kernel Image integrieren </li>
<li class="fragment ">-> Kernel Image wird grösser sein</li>
</ul>
</section>
<section>
<ul>
<li >Die meisten Hardwarekomponenten in eurem Computer haben einen zugehörigen Treiber.</li>
<li class="fragment">Ein großer Teil eines laufenden Kernels ist Treibercode.</li>
<li class="fragment">Ein Treiber kann statisch in die Kerneldatei auf der Festplatte eingebaut werden.</li>
</ul>
</section>
<section>
Moderne Linuxe bieten umfangreichen Treiber-Support, manuelles Laden von KM ist praktisch nie nötig.
<p>Gegenbeispiel:<p> NVIDIA Treiber f. Gaming GraKas<br> manche Drucker ( jaaa, immer noch... )
</section>
<section>
<h3>Manuelle Konfiguration von KM</h3>
<pre><code class="bash">/etc/modprobe.d/*.conf</code></pre>
<h3>Liste der Kernelmodule</h3><pre style="font-size: .5em"><code class="bash">~$ basename -s ".ko" $(find /lib/modules/$(uname -r) \
-type f -name "*.ko") </code></pre></li>
</section>
<section>
<h3>Wir bauen ein Kernel-Modul</h3>
</section>
<section>
<p>Wir benötigen hierfür git: <pre><code class="bash">~$ sudo apt install git</code></pre>
<p>Ein Album als kernelmodul??
<a href="https://github.com/usrbinnc/netcat-cpi-kernel-module">https://github.com/usrbinnc/netcat-cpi-kernel-module</a>
</section>
<section>
<h3>wir bauen uns einen Kernel</h3>
<ol>
<li class="fragment">Download der Kernel Quellen </li>
<li class="fragment">Installieren der build tools</li>
<li class="fragment">Kernel bauen ;-)</li>
</ol>
</section>
<section>
<p>Aktuelle Kernel Quellen herunterladen
<a href="https://www.kernel.org">https://www.kernel.org</a>
</section>
<section>
<pre><code class="bash">
$ sudo apt-get install build-essential \
libncurses5-dev gcc libssl-dev bc
# für XXXXXXX entspr. Kernel Version einsetzen!
$ cd ~/Downloads
$ tar xvf linux-XXXXXXX.tar.xz
$ cd linux-XXXXXXX
$ cp /boot/config-4.13-XXXXXXX .config
$ make menuconfig
</code></pre>
</section>
<section><img src="img/menu-1.png"></section>
<section>Folgendes bitte zu Hause probieren::<pre><code class="bash"># Das dauert jetzt....
# ca 90min auf einem Core i3 @2.4MHz
# -j 4 -> Nutze 4 Kerne
~$ make -j4 deb-pkg
#Kernel installieren:
~$ sudo dpkg -i ../linux-*.deb
# reboot -> neuen Kernel wählen
</code></pre>
<a href="https://debian-handbook.info/browse/stable/sect.kernel-installation.html">Debian Handbbok - Installing a kernel</a></section>
<!--
<section>
<ul>
<li class="fragment ">mysql</li>
<li class="fragment ">LAMP</li>
<li class="fragment ">Multimedia</li>
<li class="fragment ">Gimp</li>
</ul>
</section>
-->
<!--
<section>
Übungen
C 11.11 [3] Besorgen Sie sich eine geeignete Datei (etwa ein größeres tar -Ar-
chiv mit Quellcode, vielleicht für den Linux-Kernel) und komprimieren Sie
sie jeweils mit gzip , bzip2 und xz . Messen Sie dabei die Ausführungszeit
durch ein vorgesetztes time . Wie verhalten die Laufzeiten und die Kompri-
mierungsraten sich zueinander?
C 11.12 [2] Experimentieren Sie mit der Datei aus der vorigen Aufgabe und
vergleichen Sie die Laufzeit und die Größe des Resultats für xz mit verschie-
denen Effizienz-Optionen. Was ist der Unterschied zwischen -1 und -6 und
zwischen -6 und -9 ?
</section>
-->
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// More info https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// More info https://github.com/hakimel/reveal.js#dependencies
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/search/search.js', async: true },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>