]> rtime.felk.cvut.cz Git - edu/osp-wiki.git/blobdiff - cviceni/2-en.mdwn
lectures: minor update of link to LinuxDays 2023 presentation listing.
[edu/osp-wiki.git] / cviceni / 2-en.mdwn
index f1c849bd9b84927461084331cba52eaec92bd841..296e6ea560d165ca844f72140628bbcaa58ee8fa 100644 (file)
@@ -8,8 +8,8 @@ Aim of the Exercises
 The aim of this exercise is to practice building of the base
 system from open-source components presented during 2-nd lecture
 and motivate and practically introduce students for topics presented
-during 4-th lecture  *Linux kernel - beginning, development, components
-and device drivers; GNU libc and user space*. If there are some
+during 4-th lecture  "*Linux kernel - beginning, development, components
+and device drivers; GNU libc and user space*". If there are some
 steps or relations clear to you, we recommend you try Google to find
 information first and prepare to ask questions at the 4-th lecture.
 
@@ -19,7 +19,6 @@ or even distributions. Perhaps the best known is the LAMP stack - Linux,
 Apache, MySQL, PHP. In today's exercise you will learn and experiment
 with another, very often used, a stack of [Linux][kenrel] + [BusyBox][bb] (+[Dropbear][dropbear] SSH server).
 
-
 [BusyBox][bb] is a set of basic/standard UNIX utilities (shell, editor
 and such utilities as ls, mkdir, …) compiled into one binary.
 In combination with the Linux kernel it forms a complete minimal
@@ -161,13 +160,7 @@ The Steps
 
 [gic]:http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=usr/gen_init_cpio.c;hb=HEAD      
 
