Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
|
start [2025/12/05 18:38] jango |
start [2025/12/10 10:09] (aktuell) jango |
||
|---|---|---|---|
| Zeile 11: | Zeile 11: | ||
| ~~ORPHANSWANTED: | ~~ORPHANSWANTED: | ||
| - | < | ||
| - | config system interface | ||
| - | edit port1 | ||
| - | set ip 172.21.1.167 255.255.254.0 | ||
| - | set allowaccess ping | ||
| - | next | ||
| - | edit port2 | ||
| - | set ip 10.100.0.1 255.255.255.0 | ||
| - | set allowaccess ping | ||
| - | next | ||
| - | end | ||
| - | |||
| - | config router static | ||
| - | edit 1 | ||
| - | set gateway 172.21.0.1 | ||
| - | set device port1 | ||
| - | next | ||
| - | end | ||
| - | |||
| - | config firewall policy | ||
| - | edit 1 | ||
| - | set name " | ||
| - | set srcintf " | ||
| - | set dstintf " | ||
| - | set srcaddr " | ||
| - | set dstaddr " | ||
| - | set schedule " | ||
| - | set service " | ||
| - | set action accept | ||
| - | set nat enable | ||
| - | next | ||
| - | end | ||
| - | </ | ||
| - | |||
| - | =====Kernel===== | ||
| - | |||
| - | < | ||
| - | ┌──(manuel㉿kali)-[~/ | ||
| - | └─$ cat run.sh | ||
| - | #assemble boot.s file | ||
| - | as --32 boot.s -o boot.o | ||
| - | |||
| - | #compile kernel.c file | ||
| - | gcc -m32 -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O1 -Wall -Wextra | ||
| - | |||
| - | gcc -m32 -c utils.c -o utils.o -std=gnu99 -ffreestanding -O1 -Wall -Wextra | ||
| - | |||
| - | gcc -m32 -c char.c -o char.o -std=gnu99 -ffreestanding -O1 -Wall -Wextra | ||
| - | |||
| - | #linking the kernel with kernel.o and boot.o files | ||
| - | ld -m elf_i386 -T linker.ld kernel.o utils.o char.o boot.o -o MyOS.bin -nostdlib | ||
| - | |||
| - | #check MyOS.bin file is x86 multiboot file or not | ||
| - | grub-file --is-x86-multiboot MyOS.bin | ||
| - | |||
| - | #building the iso file | ||
| - | mkdir -p isodir/ | ||
| - | cp MyOS.bin isodir/ | ||
| - | cp grub.cfg isodir/ | ||
| - | grub-mkrescue -o MyOS.iso isodir | ||
| - | |||
| - | #run it in qemu | ||
| - | qemu-system-x86_64 -cdrom MyOS.iso | ||
| - | |||
| - | ┌──(manuel㉿kali)-[~/ | ||
| - | └─$ bash run.sh | ||
| - | ld: kernel.o: in function loop': kernel.c: | ||
| - | grub-file: error: cannot open `MyOS.bin': | ||
| - | cp: cannot stat ' | ||
| - | xorriso 1.5.6 : RockRidge filesystem manipulator, | ||
| - | |||
| - | Drive current: -outdev ' | ||
| - | Media current: stdio file, overwriteable | ||
| - | Media status : is blank | ||
| - | Media summary: 0 sessions, 0 data blocks, 0 data, 10.6g free | ||
| - | Added to ISO image: directory '/' | ||
| - | xorriso : UPDATE : 338 files added in 1 seconds | ||
| - | Added to ISO image: directory '/' | ||
| - | xorriso : UPDATE : 341 files added in 1 seconds | ||
| - | xorriso : NOTE : Copying to System Area: 512 bytes from file '/ | ||
| - | ISO image produced: 5057 sectors | ||
| - | Written to medium : 5057 sectors at LBA 0 | ||
| - | Writing to ' | ||
| - | |||
| - | QEMU sagt | ||
| - | |||
| - | error: file '/ | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | |||
| - | Warum der Build fehlschlägt (undefined reference to strcmp) | ||
| - | |||
| - | Die entscheidende Zeile ist: | ||
| - | |||
| - | text | ||
| - | |||
| - | ld: kernel.o: in function `loop': | ||
| - | kernel.c: | ||
| - | |||
| - | Du baust ein freestanding Kernel-Binary: | ||
| - | |||
| - | Bash | ||
| - | |||
| - | gcc -m32 ... -ffreestanding -nostdlib | ||
| - | |||
| - | In so einem Umfeld gibt es keine libc, also auch kein fertiges strcmp. | ||
| - | Du rufst strcmp in kernel.c aber auf, ohne es selbst zu implementieren. | ||
| - | |||
| - | Lösung: Implementiere strcmp selbst, z.B. in utils.c: | ||
| - | |||
| - | C | ||
| - | |||
| - | // utils.c | ||
| - | int strcmp(const char *s1, const char *s2) { | ||
| - | while (*s1 && (*s1 == *s2)) { | ||
| - | s1++; | ||
| - | s2++; | ||
| - | } | ||
| - | return (unsigned char)*s1 - (unsigned char)*s2; | ||
| - | } | ||
| - | |||
| - | Und in der Header-Datei, | ||
| - | |||
| - | C | ||
| - | |||
| - | int strcmp(const char *s1, const char *s2); | ||
| - | |||
| - | Danach neu bauen: | ||
| - | |||
| - | Bash | ||
| - | |||
| - | bash run.sh | ||
| - | |||
| - | Wenn ld dann ohne Fehler durchläuft, | ||
| - | |||
| - | Warum GRUB in QEMU '/ | ||
| - | |||
| - | QEMU/ | ||
| - | |||
| - | text | ||
| - | |||
| - | error: file '/ | ||
| - | |||
| - | In deinem Script kopierst du: | ||
| - | |||
| - | Bash | ||
| - | |||
| - | cp MyOS.bin isodir/ | ||
| - | |||
| - | Also mit großem M: MyOS.bin. | ||
| - | |||
| - | In der Fehlermeldung sucht GRUB aber nach myOS.bin (kleines m). | ||
| - | ISO9660/ | ||
| - | |||
| - | Lösung: In deiner grub.cfg (liegt bei dir in grub.cfg, wird nach isodir/ | ||
| - | |||
| - | cfg | ||
| - | |||
| - | menuentry " | ||
| - | multiboot / | ||
| - | boot | ||
| - | } | ||
| - | |||
| - | Achte auf: | ||
| - | |||
| - | Pfad: / | ||
| - | Groß-/ | ||
| - | |||
| - | Warum grub-file und cp meckern | ||
| - | |||
| - | Nach dem ld‑Fehler wird MyOS.bin gar nicht erzeugt, deshalb: | ||
| - | |||
| - | text | ||
| - | |||
| - | grub-file: error: cannot open `MyOS.bin': | ||
| - | cp: cannot stat ' | ||
| - | |||
| - | Das ist nur eine Folge des ersten Fehlers (strcmp). Sobald du strcmp implementierst und ld erfolgreich ist, verschwinden diese Meldungen. | ||
| - | |||
| - | Kleiner Qualitäts-Tipp für dein Script | ||
| - | |||
| - | Ganz oben in run.sh: | ||
| - | |||
| - | Bash | ||
| - | |||
| - | #!/bin/bash | ||
| - | set -e | ||
| - | |||
| - | Dann bricht das Script sofort ab, wenn ein Befehl fehlschlägt (z.B. ld), und du baust nicht versehentlich ein ISO ohne Kernel. | ||
| - | |||
| - | Optional zusätzlich: | ||
| - | |||
| - | Bash | ||
| - | |||
| - | rm -rf isodir | ||
| - | |||
| - | vor mkdir -p isodir/ | ||
| - | |||
| - | Zusammenfassung der Schritte: | ||
| - | |||
| - | strcmp selbst implementieren (z.B. in utils.c) und deklarieren. | ||
| - | In grub.cfg denselben Dateinamen wie in cp benutzen (/ | ||
| - | Script mit set -e absichern. | ||
| - | bash run.sh erneut ausführen, dann QEMU starten. | ||
| - | |||
| - | Wenn du magst, poste kernel.c, utils.c und grub.cfg, dann kann ich dir konkret zeigen, wo du was einfügen musst. | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | // utils.c | ||
| - | int strcmp(const char *s1, const char *s2) { | ||
| - | while (*s1 && (*s1 == *s2)) { | ||
| - | s1++; | ||
| - | s2++; | ||
| - | } | ||
| - | return (unsigned char)*s1 - (unsigned char)*s2; | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | # utils.h | ||
| - | extern int strcmp(const char *s1, const char *s2); | ||
| - | </ | ||