FreeBSD - Wie kompiliere ich einen Kernel

saintjoe

Bodybuilder
Ein eigener Kernel ist oftmals unumgänglich, vor allem wenn es darum geht Hardware, die nicht vom Standardkernel unterstützt wird, ans laufen zu bekommen.
Bei FreeBSD 4.x/5.x gibt es zwei Möglichkeiten, einen eigenen Kernel zu erstellen. Wie auch immer, die 'Vorbereitungen' sind stets die gleichen.

Dieses muss als Root ausgeführt werden!!!

Am wichtigsten ist es, die FreeBSD Source Distribution installiert zu haben. Solltest du diese nicht bei der Installation mit Installiert haben, hilft es, die erste CD (Install-CD) einzulegen und sie zu mounten, meistens mit

mount /cdrom

Dann musst du in das Verzeichnis

./src

auf der CD wechseln, typischerweise mit

cd /cdrom/src/

Um dann die Sources zu installieren, einfach

./install.sh all

eingeben. Das kann eine Weile dauern.
Wenn das System damit fertig ist, wechsel in das Verzeichnis

/usr/src/sys/i386/conf/

Kopiere nun die Datei

GENERIC

mit dem Befehl

cp GENERIC MYKERNEL

ersetzte MYKERNEL durch den Namen, den du deinem Kernel geben möchtest.
Nun editier die Datei MYKERNEL.
Hier ein Beispiel einer Kernel-Configuration (hier ist es die meines Clients)
Code:
machine i386
cpu I686_CPU
ident GENERIC
maxusers 0

options INET #InterNETworking
options FFS #Berkeley Fast Filesystem
options FFS_ROOT #FFS usable as root device [keep this!]
options SOFTUPDATES #Enable FFS soft updates support
options UFS_DIRHASH #Improve performance on big directories
options MFS #Memory Filesystem
options MD_ROOT #MD is a potential root device
options NFS #Network Filesystem 
options NFS_ROOT #NFS usable as root device, NFS required
options MSDOSFS #MSDOS Filesystem
options CD9660 #ISO 9660 Filesystem
options CD9660_ROOT #CD-ROM usable as root, CD9660 required
options PROCFS #Process filesystem
options COMPAT_43 #Compatible with BSD 4.3 [KEEP THIS!]
options SCSI_DELAY=15000 #Delay (in ms) before probing SCSI
options UCONSOLE #Allow users to grab the console
options USERCONFIG #boot -c editor
options VISUAL_USERCONFIG #visual boot -c editor
options KTRACE #ktrace(1) support
options SYSVSHM #SYSV-style shared memory
options SYSVMSG #SYSV-style message queues
options SYSVSEM #SYSV-style semaphores
options P1003_1B #Posix P1003_1B real-time extensions
options _KPOSIX_PRIORITY_SCHEDULING
options ICMP_BANDLIM #Rate limit bad replies
options KBD_INSTALL_CDEV # install a CDEV entry in /dev

device isa
device eisa
device pci

# Floppy drives
device fdc0 at isa? port IO_FD1 irq 6 drq 2
device fd0 at fdc0 drive 0
device fd1 at fdc0 drive 1

# ATA and ATAPI devices
device ata0 at isa? port IO_WD1 irq 14
device ata1 at isa? port IO_WD2 irq 15
device ata
device atadisk # ATA disk drives
device atapicd # ATAPI CDROM drives 
device atapifd # ATAPI floppy drives
device atapist # ATAPI tape drives
options ATA_STATIC_ID #Static device numbering

device scbus # SCSI bus (required)

# atkbdc0 controls both the keyboard and the PS/2 mouse
device atkbdc0 at isa? port IO_KBD
device atkbd0 at atkbdc? irq 1 flags 0x1
device psm0 at atkbdc? irq 12

device vga0 at isa?
pseudo-device splash
device sc0 at isa? flags 0x100

# Enable this and PCVT_FREEBSD for pcvt vt220 compatible console driver
#device vt0 at isa?
#options XSERVER # support for X server on a vt console
#options FAT_CURSOR # start with block cursor
# If you have a ThinkPAD, uncomment this along with the rest of the PCVT lines
#options PCVT_SCANSET=2 # IBM keyboards are non-std
# Floating point support - do not disable.
device npx0 at nexus? port IO_NPX irq 13

# Power management support (see LINT for more options)
device apm0 at nexus? flags 0x20 # Advanced Power Management

device sio0 at isa? port IO_COM1 flags 0x10 irq 4
device sio1 at isa? port IO_COM2 irq 3
device sio2 at isa? disable port IO_COM3 irq 5
device sio3 at isa? disable port IO_COM4 irq 9

device ppc0 at isa? irq 7
device ppbus # Parallel port bus (required)
device lpt # Printer


device miibus # MII bus support
device rl # RealTek 8129/8139

pseudo-device loop # Network loopback
pseudo-device ether # Ethernet support
pseudo-device tun # Packet tunnel.
pseudo-device pty # Pseudo-ttys (telnet etc)
pseudo-device snp 3
# The `bpf' pseudo-device enables the Berkeley Packet Filter.
# Be aware of the administrative consequences of enabling this!
pseudo-device bpf #Berkeley packet filter