-5. **The Linux Kernel**. Příprava jádra je téměř stejná jako u BusyBoxu:
-   stáhneme zdrojový kód, nakonfigurujeme a přeložíme. Vzhledem k
-   rozsáhlosti jádra (zkompilované zabere na disku cca 1 GB a překlad
-   trvá cca 20 minut) tyto kroky přeskočíme a použijeme již připravené
-   jádro z distribuce.
-
-   Preparation of the core is quite similar as steps used for BusyBox:
+5. **The Linux Kernel**. Preparation of the kernel is quite similar as steps used for BusyBox:
    the kernel source code is downloaded, configured (i.e. make menuconfig)
    and compiled (make). Given the size of the kernel and required time
    (the build tree takes about 1 GB of disk space and compilation
@@ -204,20 +197,20 @@ The Steps
    When you press Enter then a shell is started and you can test work
    inside a system which you have just created.
 
-Možná vylepšení
-===============
+Possible Enhancements
+=====================
 
-Dále můžete provést drobná vylepšení vašeho systému, která vám mohou
-zjednodušit další práci.
+Additionally, you can work out minor improvements to the system that
+can simplify your further work within a booted system.
 
-1. Můžete připojit souborový systém `/proc`, aby fungovaly příkazy
-   jako např. `ps` (výpis běžících procesů). Příkaz spusťte v
-   emulátoru, ne na vaší pracovní stanici.
+1. You can mount a `/proc` virtual filesystem to allow commands such as `ps`
+   (listing running processes) to function correctly. Use next command in
+   the emulator, not on your workstation.
 
         mount -t proc none /proc
 
-2. V RAM-disku můžete vytvořit soubor `/etc/init.d/rcS`, který bude
-   obsahovat příkazy, které budou spuštěny při bootu systému.
+2. The commands intended to be executed during each system start
+   should be writtent into newly created file `/etc/init.d/rcS`.
 
         mkdir -p _install/etc/init.d
         cat <<EOF > _install/etc/init.d/rcS
@@ -227,20 +220,56 @@ zjednodušit další práci.
         EOF
         chmod +x _install/etc/init.d/rcS    # nastavení spustitelnosti
 
-   Nyní musíte znovu vytvořit RAM-disk a nabootovat.
+   The RAM-disk has to be build again and the system should be booted
+   again to test added functionality.
+
+3. Messages print by kernel messages running in QEMU emulator can be
+   can be redirected to a virtual serial port and captured to a file.
+   This can be achieved by next QEMU options
+
+        qemu -serial file:/tmp/virtual_guest.log ...
+
+   and kernel is run with parameter `console=ttyS0` for console redirection
+
+        qemu -serial file:/tmp/virtual_guest.log -append console=ttyS0 ...
+
+4. The network connection can be provided to the virtual system as well.
+   The most simple option is to use NAT on the user level and emulate
+   standard NIC card hardware for virtualized system
+
+        qemu -net nic,vlan=0,model=ne2k_pci -net user,vlan=0 ...
+
+5. If QEMU or KVM supports Plan9 virtio network then it is it is possible
+   to promote part of the host system directory tree to the virtualized guest
+   system
 
-Jaderné moduly
-==============
+        qemu -virtfs local,path=shared_dir_name,security_model=none,mount_tag=shared_tag ...
 
-Jaderné moduly jsou přeložené kusy kódu, které lze za běhu nahrávat do
-Linuxového jádra. Pokud bychom chtěli nalézt analogickou věc v
-uživatelském prostředí, pak by to byly *sdílené knihovny*. Jaderný
-modul může obsahovat kód ovladače zařízení, podporu určitého
-souborového systému, může přidávat do jádra nové funkce (např.
-firewall) či sloužit jako knihovna pomocných funkcí pro jiné moduly
-(např. libata).
+   The directory tree is then attached (mounted) from guest system through next command
+   sequence
 
-Zdrojový kód jednoduchého jaderného modulu vypadá následovně: 
+        modprobe virtio
+        modprobe virtio_ring
+        modprobe virtio_pci
+        modprobe 9pnet
+        modprobe 9pnet_virtio
+        modprobe 9p
+        mkdir -p /mnt/shareddir
+        mount -t 9p -o trans=virtio shared_tag /mnt/shareddir
+
+
+Kernel Loadable Modules
+=======================
+
+Kernel modules are separate compiled pieces of code that can be loaded
+into running Linux kernel. If we wanted to find an analogy in the user
+environment, then it would be shared *shared/dynamically linked library*
+or program *plugins*. Kernel module can provide device driver functionality,
+can add support for a file system, can add new features to the core
+(i.e., firewalls), or serve as a library of utility functions for other
+modules (i.e., libata).
+
+The example of source code of a simple kernel module follows: 
 
     #include <linux/init.h>
     #include <linux/module.h>
@@ -259,68 +288,71 @@ Zdrojový kód jednoduchého jaderného modulu vypadá následovně:
     
     module_init(hello_init);
     module_exit(hello_exit);
-*Příklad převzat z [LDD3][LDD3].*
+*Example taken from [LDD3][LDD3].*
 
-Překlad modulu provedeme pomocí jednoduchého souboru Makefile, který
-bude obsahovat jedinou řádku (zde předpokládáme, že výše uvedený
-soubor se jmenuje **khello.c**):
+The compilation can be controlled by a simple Makefile,
+which will contain a single line (here we assume that the
+above file is named **khello.c**):
 
     obj-m = khello.o
 
-Nyní stačí zavolat `make` se správnými parametry:
+Now a `make` program has to be invoked with right parameters:
 
     make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
 
-Tímto říkáme, že příkaz `make` načte `Makefile` z adresáře se
-zdrojovými kódy aktuálně běžícího jádra (o který adresář se jedná
-můžete zjistít pomocí `readlink -f /lib/modules/$(uname -r)/build`),
-pomocí proměnné `M` řeknete, že se váš modul nachází v aktuálním
-adresáři a slovo `modules` na konci znamená, že chcete, aby se
-zkompilovaly pouze moduly.
+The parameter `-C` direct a `make` build control tool
+to read kernel installation provided `Makefile` from actual
+running kernel sources/build directory directory (where
+are actual directory located can be check by link examination
+`readlink -f /lib/modules/$(uname -r)/build`). The parameter
+`M` specifies that your module is located in the current
+directory and kernel make-system should build only in that directory.
+The word `modules` on the end means that you want to compiled modules only.
 
-Pokud vše dopadlo dobře, objevil se vám soubor `khello.ko`, což je
-modul, který můžete zavést do jádra příkazem
+If everything goes well, the file `khello.ko` is created as a result
+of compilation, which is module which can be load into kernel by command
 
     insmod khello.ko
 
 
+Assignment
+==========
 
-Zadání
-======
-
-Vytvořte jednoduchý jaderný modul, který po zavedení do jádra vypíše
-vaše jméno (objeví se ve výstupu příkazu `dmesg`). Jinak nemusí dělat nic.
-Předveďte činnost vašeho modulu ve vámi vytvořeném systému běžícím v
-emulátoru.
+Create a simple kernel module, which after logs your name after insertion
+into the kernel. The kernel log can be examined by `dmesg` command.
+No other functionality is required from the module.
+Demonstrate functionality of result of your work in a emulator
+environment with root filesystem created according above described steps.
 
-Kdo se bude nudit, může zkusit rozšířit modul tak, aby se jeho jméno
-objevilo v souboru `/proc/myname` nebo vytvořit jednoduchý ovladač,
-který bude vracet vaše jméno při čtení z `/dev/myname`. Návod najdete
-v [tomto článku][henson_drivers] (strany 2 a 3).
+Who will get bored, may try to extend the module such way that his/her
+name appeared in the file `/proc/myname` or a simple driver
+can be created which would return your name when read from `/dev/myname`
+is issued. Instructions can be found in [this article][henson_drivers] (page 2 and 3).
 
-Tipy a triky
-============
+Tips and Tricks
+===============
 
-* Pro vyvolání určitého příkazu z historie můžete použít klávesu
-  `Ctrl-R` následovanou textem hledaného příkazu. Např:
+* The shell history search by Ctrl-`R` followed by search text
+  can be used to repeat a command already issued. For example:
 
         <Ctrl-R>cpio<Enter>
 
-* Pro rychlé kopírování textu mezi programy (např. příkazy z této stránky do shellu),
-  můžete použít prostřední tlačítko myši. Funguje to tak, že text označíte myší
-  (nemačkáte při tom Ctrl-C) a stiskem prostředního tlačítka myši v terminálovém
-  okně ho vložíte na příkazovou řádku shellu. Tím, že při tom nemusíte šahat na
-  klávesnici vám to půjde rychleji.
-
-* Pokud je Qemu spouštěný přes vzdálené připojení (např. server postel),
-  je potřeba pro zobrazení emulované obrazovky spouštěného stroje
-  buď provést protunelování X protokolu (`ssh -X`) nebo používat Qemu
-  s emulací obrazovky v textovém režimu `qemu -curses`. Další možnost
-  je emulovat HW bez grafické karty `qemu -nographic` a nastavit testovaný
-  systém tak, aby systémová konzole směřovala na sériový port.
-
-Reference
-=========
+* To quickly copy text between programs (i.e., commands from the shell of this page)
+  use a middle mouse button. It works so that the text is selected by mouse
+  left button (the Ctrl-C is not pressed/used) and then position mouse
+  to desired target terminal/window/location and press the middle mouse button.
+  It is not necessary to touch keyboard at all and you get forward faster.
+
+* If the QEMU is executed over a remote connection (i.e. on server postel)
+  then tunneling of X protocol (`ssh -X`) is required to allow
+  QEMU emulated screen of target system to be launched. Or the QEMU
+  and target system can be run with text mode console (`qemu -curses`).
+  Yet another option is to run QEMU without console and graphic card
+  emulation at all (`qemu -nographic`) and setup emulated system system
+  console to be redirected to serial port.
+
+References
+===========
 
 * [ramfs, rootfs and initramfs](http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/filesystems/ramfs-rootfs-initramfs.txt;hb=HEAD)
 * [Early userspace support](http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/early-userspace/README;hb=HEAD)