Erstellen eines Boot

Transcription

Erstellen eines Boot
Erstellen eines Boot-Mediums
Dr.-Ing. Matthias Sand
Lehrstuhl für Informatik 3 (Rechnerarchitektur)
Friedrich-Alexander-Universität Erlangen-Nürnberg
SS 2009
Erstellen eines Boot-Mediums– 1/21– 2009-05-06
Inhalt
Bootloader
Kernel
Initiale RAM-Disk
Boot-Medium
Booten von CD
Erstellen eines Boot-Mediums– 2/21– 2009-05-06
Bootloader
Schritte
Auswahl eines Bootloaders, abhängig von:
Plattform,
gewünschtem Boot-Medium,
gewünschtem Komfort ;)
ggf. bauen aus den Sourcen,
erstellen einer Boot-Konfiguration.
Erstellen eines Boot-Mediums– 3/21– 2009-05-06
GRUB-Konfiguration
Beispiel: menu.lst
# Erster Eintrag ist Standard
default 0
# bootet nach 30 Sekunden
timeout 30
# Booteintrag fuer Linux
title
Install Linux
root
(fd0)
kernel /boot/vmlinuz vga=normal
initrd /boot/initrd.gz
Erstellen eines Boot-Mediums– 4/21– 2009-05-06
Kernel
Schritte
Entweder vorgebauten Kernel (der Boot-Strapping- oder eigenen
Distribution) verwenden oder:
Auswahl der Kernel-Version,
Holen der Sourcen
(http://ftp.linux.org/pub/linux/kernel/v2.6/),
ggf. Patchen des Kernels,
Konfiguration des Kernels
minimalistisch ↔ „full blown”,
monolithisch ↔ modular,
Kernel und Module bauen.
Erstellen eines Boot-Mediums– 5/21– 2009-05-06
Initiale RAM-Disk
Inhalt
/init bzw. /linuxrc,
Kernelmodule (passend zum gebooteten Kernel),
elementare Programme:
zum Laden von Modulen,
ggf. zum Mounten von Dateisystemen,
Shell,
Geräteknoten für
elementare Pseudo-Geräte (z.B. /dev/null),
Konsole und Terminals,
Platten und optische Laufwerke,
Mount-Punkte für weitere Dateisysteme (/proc, /mnt, ...).
Erstellen eines Boot-Mediums– 6/21– 2009-05-06
Initiale RAM-Disk (2)
BusyBox
„Multi-Call-Binary”: ein Binary enthält Code für viele
Programme,
diverse Dienstprogramme aus der Single-Unix-Specification
und der Linux-Welt,
meist mit eingeschränkter Funktionalität,
Auswahl kann zur Build-Zeit konfiguriert werden,
symbolische Links nach /bin/busybox für jedes
Dienstprogramm,
BusyBox wertet argv[0] aus und führt entsprechenden Code
aus.
→ kleiner als viele einzelne Binaries.
Erstellen eines Boot-Mediums– 7/21– 2009-05-06
Initiale RAM-Disk (3)
Beispiel: Inhalt einer initrd
/linuxrc
/bin/sh, /bin/mount, /bin/umount, /bin/cp, /bin/tar, ...
/dev/null, /dev/zero,
/dev/console, /dev/tty[0-7]
/dev/hd*, /dev/sd*
/dev/scd*
/etc/ld.so.conf, /etc/ld.so.cache
/etc/mtab
/lib/ld-linux.*, /lib/libc.so.*
/lib/modules/*
/mnt
/proc
Erstellen eines Boot-Mediums– 8/21– 2009-05-06
Initiale RAM-Disk (4)
Beispiel: Bau einer initrd
insmod l o o p
dd i f =/dev / z e r o o f =/tmp/ i n s t r d . img b s =1024 c o u n t=<s i z e >
l o s e t u p / dev / l o o p 0 /tmp/ i n s t r d . img
mkfs −t e x t 2 / dev / l o o p 0
m k d i r /tmp/ i n s t r d
mount / dev / l o o p 0 /tmp/ i n s t r d
cp . . . /tmp/ i n s t r d / . . .
umount /tmp/ i n s t r d
r m d i r /tmp/ i n s t r d
l o s e t u p −d / dev / l o o p 0
rmmod l o o p
g z i p /tmp/ i n s t r d . img
Erstellen eines Boot-Mediums– 9/21– 2009-05-06
Initiale RAM-Disk (5)
Beispiel: Bau eines initramfs
m k d i r /tmp/ i n i t r a m f s
m k d i r /tmp/ i n i t r a m f s / . . .
cp . . . /tmp/ i n i t r a m f s / . . .
cd /tmp/ i n i t r a m f s
f i n d . | c p i o −ov −H newc > . . / i n i t r a m f s . c p i o
cd . .
gzip initramfs . cpio
rm −Rf i n i t r a m f s
Erstellen eines Boot-Mediums– 10/21– 2009-05-06
Boot-Medium
Früher:
Kernel-Buildsystem lieferte ein bootbares Floppy-Image des
Kernels.
(Seit Linux 2.6 nicht mehr möglich!)
Minimaler Inhalt des Boot-Mediums
Kernel,
ggf. RAM-Disk-Image,
ggf. Stages (z.B. stage2),
ggf. Hilfsdateien des Bootloaders (menu.lst,
Hintergrundbilder, ...).
Erstellen eines Boot-Mediums– 11/21– 2009-05-06
Boot-Medium (2)
Beispiel: Inhalt einer Boot-Disk
/boot/initrd.img.gz
/boot/vmlinuz
/boot/grub/stage2
/boot/grub/menu.lst
Erstellen eines Boot-Mediums– 12/21– 2009-05-06
Boot-Medium (3)
Beispiel: Bau einer Boot-Floppy
mkfs −t e x t 2 / dev / f d 0
m k d i r /tmp/ b o o t d i s k
mount / dev / f d 0 /tmp/ b o o t d i s k
cp . . . /tmp/ b o o t d i s k / . . .
m k d i r −p /tmp/ b o o t d i s k / b o o t / g r u b
cp / u s r / l i b / g r u b / i 3 8 6 −pc / s t a g e 2 /tmp/ b o o t d i s k / b o o t / g r u b
cp . . . /tmp/ b o o t d i s k / b o o t / g r u b
umount /tmp/ b o o t d i s k
r m d i r /tmp/ b o o t d i s k
grub
grub> r o o t ( f d 0 )
grub> s e t u p ( f d 0 )
grub> q u i t
Erstellen eines Boot-Mediums– 13/21– 2009-05-06
Boot-Medium (4)
Problem bei Floppy:
maximale Größe der Boot-Floppy: 1,44 MByte
(eventuell: 2,88 MByte),
Linux-Kern inzwischen > 1 MByte, Module >> 10 MByte,
Shared-Library (glibc) braucht (gezippt) > 500 KByte.
Erstellen eines Boot-Mediums– 14/21– 2009-05-06
Boot-Medium (5)
Lösungsmöglichkeiten:
minimaler Kern,
statisch gebundene(s)
Shell,
Installationsprogramm,
...
Boot-Diskette + Extra-Diskette(n),
kleinere libc:
uClibc,
dietlibc,
klibc,
Boot-Diskette mountet CD,
oder gleich: bootbare CD.
Erstellen eines Boot-Mediums– 15/21– 2009-05-06
Boot-CD
El Torito
Spezifikation eines besonderen Formats für CD-ROMs,
muss vom BIOS unterstützt werden,
BIOS bootet dann „direkt” von CD,
drei Varianten:
Festplatten-Image (Emulation von C:),
Floppy-Image (Emulation von A:),
Programmcode (keine Emulation).
Erstellen eines Boot-Mediums– 16/21– 2009-05-06
Boot-CD (2)
Nutzung von El Torito
mit Emulation:
Vorbereiten eines Boot-Floppy-Images,
Vorbereiten des Daten-Tracks,
Brennen des/der Images auf die CD,
Booten vom emulierten Laufwerk A:,
Init-Skript oder Installer mountet dann eigentlichen
Daten-Track der CD.
→ Platzproblem nicht wirklich gelöst!
ohne Emulation:
verwenden eines Bootloaders mit Bootcode:
isolinux,
GRUB (i.W. derselbe Code wie isolinux).
Erstellen eines Boot-Mediums– 17/21– 2009-05-06
Boot-CD (3)
isolinux
Aus der syslinux-Familie (außerdem: pxelinux, extlinux),
liefert den Bootcode, der vom BIOS geladen und ausgeführt
wird (isolinux.bin),
unterstützt das ISO9660-Dateisystem
→ kann Konfigurationsdateien, Kernel und initrd von CD
nachladen,
bietet Boot-Menüs (isolinux.cfg),
liefert einige Erweiterungsmodule sowie eine API für eigene
Module („COMBOOT”) mit.
Erstellen eines Boot-Mediums– 18/21– 2009-05-06
Boot-CD (3)
Beispiel: isolinux.cfg
DEFAULT /install/linpci
APPEND root=/dev/ram ro initrd=idepci.bin ramdisk_size=16384
LABEL linux
kernel /install/linpci
LABEL bf24
kernel /install/lin24
append root=/dev/ram ro initrd=bf24.bin ramdisk_size=16384
DISPLAY isolinux.txt
TIMEOUT 0
PROMPT 1
F1 f1.txt
F2 f2.txt
Erstellen eines Boot-Mediums– 19/21– 2009-05-06
Boot-CD (4)
Beispiel: Bau einer Boot-CD mit isolinux
m k d i r −p /tmp/ i s o / i s o l i n u x
cp . . . / i s o l i n u x . b i n /tmp/ i s o / i s o l i n u x
cp . . . /tmp/ i s o / . . .
v i /tmp/ i s o / i s o l i n u x / i s o l i n u x . c f g
m k i s o f s −o image . i s o \
−b i s o l i n u x / i s o l i n u x . b i n
−c i s o l i n u x / b o o t . c a t \
−no−emul−b o o t −boot−l o a d −s i z e 4 \
−boot−i n f o −t a b l e \
/tmp/ i s o
rm −Rf /tmp/ i s o
Nun kann image.iso mit einem beliebigen Brennprogramm auf CD gebrannt
werden.
Erstellen eines Boot-Mediums– 20/21– 2009-05-06
Boot-CD (5)
Beispiel: Bau einer Boot-CD mit GRUB
Völlig analog zur isolinux-Methode.
m k d i r −p /tmp/ i s o / b o o t / g r u b
cp . . . / s t a g e 2 _ e l t o r i t o /tmp/ i s o / b o o t / g r u b
cp . . . /tmp/ i s o / . . .
g e n i s o i m a g e −R −b b o o t / g r u b / s t a g e 2 _ e l t o r i t o \
−no−emul−b o o t −boot−l o a d −s i z e 4 \
−boot−i n f o −t a b l e −o g r u b . i s o /tmp/ i s o
rm −Rf /tmp/ i s o
Erstellen eines Boot-Mediums– 21/21– 2009-05-06