# USB support
device uhci # UHCI PCI->USB interface
device ohci # OHCI PCI->USB interface
device usb # USB Bus (required)
device ugen # Generic
device ums # Mouse
device uhid # 'Human Interface Devices'
device pcm

options SC_HISTORY_SIZE=5000 # number of history buffer lines
options SC_DISABLE_REBOOT # disable reboot key sequence
options USER_LDT
options SYSVSHM
options SYSVSEM
options SYSVMSG
device agp
options COMPAT_LINUX
device bktr
pseudo-device vn
options UFS_DIRHASH

Welche Devices usw du im Kernel brauchst ist allerdings von Maschine zu Maschine verschieden, daher musst du selber herausfinden was du brauchst! Als Hilfe schau dir einfach die Datei

/usr/src/sys/i386/conf/LINT

an!
Wenn du diese Datei nun gespeichert hast, wechsel in das Verzeichnis

/usr/src/

Gib dort ein:

make buildkernel KERNCONF=MYKERNEL
danach
make installkernel KERNCONF=MYKERNEL


Ersetze MYKERN mit dem von dir oben gewählten Kernelnamen.
Nun fängt dein Rechner wie wild an zu arbeiten. Normalerweise sollte ein Kernel auf einer einigermassen schnellen CPU in ca. 10 Minuten kompiliert sein.
Wenn alles ohne Fehler fertig geworden ist, kannst du deinen Rechner neu starten. Dein neuer Kernel sollte jetzt booten.
Viel Spass und Glück beim kompilieren.
 
Am wichtigsten ist es, die FreeBSD Source Distribution installiert zu haben. Solltest du diese nicht bei der Installation mit Installiert haben, hilft es, die erste CD (Install-CD) einzulegen und sie zu mounten,

Das mit den Sourcen von der CD ist ganz nützlich. Heutzutage macht man das eher mit dem Tool cvsup aus den Ports net/cvsup. Ich installiere gerne cvsup-without-gui.

Mehr dazu hier: http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/cvsup.html

Dann allerdings sollte man auch komplettes world bauen. Siehe: http://www.freebsd.org/doc/de_DE.ISO8859-1/books/handbook/makeworld.html

wechsel in das Verzeichnis

/usr/src/sys/i386/conf/

Kopiere nun die Datei

GENERIC

mit dem Befehl

cp GENERIC MYKERNEL

Ich empfehle hier, die Kernel-Konfigurationsdatei außerhalb von /usr/src zu legen. Am besten irgendwo in /etc und dann einen Softlink von dem jeweiligen conf-Verzeichnis zu legen. Damit sichert man, dass wenn man /usr/src ganz tötet, nicht aus Versehen die wertvolle Konfiguration mitzerstört.

wechsel in das Verzeichnis

/usr/src/

Gib dort ein:

make buildkernel KERNCONF=MYKERNEL
danach
make installkernel KERNCONF=MYKERNEL

Heutzutage haben Leute mehrere Cores. Den Bauvorgang kann man oft beschleunigen, wenn man folgendes benutzt (oft Anzahl der verfügbaren Cores + 1):
Code:
make -j3 buildkernel KERNCONF=MYKERNEL
make -j3 installkernel KERNCONF=MYKERNEL

Wenn alles ohne Fehler fertig geworden ist, kannst du deinen Rechner neu starten. Dein neuer Kernel sollte jetzt booten.
Viel Spass und Glück beim kompilieren.

Wenn der Rechner sich nicht starten lassen sollte, nachdem man einen neuen Kernel geladen hat, kann man auch den alten laden. Dazu gibt man auf dem FreeBSD-Boot prompt das folgende ein:

Code:
unload
kernel /boot/kernel.old/kernel
boot

Vor dem boot kann man mit load modulename auch Module nachladen, die für das rudimentäre Booten des Rechners nötig sind. Dazu kann man folgendermaßen vorgehen (nehmen wir an, dass wir gjournal-Partitionen haben):

Code:
set module_path=/boot/kernel.old
load geom_journal

Wenn man sich wieder einloggen kann, dann kann man das alte funktionierende /boot/kernel.old Verzeichnis wieder nach /boot/kernel umbenennen. Also folgendermaßen:

Code:
cd /boot
mv kernel kernel.kaputt
mv kernel.old kernel

Beim nächsten Boot-Vorgang ist alles wieder beim alten. Also keine Angst vor Updates!
 
Leichenschänder! Wenn du schon einen 6 Jahre alten Beitrag korrigierst, dann doch bitte richtig.

Man nimmt natürlich csup aus der Base.

Also, wer einen Kernel bauen will, lese doch bitte das entsprechende Kapitel im Handbuch. Das lässt eigentlich keine Fragen offen.

Edit:
Äh, ich sehe gerade die Antwort ist auch schon 6 Jahre alt. Wie ist das bitte ganz oben im Portal gelandet bevor ich darauf geantwortet habe? Und wie konnte nakal hier 2 Jahre bevor er sich registriert hat posten?
 
Zuletzt bearbeitet:
Zurück
Oben