- Fragen und Tipps bitte hier in den Thread
- Kritik bitte ausschließlich per PN, ICQ oder eMail
- Aktuell
02 Jun 2004 Momentan wird in eine Shell (ash) gebootet, mit der eine rudimentäre Manipulation der Festplatten möglich ist. Dank Bootsplash sieht diese auch recht nett aus.
03 Jun 2004 fbi funktioniert jetzt auch.
07 Jun 2004 Unterstützung für alte Gerätenamen (/dev/sdx, /dev/hdx, etc.) hinzugefügt.
- Grub OK
- Kernel OK
- Initrd OK
- Bootsplash OK
- fbi OK
- Busybox
- RootFs
- ...
Die Motivation
Ich will mit Eurer Hilfe versuchen einen bootfähigen USB-Stick mit einem minimalen System zu erstellen, um Bilder auf einer Framebuffer Konsole anzuzeigen (fbi) und mit gebräuchlichen Tools (Busybox), Daten sichern zu können.
Zwar gibt es viele Mini-Distributionen bzw. Anleitungen die einen ähnlichen Weg gehen, aber leider stelle ich mir oft Fragen auf die selbst Google keine zufriedenstellende Antwort hat. Deswegen hoffe ich, daß wir eine Anleitung für ein minimales USB-System entwickeln, mit der auch Unbedarfte etwas anfangen können.
- Step by step
- Grub
Während der folgenden Schritte gehe ich davon aus, daß die Unterstützung für den USB-Stick in den laufenden Kernel einkompiliert ist (fest oder als Modul) und der Mountpoint /mnt/stick lautet./mnt/stick/boot/grub/grub.confCode: Select all
mke2fs /dev/sda1 mount -t ext2 /dev/sda1 /mnt/stick/ mkdir -p /mnt/stick/boot/grub cp /boot/grub/stage1 /mnt/stick/boot/grub/ cp /boot/grub/stage2 /mnt/stick/boot/grub/ cp /boot/grub/e2fs_stage1_5 /mnt/stick/boot/grub/ cp /boot/grub/splash.xpm.gz /mnt/stick/boot/grub/Den Symlink auf menu.lst nicht vergessenCode: Select all
cat > /mnt/stick/boot/grub/grub.conf << "EOF" title MyMiniLinux splashimage=(hd0,0)/boot/grub/splash.xpm.gz kernel=(hd0,0)/boot/bzImage root=/dev/scsi/host1/bus0/target0/lun0/part1 video=mtrr,vesa:1024x768 vga=0x317 splash=silent initrd=(hd0,0)/boot/initrd.gz EOF
Jetzt den Stick noch bootfähig machen und schon geht's mit dem Kernel weiter:Code: Select all
cd /mnt/stick/boot/grub ln -sf grub.conf menu.lst umount /mnt/stickCode: Select all
grub grub> root (hd1,0) Filesystem type is ext2fs, partition type 0x83 grub> setup (hd1) Checking if "/boot/grub/stage1" exists... yes Checking if "/boot/grub/stage2" exists... yes Checking if "/boot/grub/e2fs_stage1_5" exists... yes Running "embed /boot/grub/e2fs_stage1_5 (hd1)"... 22 sectors are embedded... succeeded Running "install /boot/grub/stage1 (hd1) (hd1)1+22 p (hd1,0)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded Done. grub> quit - Kernel
Vanilla Kernel 2.6.6 von http://www.kernel.org und Bootsplash Patch (bootsplash-3.1.4-2.6.6.diff) von http://www.bootsplash.de/files/
Vor der ersten Konfiguration immer erst die Quellen säubern und den Kernel patchen:Code: Select all
make mrproper patch -p1 < bootsplash-3.1.4-2.6.6.diff make menuconfigDas Kompilieren und Kopieren nicht vergessenCode: Select all
Code maturity level options ---> [*] Prompt for development and/or incomplete code/drivers [*] Select only drivers expected to compile cleanly [*] Select only drivers that don't need compile-time external firmware General setup ---> [*] Support for hot-pluggable devices[*] Configure standard kernel features (for small systems) ---> [*] Enable futex support [*] Enable eventpoll support [*] Anticipatory I/O scheduler [*] Optimize for size Processor type and features ---> Subarchitecture Type (PC-compatible) ---> Processor family (Pentium M) ---> [*] Generic x86 support [*] Preemptible Kernel [*] Machine Check Exception [*] MTRR (Memory Type Range Register) support Power management options (ACPI, APM) ---> [*] Power Management support ACPI (Advanced Configuration and Power Interface) Support ---> [*] ACPI Support [*] Sleep States (EXPERIMENTAL) [*] AC Adapter [*] Battery [*] Button [*] Fan [*] Processor [*] Thermal Zone CPU Frequency scaling ---> [*] CPU Frequency scaling [*] CPU frequency table helpers [*] Intel Enhanced SpeedStep Bus options (PCI, PCMCIA, EISA, MCA, ISA) ---> [*] PCI support PCI access mode (Any) ---> [*] Legacy /proc/pci interface Executable file formats ---> [*] Kernel support for ELF binaries [*] Kernel support for a.out and ECOFF binaries [*] Kernel support for MISC binaries Device Drivers ---> Block devices ---> [*] Loopback device support [*] RAM disk support (4096) Default RAM disk size [*] Initial RAM disk (initrd) support ATA/ATAPI/MFM/RLL support ---> [*] ATA/ATAPI/MFM/RLL support [*] Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support [*] Include IDE/ATA-2 DISK support [*] generic/default IDE chipset support [*] PCI IDE chipset support [*] Sharing PCI IDE interrupts support [*] Generic PCI IDE Chipset Support [*] Generic PCI bus-master DMA support [*] Use PCI DMA by default when available [*] Intel PIIXn chipsets support SCSI device support ---> [*] legacy /proc/scsi/ support [*] SCSI disk support Input device support ---> [*] i8042 PC Keyboard controller [*] Keyboards [*] AT keyboard support Character devices ---> [*] Virtual terminal [*] Support for console on virtual terminal [*] Unix98 PTY support Graphics support ---> [*] Support for frame buffer devices [*] VESA VGA graphics support Console display driver support ---> [*] VGA text console [*] Video mode selection support [*] Framebuffer Console support Bootsplash configuration ---> [*] Bootup splash screen USB support ---> [*] Support for Host-side USB [*] USB device filesystem [*] EHCI HCD (USB 2.0) support [*] UHCI HCD (most Intel and VIA) support [*] USB Mass Storage support File systems ---> [*] Second extended fs support [*] Reiserfs support DOS/FAT/NT Filesystems ---> [*] DOS FAT fs support [*] VFAT (Windows-95) fs support Pseudo filesystems ---> [*] /proc file system support [*] sysfs file system support [*] /dev file system support (OBSOLETE) [*] Automatically mount at boot [*] Virtual memory file system support (former shm fs) Native Language Support ---> (iso8859-1) Default NLS Option [*] NLS ISO 8859-1 (Latin 1; Western European Languages)
Code: Select all
make mount -t ext2 /dev/sda1 /mnt/stick cp arch/i386/boot/bzImage /mnt/stick/boot/ umount /mnt/stick - Initrd
Da es ein Timing-Problem beim Erkennen des USB-Sticks gibt, brauchen wir eine InitialRamdisk (initrd) um eine Pause im Bootvorgang zu erzeugen. Es gibt zwar ein Patch (usb-storage-root.patch), aber leider ist mir keins für den 2.6er Kernel bekannt. Außerdem wird die initrd für den Bootsplash sowieso benötigt.
Als Erstes wird ein leeres Dateisystem erstellt und als Loopback-Device gemounted (Der Kernel muß das Loopback-Device unterstützen und der Mountpoint /mnt/loop muß vorhanden sein):Dann besorgen wir uns die aktuelle Version von Busybox (z.B. busybox-1.00-pre10.tar.gz). Für die initrd kompilieren wir die nötigsten Programme (z.B. echo, usleep, etc.) statisch und kopieren das Binary auf das Loopback-Device:Code: Select all
dd if=/dev/zero of=initrd bs=1024k count=1 mke2fs -F -m0 initrd mount -t ext2 -o loop initrd /mnt/loopCode: Select all
make menuconfigCode: Select all
Build Options ---> [*] Build BusyBox as a static binary (no shared libs) Coreutils ---> [*] echo (basic SUSv3 version taking no options) [*] usleep Another Bourne-like Shell ---> Choose your default shell (ash) ---> [*] Optimize for size instead of speed (NEW)linuxrcCode: Select all
make dep make mkdir -p /mnt/loop/{dev,bin} cp busybox /mnt/loop/bin cd /mnt/loop/bin ln -s busybox ash ln -s busybox echo ln -s busybox sh ln -s busybox usleep
Das linuxrc-Skript wird nach dem Laden der initrd automatisch ausgeführt und enthält alle Befehle, die notwendig sind um auf das RootFs zugreifen zu können. Uns reicht eine kleine Pause, damit der USB-Stick erkannt wird. Falls wichtige Treiber (z.B. für das Dateisystem) als Modul kompiliert wurden, müssen diese hier geladen werden. Da zum Ausführen von Skripten eine Shell benötigt wird, wird auch klar warum die ash-Funktionalität von Busybox aktiviert wurde.
Code: Select all
cat > /mnt/loop/linuxrc << "EOF" #!/bin/sh /bin/echo "Executing Busybox 'usleep 5000000'" /bin/usleep 5000000 /bin/echo "Proceeding ..." EOFCode: Select all
chmod +x /mnt/loop/linuxrc umount /mnt/loop gzip initrd mount /mnt/stick cp initrd.gz /mnt/stick/boot umount /mnt/stick - Bootsplash
Zm Glück benutzen wir ja alle Gentoo
und können uns hier ein paar Schritte ersparen. Zunächst wird der UserSpaceStuff installiert:
Dann besorgen wir uns ein hübsches Theme von Bootsplash.org (z.B Default Linux Theme) und entpacken es nach /etc/bootsplash. Jetzt müssen wir nur noch an unsere initrd.gz das Theme anhängen und schon wird die Konsole bunt.Code: Select all
emerge bootsplash
Das splash-Tool hängt alle für den Bootsplash wichtigen Daten an die initrd. Deswegen muß die initrd vorher gepackt werden (gzip initrd) und nicht hinterher, weil der gepatchte Kernel die Bootsplash-Daten an der initrd.gz und nicht in ihr sucht.
Code: Select all
mount /mnt/stick splash -s -f /etc/bootsplash/Linux/config/bootsplash-1024x768.cfg >> /mnt/stick/boot/initrd.gz umount /mnt/stick
Falls es noch Fragen zum Bootsplash geben sollte, dann werf doch einen Blick in [HOWTO] Gentoo Bootsplash und Framebuffer von equinox0r.
- RootFs + Busybox
Nun werden die benötigten Systemordner und ein paar grundlegende Dateien angelegt:/etc/inittabCode: Select all
mount /mnt/stick mkdir -p /mnt/stick/{bin,dev,etc/init.d,initrd,mnt,proc,root,sbin,sys,tmp,usr/{bin,sbin}}/etc/init.d/rcSCode: Select all
cat > /mnt/stick/etc/inittab << "EOF" ::sysinit:/etc/init.d/rcS ::ctrlaltdel:/sbin/reboot ::shutdown:/bin/umount -a -r vc/1::respawn:/bin/sh vc/2::askfirst:/bin/sh vc/3::once:/bin/dmesg EOFAusführbar macht das Skript gleich nochmal soviel SpaßCode: Select all
cat > /mnt/stick/etc/init.d/rcS << "EOF" #!/bin/sh /bin/echo "Mounting filesystems ..." /bin/mount -a /bin/echo "Starting devfsd ..." /sbin/devfsd /dev EOF
/etc/fstabCode: Select all
chmod +x /mnt/stick/etc/init.d/rcS/etc/passwdCode: Select all
cat > /mnt/stick/etc/fstab << "EOF" none /proc proc defaults 0 0 none /sys sysfs defaults 0 0 none /dev/pts devpts defaults 0 0 none /dev/shm tmpfs defaults 0 0 none /proc/bus/usb usbfs defaults 0 0 EOF/etc/groupCode: Select all
cat > /mnt/stick/etc/passwd << "EOF" root:x:0:0:root:/root:/bin/sh EOF/etc/devfsd.confCode: Select all
cat > /mnt/stick/etc/group << "EOF" root:x:0: bin:x:1: EOFAls nächstes kompilieren wir Busybox mit allen gewünschten Tools:Code: Select all
cat > /mnt/stick/etc/devfsd.conf << "EOF" REGISTER .* MKOLDCOMPAT UNREGISTER .* RMOLDCOMPAT EOFCode: Select all
make menuconfigCode: Select all
General Configuration ---> [*] Support for devfs [*] Use the devpts filesystem for Unix98 PTYs Build Options ---> [*] Build BusyBox as a static binary (no shared libs) Archival Utilities ---> [*] bunzip2 [*] gunzip [*] gzip [*] tar [*] Enable archive creation (NEW) [*] Enable -j option to handle .tar.bz2 files [*] Enable -z option (NEW) Coreutils ---> [*] cat [*] chgrp [*] chmod [*] chown [*] chroot [*] cp [*] dd [*] df [*] echo (basic SUSv3 version taking no options) [*] ls [*] Enable filetyping options (-p and -F) (NEW) [*] Enable symlinks dereferencing (-L) (NEW) [*] Enable recursion (-R) (NEW) [*] Show username/groupnames (NEW) [*] mkdir [*] mknod [*] mv [*] rm [*] rmdir [*] Calculate terminal & column widths (NEW) Editors ---> [*] vi [*] Enable ":" colon commands (no "ex" mode) (NEW) [*] Enable yank/put commands and mark cmds (NEW) [*] Enable search and replace cmds (NEW) [*] Catch signals (NEW) [*] Remember previous cmd and "." cmd (NEW) [*] Enable -R option and "view" mode (NEW) [*] Enable set-able options, ai ic showmatch (NEW) [*] Support for :set (NEW) [*] Handle window resize (NEW) [*] Optimize cursor movement (NEW) Init Utilities ---> [*] init [*] Support reading an inittab file? (NEW) [*] Should init be _extra_ quiet on boot? (NEW) [*] halt [*] poweroff [*] reboot Login/Password Management Utilities ---> [*] Use internal password and group functions rather than system functions [*] getty [*] login [*] passwd [*] su [*] sulogin [*] Support for shadow passwords [*] Use busybox shadow password functions Miscellaneous Utilities ---> [*] devfsd Another Bourne-like Shell ---> Choose your default shell (ash) ---> [*] Optimize for size instead of speed Linux System Utilities ---> [*] dmesg [*] fbset [*] Turn on extra fbset options (NEW) [*] Turn on fbset readmode support (NEW) [*] mount [*] umount [*] Support for loop devicesCode: Select all
make dep make make PREFIX=/mnt/stick install umount /mnt/stick/ - fbi
Code: Select all
emerge fbiEin ldd /usr/bin/fbi gibt uns folgende Shared Libraries aus:Code: Select all
mount /mnt/stick cp /usr/bin/fbi /mnt/stick/usr/bin/Zwar wäre es möglich das Binary statisch zu kompilieren, aber ich hatte während meiner Versuche mehrere nicht reproduzierbare Fehler. Deswegen kopieren wir nun alle erforderlichen Bibliotheken auf den Stick:Code: Select all
linux-gate.so.1 => (0xffffe000) libm.so.6 => /lib/libm.so.6 (0x40021000) libjpeg.so.62 => /usr/lib/libjpeg.so.62 (0x40043000) libungif.so.4 => /usr/lib/libungif.so.4 (0x40061000) libpng.so.3 => /usr/lib/libpng.so.3 (0x40069000) libz.so.1 => /usr/lib/libz.so.1 (0x40094000) libtiff.so.3 => /usr/lib/libtiff.so.3 (0x400a2000) libexif.so.9 => /usr/lib/libexif.so.9 (0x400e9000) libcurl.so.2 => /usr/lib/libcurl.so.2 (0x400fd000) libc.so.6 => /lib/libc.so.6 (0x40127000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x40248000) libssl.so.0.9.7 => /usr/lib/libssl.so.0.9.7 (0x40325000) libcrypto.so.0.9.7 => /usr/lib/libcrypto.so.0.9.7 (0x40356000) libdl.so.2 => /lib/libdl.so.2 (0x40454000)fbi benötigt die Standard-Konsolenschriftart. Diese kopieren wir als Letztes:Code: Select all
mkdir -p /mnt/stick/{lib,usr/lib} cp /lib/libm.so.6 /mnt/stick/lib/ cp /usr/lib/libjpeg.so.62 /mnt/stick/usr/lib/ cp /usr/lib/libungif.so.4 /mnt/stick/usr/lib/ cp /usr/lib/libpng.so.3 /mnt/stick/usr/lib/ cp /usr/lib/libz.so.1 /mnt/stick/usr/lib/ cp /usr/lib/libtiff.so.3 /mnt/stick/usr/lib/ cp /usr/lib/libexif.so.9 /mnt/stick/usr/lib/ cp /usr/lib/libcurl.so.2 /mnt/stick/usr/lib/ cp /lib/libc.so.6 /mnt/stick/lib/ cp /lib/ld-linux.so.2 /mnt/stick/lib/ cp /usr/X11R6/lib/libX11.so.6 /mnt/stick/usr/lib/ cp /usr/lib/libssl.so.0.9.7 /mnt/stick/usr/lib/ cp /usr/lib/libcrypto.so.0.9.7 /mnt/stick/usr/lib/ cp /lib/libdl.so.2 /mnt/stick/lib/Code: Select all
mkdir -p /mnt/stick/usr/share/consolefonts cp /usr/share/consolefonts/lat1-16.psfu.gz /mnt/stick/usr/share/consolefonts/ umount /mnt/stick
- Bisherige Probleme/Fehler und deren Behebung
- Problem: Der USB-Treiber wird geladen, aber kein Gerät sda angelegt. (Hinweis: Vom rootfs /dev/hdaX ist das Booten möglich.)
Deswegen kommt es zu folgender Kernel Panic
Code: Select all
Initializing USB Mass Storage driver... usbcore: registered new driver usb-storage USB Mass Storage support registered.Lösung: Nach dem Laden des USB-Treibers (EHCI, OHCI oder UHCI) dauert es einen Moment, bis der USB-Stick als Gerät initialisiert wird. Leider versucht der Kernel schon vorher das rootfs zu mountenCode: Select all
VFS: Cannot open root device "sda1" or unknown-block(0,0) Please append a correct "root=" boot option Kernel panic: VFS: Unable to mount root fs on unknown-block(0,0)
Deswegen starten wir über eine Initial-Ramdisk (initrd) - die wir für den Bootsplash sowieso benötigen - und warten mit der Hilfe von usleep so lange (bei mir reichen 2 Sekunden), bis /dev/scsi/host1/bus0/target0/lun0/part1 angelegt wird. - Problem: Nach dem Ausführen der /etc/init.d/rcS wird die Konsole gestartet und gibt die folgende Fehlermeldung aus:
Die Konsole funktioniert, aber die Meldung stört.
Code: Select all
Please press Enter to activate this console. BusyBox v1.00-pre10 (2004.06.01-08:33+0000) Built-in shell (ash) Enter 'help' for a list of commands. -sh: can't access tty; job control turned off / #
Das Vergrößern der Ramdisk auf 8192k bringt auch keine Abhilfe (Tip aus: /bin/sh: can`t access tty; job control turned off und BOOT problem).
Ein manuelles Anlegen der Geräte hilft auch nicht.Lösung: Warum auch immer werden keine tty-Geräte in /dev angelegt, auf denen init die Konsole öffnen will. Der folgende Eintrag in der /etc/inittab zwingt init die virtuelle Konsole /dev/vc/0 zu benutzen:Code: Select all
mknod /mnt/stick/dev/tty c 5 0 mknod /mnt/stick/dev/tty0 c 4 0 mknod /mnt/stick/dev/tty1 c 4 1 ...Code: Select all
vc/1::respawn:/bin/sh



