GRUB

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page GRUB and the translation is 67% complete.

GRUB 2 (GRand Unified Bootloader Version 2), teilweise auch GRUB2 genannt, meistens allerdings nur GRUB, ist ein Multiboot-fähiger sekundärer Bootloader welcher den Kernel aus einer Vielzahl an Dateisystemen laden kann und die meisten Architekturen unterstützt. GRUB unterstützt PC BIOS, PC EFI, IEEE 1275 (Open Firmware), SPARC und MIPS Lemote Yeelong.

GRUB 2 besitzt eine von Grund auf neu entwickelte Codebase und ersetzt damit den originalen GRUB Legacy Bootloader. Eingeführt wurde eine neue Shell-Syntax durch die der Bootvorgang weiter anpassbar gemacht wird.

Für eine einfache Grundkonfiguration, siehe GRUB2 Quick Start.

Für Infos zur Migration von GRUB Legacy zu GRUB2, siehe GRUB2 Migration.

Installation

Voraussetzungen

Die GRUB_PLATFORMS Variable in der make.conf kontrolliert das Ziel welches mit grub-install benutzt werden soll. Auf amd64 Systemen wird standardmäßig ein Profil beigefügt, welches mit den meisten Systemen kompatibel sein sollte.

DATEI /etc/portage/make.confBeispieleinstellung der GRUB_PLATFORMS Variable für EMU, EFI und PC Plattformen
GRUB_PLATFORMS="emu efi-32 efi-64 pc"

Die folgenden Plattformen werden, abhängig von der CPU, unterstützt:

Plattform Zielsystem
i386 ia64 mips mipsel powerpc sparc64 x86_64
ARC No No No Yes No No No
Coreboot Yes No No No No No 32-bit
EFI Yes Yes No No No No Yes
EMU Yes Yes Yes Yes Yes Yes Yes
IEEE 1275 (Open Firmware) Yes No No No Yes Yes 32-bit
Loongson No No No Yes No No No
Multiboot Yes No No No No No 32-bit
QEMU Yes No No No No No 32-bit
QEMU-MIPS No No Yes No No No No
PC Yes No No No No No 32-bit
Hinweis
Nach einer Änderung der GRUB_PLATFORMS Variable ist es erforderlich GRUB zu re-emergen um die Binärdateien neu zu erstellen. Stellen sie sicher, dass die --newuse --deep Optionen genutzt werden wie weiter unten in Emerge gezeigt.

Alle amd64 Profile unterstützen standardmäßig (U)EFI Funktionalität. Bei Benutzung eines BIOS-basierten Systems sollte die GRUB_PLATFORMS Variable zu pc gestellt werden um unnötige Abhängigkeiten zu vermeiden.

USE flags

USE flags for sys-boot/grub GNU GRUB boot loader

device-mapper Enable support for device-mapper from sys-fs/lvm2
doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
efiemu Build and install the efiemu runtimes
fonts Build and install fonts for the gfxterm module
libzfs Enable support for sys-fs/zfs
mount Build and install the grub-mount utility
nls Add Native Language Support (using gettext - GNU locale utilities)
sdl Add support for Simple Direct Layer (media library)
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)
themes Build and install GRUB themes (starfield)
truetype Build and install grub-mkfont conversion utility
verify-sig Verify upstream signatures on distfiles

Emerge

Nutzen sie die folgenden Optionen um GRUB zu installieren:

root #emerge --ask --newuse --deep sys-boot/grub

Zusätzliche Software

Optional kann auch os-prober (bereitgestellt durch das sys-boot/os-prober Packet) installiert werden um es GRUB zu ermöglichen bei Ausführung von grub-mkconfig nach anderen Betriebssystemen zu suchen, und für diese Booteinträge zu generieren. In den allermeisten Fällen erlaubt dies GRUB andere Betriebssysteme wie z.B: Windows 7, 8.1, 10, andere Linux Distributionen, etc. zu erkennen.

root #emerge --ask --newuse sys-boot/os-prober

Die Installation von GRUB (und optional auch sys-boot/os-prober) aktivieren nicht automatisch den Bootloader als solchen. Portage installiert nur die Software auf dem System, nicht aber den Bootloader selbst. Um eine funktionierende (bootbare) GRUB-Installation zu erhalten muss weitere Konfiguration erfolgen, was in Konfiguration beschrieben wird.

GRUB Bootloader Installation

Wie die Installation von GRUB als Bootloader funktioniert, hängt von der Firmware des Computers (entweder BIOS oder der Nachfolger UEFI) und davon wie die Festplatte partitioniert werden soll (MBR oder GPT) ab.

Dieser Artikel behandelt die folgenden Situationen:

Wählen sie die zu ihrem System passende Installationsanleitung.

UEFI mit GPT

Warnung
Auch wenn 64-Bit x86 Prozessoren ("x86-64" oder auch "x64") legacy 32-Bit Software unterstützen, gilt dies nicht auch für die EFI Implementation. Einem 64-Bit EFI ist es nicht möglich 32-Bit .efi Einträge auszuführen! In manchen Fällen nutzen einige wenige 64-Bit fähige Systeme, also Systeme mit einem x64 Prozessor (ein x86 Prozessor welcher mit AMD64 oder Intel 64 ausgestattet ist), eine 32-Bit Implementation von EFI, z.B. einige frühe MacBooks (Intel Core 2) und einige Windows Computer von vor 2010. In diesen Fällen ist (U)EFI als 32-Bit software implementiert und efi32 ist das richtige EFI Ziel, auch wenn der Prozessor 64-Bit ist. Denn genau wie ein 64-Bit EFI keine 32-Bit .efi Einträge starten kann, kann ein 32-Bit EFI auch keine 64-Bit Einträge starten.
Hinweis
Falls UEFI-CSM genutzt wird, siehe BIOS mit MBR oder BIOS mit GPT. CSM steht für "Compatibility Support Module" und ist eine Emulation von BIOS, welche UEFI wie BIOS agieren lässt. Im Firmware Setup wird dies oft mit "Legacy Mode" oder "Compatibility Mode" betitelt. UEFI-CSM war schon immer optional und wurde in normalen Systemen (z.B. PCs) in 2020 abgeschafft.

Partitionierung für UEFI mit GPT

Wichtig
Um UEFI GPT zu booten muss das System eine dedizierte EFI Systempartition, formatiert in FAT, besitzen.

UEFI Systeme booten von efi Dateien in ihrer jeweiligen EFI Systempartition (ESP). Es ist relativ egal welche Größe die EFI Systempartition besitzt, wobei eine zu groß dimensionierte EFI Partition natürlich nur Platz wegnimmt.

Die EFI Systempartition kann entweder nur den Bootloader, oder den Bootloader zusammen mit benötigten Dateien enthalten. Typischerweise enthält /boot den Kernel zusammen mit zusätzlichen benötigten EFI Konfigurationsdateien, während /boot/efi die tatsächlichen bootbaren EFI Dateien enthält, welche normalerweise relativ klein sind.

Hinweis
Die EFI Systempartition kann entweder unter /boot oder /boot/efi eingerichtet werden, wobei /boot normalerweise die simplere Lösung ist. Die Nutzung von /boot/efi ermöglicht es Dateien wie den Kernel und Bootloader Konfigurationsdateien auf einer separaten Partiiton und Dateisystem oder auch dem Root-Dateisystem selbst zu speichern; letzteres setzt voraus, dass GRUB Zugriffsrechte auf das Root-Dateisystem besitzt um die benötigten Dateien zu lesen, was teilweise nicht möglich oder nur kompliziert einzurichten ist (z.B. mit einem verschlüsseltem Root-Dateisystem).

Eine angemessene Größe für eine eigenständige EFI Systempartition unter /boot/efi ist 128mb. Dies ist groß genug für mehrere .efi-Dateien.

Hinweis
Es kann nicht schaden Backups von aktuellen .efi Dateien zu machen, welche auch nachdem sie ersetzt werden noch gebootet werden können.

Erstellen sie die Partition mit der Partitionierungssoftware ihrer Wahl.

Partitionierung mit fdisk
Hinweis
Im Gentoo Handbuch, unter Vorbereiten der Festplatte(n), wird /boot als Mountpoint für die ESP verwendet. Abhängig davon wie sie ihr System konfigurieren möchten, könnte es sinnvoll sein eine separate Partition für /boot zu erstellen, z.B. im Falle eines verschlüsselten Dateisystems.

Wenn sie fdiskzur Partitionierung verwenden, starten sie das Programm und wählen sie die zu partitionierende Festplatte aus, hier /dev/sda:

root #fdisk /dev/sda
Willkommen bei fdisk (util-linux 2.38.1).
Änderungen werden vorerst nur im Speicher vorgenommen, bis Sie sich entscheiden, sie zu schreiben.
Seien Sie vorsichtig, bevor Sie den Schreibbefehl anwenden.

Eine neue Partitionstabelle kann mit "g" erstellt werden:

Befehl (m für Hilfe):g

Eine neue GPT-Festplattenbezeichnung wurde erstellt (GUID: 4AB36B49-BAAD-D544-AC45-E3154565018D).

Eine neue Partition kann mit "n" erstellt werden:

Befehl (m für Hilfe):n
 
Partitionsnummer (1-128, Vorgabe 1): 1
Erster Sektor (2048-121012190, Vorgabe 2048):
Letzter Sektor, +/-Sektoren oder +/-Größe{K,M,G,T,P} (2048-121012190, Vorgabe 121010175): +128m

Eine neue Partition 1 des Typs »Linux filesystem« und der Größe 128 MiB wurde erstellt.

Sobald die Partition erstellt ist müssen die ESP und Boot Flags gesetzt werden, dies erfolgt durch das Umstellen des Partitionstyps zu EFI System. Geben sie dazu "t" ein, der EFI System Partitionstyp hat die Nummer 1.

Befehl (m für Hilfe):t
 
Partitionsnummer (1-x, Vorgabe 1): 1
Partitionstyp oder Alias (geben Sie L ein, um alle Typen aufzulisten): 1
 
Partitionstyp von »Linux filesystem« nach »EFI System« geändert.

Zum Schluss können die Änderungen mit "w" gespeichert werden.

Befehl (m für Hilfe):w
 
Die Partitionstabelle wurde verändert.
ioctl() wird aufgerufen, um die Partitionstabelle neu einzulesen.
Festplatten werden synchronisiert.

Die neu erstellte Partition kann nun wie folgt mit FAT32 formatiert werden:

root #mkfs.fat -F 32 -n efi-boot /dev/sda1
root #mkdir /boot/efi

um die Partition UUID (PARTUUID) herauszufinden kann der folgende Befehl genutzt werden:

user $lsblk -o name,partuuid
lsblk -o name,partuuid
NAME         PARTUUID
sdd          
└─sd1       20f3d6cc-9781-3640-9232-0f5a8c662a60

Nun erstellen sie einen fstab Eintrag für die neue Partition:

DATEI /etc/fstabHinzufügen des Mountpoints der ESP
PARTUUID=20f3d6cc-9781-3640-9232-0f5a8c662a60       /boot      vfat    noauto,noatime  1 2
root #mount /boot
Hinweis
Es ist empfehlenswert die GRUB_PLATFORMS Variable in /etc/portage/make.conf zu stellen. Dies hilft GRUB dabei das richtige EFI Ziel zu erkennen. Für 32-Bit UEFI Systeme, stellen sie die Variable auf efi-32. Bei 64-Bit Systemen, nutzen sie efi-64.
Wichtig
Um eine funktionierende GRUB Installation zu erhalten, muss die ESP eingehängt sein und das efivars Kernel Modul muss geladen sein, um grub-install erfolgreich ausführen zu können.

GRUB für EFI installieren

Wichtig
/boot, bzw. die ESP, müssen während der Installation eingehängt sein. Wenn sie für die Partition einen Eintrag in der fstab hinterlegt haben, können sie sie wie folgt einhängen:
root #mount /boot

grub-install kopiert GRUB und alle relevanten benötigten Dateien nach /boot/grub. Dies installiert GRUB nach /boot/grub, kopiert den Bootloader selbst nach /boot/EFI/gentoo/grubx64.efi, und fügt via {{c>efibootmgr}} einen neuen Boot Eintrag hinzu.

root #grub-install --efi-directory=/boot
Installation beendet. Keine Fehler aufgetreten.
Wichtig
Dieser Befehl setzt voraus, dass eine mit FAT formatierte EFI Systempartition (ESP) unter /boot eingehängt ist. Falls eine andere ESP genutzt wird muss dieser Pfad dementsprechend geändert werden.
Hinweis
Standardmäßig passt grub-install die Installation an die Architektur des ausführenden Systems an. Sollte ein anderer Systemtyp genutzt werden, kann die --target Option genutzt werden um den Typ manuell festzulegen.
Hinweis
Die --removable Option kann dazu genutzt werden GRUB nach /boot/EFI/BOOT/BOOTX64.EFI zu installieren, was in manchen Fällen die Kompatibilität verbessert, da dieser Pfad oft standardmäßig gecheckt wird.

BIOS mit MBR

Hinweis
Falls das System zusammen mit einem anderen (vorinstallierten) Betriebssystem, z.B. Microsoft Windows, booten soll, stellen sie sicher, dass GRUB dazu in der Lage ist beide Betriebssysteme zu starten, wenn also z.B. die Windows Installation noch alte MBR Partitionierung verwendet, bedeutet das, dass es im 'legacy BIOS' Modus startet (unter UEFI auch CSM, Compatibility Support Mode, genannt). Wenn sie nun den Modus, z.B. von CSM (BIOS Modus) zu (U)EFI wechseln, wird das vorinstallierte Betriebssystem nicht mehr starten.

Stellen sie sicher, dass /boot erreichbar ist - falls eine separate Partition genutzt wird, so muss diese eingehängt sein.

root #mount /boot

Führen sie grub-install aus um alle relevanten Dateien nach /boot/grub zu kopieren. Auf einem konventionellen PC wird dies auch das Start image in den Master Boot Record (MBR) oder den Bootsektor der Partition installieren. Wenn alles klappt, sollte grub-install dies ausgeben:

root #grub-install /dev/sda
Installation beendet. Keine Fehler aufgetreten.

Es ist möglich über die --target Option zu spezifizieren für welche Architektur und Plattform grub-install den Bootloader installieren soll. Wenn nichts angegeben wird, wird grub-install selbst versuchen die richtige Einstellung herauszufinden; auf einem amd64/x86 System wird es z.B. standardmäßig i386-pc verwenden. Über die Option --boot-directory kann man auch spezifizieren welchen Pfad grub-install für die Konfigurationsdateien verwenden soll. Dies ist standardmäßig auf /boot gestellt.

Partitionierung für BIOS mit MBR

Stellen sie sicher, dass vor der ersten Partition genug Platz für den Master Boot Record (MBR) freigelassen wird. Vor der ersten Partition sollten mindestens 2048 Sektoren (1 MiB) für den Master Boot Record freigelassen sein. Es wird empfohlen in diesem Bereich eine Separate Partition vom Typ BIOS boot partition anzulegen. Diese Partition muss nicht formatiert werden. Diese Partition wird nur dann benötigt, wenn das System später zu einem GPT Partitionsmuster umgestellt werden soll, wenn nur MBR genutzt wird ist sie nicht unbedingt notwendig.

Wenn sie der Gentoo Installationsanleitung gefolgt sind, sollte diese BIOS Bootpartition schon eingerichtet sein.

BIOS mit GPT

Warnung
Auch wenn GPT ein Protective MBR besitzt und somit legacy BIOS Systeme im Hinterkopf behält, wurde es nicht ursprünglich zur vollständigen BIOS Kompatibilität entwickelt. Alte Betriebssysteme welche für MBR Partitionierung ausgelegt sind, der de Facto Standard unter legacy BIOS Computern, müssen zudem ihre Partitionen durch den MBR erreichen können, was durch hybride GPT/MBR Partitionen möglich ist. Diese Methode hat jedoch gewisse Einschränkungen.

Auf einem BIOS System mit GPT Partitionierung installiert sich GRUB in der sogenannten "BIOS boot partition". Diese Partition ist nicht formatiert. grub-install nutzt sie wie den MBR und speichert dort Teile des Bootloaders. Die "BIOS boot partition" ist dabei nicht mit der /boot Partition zu verwechseln.

Hinweis
Siehe auch Was ist die BIOS boot partition? im x86 Handbuch.

Falls eine /boot Partition existiert, hängen sie diese nun ein.

root #mount /boot

Wenn alles klappt und keine Fehler auftreten, sollte der grub-install Befehl nun dies ausgeben:

root #grub-install /dev/sda
Installation beendet. Keine Fehler aufgetreten.

Es ist möglich über die --target Option zu spezifizieren für welche Architektur und Plattform grub-install den Bootloader installieren soll. Wenn nichts angegeben wird, wird grub-install selbst versuchen die richtige Einstellung herauszufinden; auf einem amd64/x86 System im BIOS Modus wird es standardmäßig i386-pc verwenden, und wenn ein GUID Partitionslayout (GPT) existiert, wird grub-install automatisch die "BIOS boot partition" verwenden.

Über die Option --boot-directory kann man auch spezifizieren welchen Pfad grub-install für die Konfigurationsdateien verwenden soll. Dies ist standardmäßig auf /boot gestellt.

Dual-boot mit Windows

Ein Dual-Boot mit Microsoft Windows in BIOS Modus erschwert die Installation unter GPT erheblich, da Windows das GPT Partitionslayout unter BIOS, bzw. CSM, im Gegensatz zu Linux nicht nativ unterstützt. Hier muss für den Dual-boot ein hybrides Partitionslayout angelegt werden; bis zu vier Partitionen können gleichzeitig in GPT und MBR definiert werden.

Hinweis
Klassischerweise nutzten x86-PCs BIOS Firmware. Nachdem PCs um 2005 weitgehend auf (U)EFI umgestellt wurden, gab es für die längste Zeit eine BIOS Emulation namens 'Compatibility Support Mode' (CSM), wodurch PCs auch mit Betriebssystemen kompatibel waren welche noch kein UEFI unterstützen. Seit 2020 wird die Unterstützung für CSM bei vielen neuen Motherboards nicht mehr mitgeliefert und CSM wird langsam abgeschafft. Schon vor 2020 unterstützten manche Implementationen von (U)EFI, z.B. im Serverbereich, kein CSM mehr. Auf modernen UEFI Systemen sollte 'Legacy BIOS Mode' daher nicht mehr verfügbar sein. Da UEFI nur GPT unterstützt wird ein jedes vorinstalliertes Betriebssystem auf diesen Systemen schon mit GPT partitioniert sein.

Für eine schon bestehende Windows-Installation kann der Bootmodus (also UEFI oder BIOS) und das Partitionsschema nicht umgestellt werden, da das System danach nicht mehr starten würde. Ältere Windows Systeme unterstützen außerdem GPT (und/oder EFI) überhaupt nicht. Hier muss das System in BIOS, bzw. CSM mit einem MBR Partitionslayout installiert sein. Sollte die Windows Version EFI-kompatibel sein (alle Versionen ab Windows 7), kann das System im nativen UEFI Modus neu installiert werden. Das selbe gilt für Linux; siehe UEFI mit GPT.

Ein Hybrides Partitionslayout mit GPT und MBR erstellt ein funktionsfähiges GPT- und MBR-Partitionslayout auf der selben Festplatte, allerdings liegt das Limit, wie auch bei klassischem MBR, bei vier Partitionen. Da die ESB (die EFI Systempartition welche die EFI Bootloader beinhaltet) schon eine Partition einnimmt, bleiben nur noch drei zwischen MBR und GPT geteilte Partitionen. Wenn sie z.B. eine Partition für Windows und eine für Linux verwenden, so lässt das nur eine andere Partition frei, z.B. für eine separate /boot Partition, eine zwischen Windows und Linux geteilte Partition oder auch einen Swapspeicher.

Warnung
Im Normalfall erstellt ein GPT Partitionslayout automatisch auch ein MBR Partitionslayout welches genau eine Partition, welche den kompletten Platz ausfüllt, beinhaltet. Dies stellt sicher, dass ältere Software nicht die komplette Festplatte für 'leer' hält. Das MBR mit seiner Partition wird daher auch als 'protective MBR', Schutz-MBR, bezeichnet, und ist Teil eines jeden standard GPT Layouts. Bei nutzung eines hybriden Layouts wird dieser Schutzmechanismus entfallen! Ältere Software wird bei Analyse eines hybriden MBRs keinen benutzten Speicher erkennen und könnte diesen Platz als ungenutzt markieren. Falls das zum Beschreiben der Festplatte außerhalb der definierten MBR Partitionen führt kann dadurch ein Verlust von Daten in den GPT Partitionen entstehen!

Falls sie für ihren Computer zwei oder mehr Festplatten zur Verfügung haben, wird empfohlen eine davon für GPT, und die andere mit MBR zu partitionieren. Windows nutzt im BIOS Modus normalerweise nur eine Partition als System- und Bootpartition, unter der Bezeichnung 'C:' bekannt. Im BIOS Modus muss diese Partition unter MBR definiert sein. Dies gilt für alle Windows Versionen seit Windows XP, inklusive Windows 10. Seit Windows Vista (Tatsächlich auch schon mit Windows XP Professional x64 Edition) unterstützt Windows den Zugriff auf GPT-Partitionen. Wie folgt kann hier nun die 'C:'-Systempartition unter der mit MBR partitionierten Platte gespeichert werden und und die Windows Installation (der gesamte Inhalt des \WINDOWS Ordners) auf eine GPT Partition verschoben werden. Windows kann dann auf die GPT Platte zugreifen, aber die 'C:' Partition wird weiterhin im MBR Layout (oder hybrid) bleiben. Unter Windows 11 wird BIOS/CSM/MBR-Modus nicht mehr unterstützt.

Partitionierung für BIOS mit GPT

Wenn ein GPT-Partitionslayout auf der Festplatte installiert ist, muss eine kleine BIOS boot partition vom Typ EF02 (nicht mit der EFI-Systempartition (ESP) vom Typ EF00 zu verwechseln) verfügbar sein. Eine Größe von 1 MiB sollte normalerweise ausreichen, wer auf Nummer Sicher gehen will kann die Größe aber auch bei 2-4 MiB anlegen. Diese Partition sollte als erste Partition ganz am Anfang der Festplatte liegen und wird die Stage 2 des Bootloaders beinhalten. BIOS boot partitions werden nicht mit einem Dateisystem formatiert und grub-install wird das Dateisystem überschreiben, sollte eins vorliegen.

Wichtig
Die BIOS boot partition ist nicht mit der unter /boot eingehängten Partition, welche bei vielen Systemen besteht, zu verwechseln. /boot und BIOS boot sind zwei verschiedene Partitionen und als solche separat von einander zu sehen. In keinem Fall wird BIOS boot als normales Dateisystem eingehängt (und wird daher auch niemals in /etc/fstab eingetragen). Die /boot Partition kann als normales Dateisystem ohne Probleme eingehängt werden und ist somit auch oft in der /etc/fstab Datei zu finden.

Um eine schon bestehende Partition als BIOS boot partition zu markieren, nutzen sie parted (sys-block/parted) und führen sie diesen Befehl aus (die 1 legt die Partitionsnummer fest):

(parted)set 1 bios_grub on

Mit cgdisk (enthalten in sys-apps/gptfdisk), ändern sie den Partitionstyp zu 0xEF02 und markieren sie die Partition mit dem gptbios Label um das selbe zu erreichen.

Eine EFI-Systempartition wird nicht benötigt, aber es kann sinnvoll sein die BIOS boot partition so zu dimensionieren, sodass sie später zu einer EFI-Systempartition umgestellt werden kann, sollte das System später auf UEFI umgestellt werden.

Das Folgende ist die Ausgabe nach Drücken des p Keys innerhalb von gdisk auf einer GPT-partitionierten Festplatte mit einer BIOS boot [0xEF02] Partition und einer EFI [0xEF00] Partition:

root #gdisk /dev/sdc
GPT fdisk (gdisk) version 0.8.1
 
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present
 
Found valid GPT with protective MBR; using GPT.
 
Command (? for help): p
Disk /dev/sdc: 976773168 sectors, 465.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): AA369F4D-37A4-4C0D-A357-DC24B99A6337
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
 
Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048       828377087   395.0 GiB   8E00  Linux LVM
   2       828377088       891291647   30.0 GiB    0700  Microsoft basic data
   3       891291648       975177727   40.0 GiB    0700  Microsoft basic data
   4       975177728       976754687   770.0 MiB   8300  Linux filesystem
   5       976754688       976756735   1024.0 KiB  EF02  BIOS boot partition
   6       976756736       976773134   8.0 MiB     EF00  EFI System
 
Command (? for help): 
Hinweis
Das hexadezimale 0x-Prefix muss bei Verwendung von fdisk mit GPT nicht verwendet werden.

Die Ausgabe von parted ist leicht anders formatiert (es wird der selbe PC und das gleiche Partitionsschema verwendet):

root #parted /dev/sdc
GNU Parted 3.0
Using /dev/sdc
(parted) print
...
Sector size (logical/physical): 512B/512B
Partition Table: gpt
  
Number  Start   End    Size    File system  Name                  Flags
 1      1049kB  424GB  424GB                Linux LVM             lvm
 2      424GB   456GB  32.2GB               Microsoft basic data
 3      456GB   499GB  42.9GB               Microsoft basic data
 4      499GB   500GB  807MB   ext2         Linux filesystem
 5      500GB   500GB  1049kB               BIOS boot partition   bios_grub
 6      500GB   500GB  8396kB               EFI System            boot
  
(parted)

Das Partitionieren in gdisk ist unkompliziert und von der Bedienung her ähnlich fdisk. Innerhalb von gdisk, drücken sie zuerst n (neu) im Hauptmenü, geben sie die Anfangs- und Endsektoren an (falls benötigt), und setzen sie den Partitionstyp auf EF00 um eine EFI Systempartition zu erhalten.

Falls sie der Gentoo Installationsanleitung gefolgt sind, werden sie schon das richtige Partitionslayout nutzen.

Open Firmware (IEEE 1275) auf PowerPC

Siehe GRUB auf Open Firmware (PowerPC) Systemen.

Installation auf einer verschlüsselten Partition

Bei vollständiger Verschlüsselung der Festplatte, inklusive /boot, muss weitere Konfiguration durchgeführt werden um es GRUB zu ermöglichen, auf das verschlüsselte /boot zuzugreifen.

Die device-mapper USE flag muss beim Installieren des GRUB Paketes eingestellt sein. Zudem muss das Packet sys-fs/cryptsetup installiert sein. Die Partition muss mit luks1 verschlüsselt sein (luks2 wird gegenwärtig nur sehr eingeschränkt von GRUB unterstützt).

Es kann sein, je nachdem wie der Kernel eingerichtet ist, dass nach der Installation von GRUB als Bootloader die Initramfs modifiziert werden muss, damit das System vollständig booten kann. Falls ein Distributionskernel genutzt wird ist Dracut auf ihrem System schon vorinstalliert und kann zur Anpassung der Konfiguration genutzt werden.

Konfiguration

Nachdem GRUB nun installiert ist, kann es nach Belieben konfiguriert und auf das System individuell zugeschnitten werden. Meistens wird allerdings keine weitere Konfiguration benötigt.

Konfigurationsdatei

Der grub-mkconfig Befehl wird genutzt um eine valide GRUB Konfiguration zu generieren. Hierzu werden die Skripts unter /etc/grub.d/* zusammen mit der Konfigurationsdatei unter /etc/default/grub verwendet, um die finale /boot/grub/grub.cfg Konfigurationsdatei zu erstellen; welche als einzige der genannten Dateien von GRUB während dem Boot verwendet wird.

Datei Format Bearbeiten empfohlen? Beschreibung
/usr/sbin/grub-mkconfig POSIX shell skript Nein Installiert als Teil des sys-boot/grub:2 Pakets. Nutzen sie dieses Skript, um /boot/grub/grub.cfg zu erstellen, nachdem sie die unten gelisteten Dateien konfiguriert haben.
/boot/grub/grub.cfg GRUB shell skript Nein Die von grub-mkconfig generierte Datei. Diese Datei benutzt GRUBS eigenen Interpreter, welcher nicht unbedingt POSIX kompatible Syntax unterstützt. Siehe auch die offizielle Skripting Anleitung im GRUB Handbuch für alle unterstützten Features. Diese Datei (und alle manuellen Anpassungen) wird bei Ausführung von grub-mkconfig überschrieben.
/etc/grub.d/* POSIX shell skripts Vielleicht Jedes als aktiviert markierte Skript in /etc/grub.d/* wird der Reihenfolge nach evaluiert, und das stdout wird kombinier und ergibt die finale /boot/grub/grub.cfg (oder auch ein beliebiger Dateipfad welcher mit der grub-mkconfig -o Option spezifiziert wurde). Diese Skripte verwenden die auf dem system aktivierte normale Shell, und können dafür jede unterstütze Syntax nutzen. Optimalerweise sollten die Skripts POSIX-kompatible Syntax nutzen und das Output sollte mit dem GRUB Interpreter kompatibel sein. Skripts können deaktiviert oder auch neu hinzugefügt werden. Dies könnte bei benutzerdefinierten Menüeinträgen nützlich sein, welche nicht automatisch generiert werden können.
/boot/grub/custom.cfg GRUB shell skript Vielleicht Das /etc/grub.d/41_custom Skript spezifiziert, dass diese Datei beim Boot gelesen werden soll, vorausgesetzt es existiert. Hier können zusätzliche Befehle oder Einträge hinzugefügt werden, ohne das eine Neukonfiguration von /boot/grub/grub.cfg benötigt wird.
/etc/default/grub POSIX shell script Ja In den allermeisten Fällen sollte diese Datei als einzige modifiziert werden. Hier werden Variablen definiert, welche von den Skrips in /etc/grub.d/* verwendet werden um eine funktionierende Konfiguration zu generieren. Siehe auch GRUB Konfigurationsvariablen oder das offizielle Handbuch.

Die Bootkonfiguration muss mit GRUB2 (im Gegensatz zu klassischen Bootloadern wie GRUB Legacy oder LILO) nicht manuell vom Administrator gewartet werden. Die Konfigurationsdatei unter /boot/grub/grub.cfg kann über den grub-mkconfig Befehl automatisch generiert werden. grub-mkconfig nutzt die Skripts in /etc/grub.d/ und die Einstellungen in /etc/default/grub.

Warnung
grub-mkconfig kann nicht in Kombination mit einem Software RAID verwendet werden. Hier ist es nötig die Skripts in /etc/grub.d/ manuell anzupassen, da ansonsten das System nicht bootbar sein wird.

Nach der Konfiguration, führen sie grub-mkconfig aus, verwenden sie die -o Option und geben sie den Pfad an unter dem die Ausgabe gespeichert werden soll (in aller Regel /boot/grub/grub.cfg; dies ist auch die Standardeinstellung).

root #grub-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.3.0-gentoo
done

Bei jedem Ausführen von grub-mkconfig wird eine komplett neue Konfiguration erstellt und die alte Datei überschrieben.

Warnung
Falls grub-mkconfig keine möglichen Booteinträge findet, wird das Bootmenü nach einem Neustart leer sein. Um derartige Probleme, welche recht zeitaufwendig zu lösen sein können, zu vermeiden, stellen sie immer sicher, dass grub-mkconfig alle Einträge ordnungsgemäß erkennt.

Konfigurationsparameter

The following variables in /etc/default/grub are the most common ones to set to control how GRUB will function:

Variable Explanation Default value
GRUB_DEFAULT Defines the default menu entry selected on boot. May be a numeric index, a menu title, or "saved". Defaults to first detected entry.
GRUB_TIMEOUT Delay (in seconds) before booting default menu entry. Set to 0 to boot immediately or -1 to wait indefinitely. The default is 5 seconds.
GRUB_CMDLINE_LINUX Parameters to be passed on the kernel command line for all Linux menu entries. For instance, to support hibernation, users will need to add GRUB_CMDLINE_LINUX="resume=/dev/sdXY" with /dev/sdXY being the swap partition.
GRUB_CMDLINE_LINUX_DEFAULT Parameters to be passed on the kernel command line for non-recovery Linux menu entries.
GRUB_DEVICE The initial root device (i.e. the kernel's root= parameter). Set this to override the grub-mkconfig command's root device auto-detection. For example, GRUB_DEVICE=/dev/ram0 will force root=/dev/ram0 to be used in the kernel command line.

For a more complete list, please refer to the configuration variables sub-page and as the info page of grub-mkconfig.

After modifying the parameters, regenerate the GRUB configuration file with grub-mkconfig.

Ein- und Ausschalten von Konfigurations-Skripts

The directory /etc/grub.d/ contains the scripts that grub-mkconfig uses to generate a grub.cfg file. By default the contents of this directory should be similar to the following:

user $ls /etc/grub.d/
00_header  10_linux  20_linux_xen  30_os-prober  40_custom  41_custom README

GRUB will use all installed scripts that are marked as executable (which by default, they all are). To disable any of the scripts simply remove the executable bit from the script's file permissions using the chmod command. In the following example every script but 00_header and 10_linux are disabled:

root #chmod -x /etc/grub.d/{20_linux_xen,30_os-prober,40_custom,41_custom}

After modifying the scripts (or removing the executable bit), regenerate the configuration file using grub-mkconfig.

Bearbeitung von Konfigurations-Skripts

Some features or functionalities are only possible to be exploited by modifying the configuration scripts. For instance, to support dual-booting with FreeBSD, the following manipulation needs to be done.

Change the /etc/grub.d/40_custom script to:

DATEI /etc/grub.d/40_customAdding an entry for dual booting
menuentry "FreeBSD" --class freebsd --class bsd --class os {
 insmod ufs2
 insmod bsd
 set root=(hd0,1)
 kfreebsd /boot/kernel/kernel
 kfreebsd_loadenv /boot/device.hints
 set kFreeBSD.vfs.root.mountfrom=ufs:/dev/ada0s1a
 set kFreeBSD.vfs.root.mountfrom.options=rw
 set kFreeBSD.hw.psm.synaptics_support=1
}

/dev/sda1 or (hd0,1) is the partition in which FreeBSD resides. If the normal UFS install was used for the FreeBSD partition then /dev/sda1 is a container (something like a logical partition). It consists of the swap and root partition. Verify the 40_custom script is executable by running ls -la /etc/grub.d/40_custom. If the executable bit is not set then set it using the chmod u+x 40_custom command.

Hinweis
Users familiar with how GRUB Legacy numbered partitions should note partitions starting from 1, not 0, with GRUB.

Next install GRUB and update the configuration file:

root #grub-install /dev/sda
root #grub-mkconfig -o /boot/grub/grub.cfg

Erweiterte Funktionen

GRUB 2 has many features that make it a very powerful boot loader. It supports:

  • Booting from UEFI platforms.
  • Booting from GPT partitioned drives without needing a hybrid MBR (hybrid MBR can enabled as needed for compatibility or portability).
  • Booting from a btrfs formatted /boot partition.
  • Booting from a ZFS pool.
  • Booting directly from a btrfs RAID set without needing an initramfs for early mount setup.
  • Booting directly from logical volume management (such as LVM2).
  • Booting with support for DM-RAID (RAID 0, 1, 4, 5, 6, 9 and 10).
  • Booting from encrypted devices (LUKS).

Some specific features are explained in more detail next.

Chainloading

GRUB 2 was built with a truly improved chainload mode when compared to GRUB Legacy. To chainload another boot loader, use the chainloader option.

DATEI /etc/grub.d/40_customChainloading another bootloader
menuentry "Custom Super-bootloader example" {
     insmod part_msdos
     insmod chain
     chainloader (hd1,1)+1
}

For more information on chainloading, please see the Chainloading sub-page.

Passwortgeschütztes GRUB-Menü

To secure GRUB so it is not possible for anyone to change boot parameters or use the command line, add a user/password combination to GRUB's configuration files. The program grub-mkpasswd-pbkdf2 generates password hashes for GRUBː

user $grub-mkpasswd-pbkdf2
Password:
Reenter password:
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.9CA4611006FE96BC77A...

Then, add the following toː

DATEI /etc/grub.d/35_auth:
# Grub user
echo 'set superusers="<username>"'
# Grub password
echo 'password_pbkdf2 <username> <password-hash>'

The above may lock all Grub menu entries, even the default entry. In that case, to allow users to boot some menu entries without a password, see Securing the grub boot loader.

The permissions for the file need to be properly set before doing grub-mkconfig:

root #chmod 755 /etc/grub.d/35_auth

Benutzung des Framebuffer-Output

To have GRUB use a framebuffer graphical display, re-emerge GRUB with the truetype USE flag enabled. This will install a default True Type font as well as a font conversion utility.

root #emerge --ask --newuse sys-boot/grub:2

Proceed to configure the default configuration file located at /etc/default/grub. For example:

DATEI /etc/default/grubFramebuffer related settings
# Set resolution and color depth
GRUB_GFXMODE=1366x768x32
 
# Keep resolution when loading the kernel
GRUB_GFXPAYLOAD_LINUX=keep
  
# Set a background image
GRUB_BACKGROUND="/boot/grub/bg.png"
 
# Use a custom font, converted using grub-mkfont utility
GRUB_FONT="/boot/grub/fonts/roboto.pf2"
 
# Set the menu colors 
GRUB_COLOR_NORMAL="light-blue/black"
GRUB_COLOR_HIGHLIGHT="light-cyan/blue"

HiDPI Displays

On modern displays with high DPI ("HiDPI"), e.g. UHD (3840x2160), the standard font will look very small. If you like to have the same font as the kernel, Terminus can be used, which resembles a BIOS built-in textmode font.

To select this font in-kernel, CONFIG_FONT_TER16x32 has to be enabled.

KERNEL Kernel compiled-in fonts
Library routines  --->
      [*] Select compiled-in fonts
      [*] Terminus 16x32 font (not supported by all drivers)

The same font is available as media-fonts/terminus-font, which can then be used for GRUB as well.

root #emerge --ask media-fonts/terminus-font
root #grub-mkfont -s 32 -o /boot/grub/fonts/terminus32b.pf2 /usr/share/fonts/terminus/ter-u32b.otb

In the above example the filename chosen for grub-mkfont output is terminus32b.pf2. The font's path has to be accessible to GRUB during boot, so it should reside in the same mount point as GRUB does; this example uses /boot/grub/fonts. The font then has to be set as GRUB_FONT in /etc/default/grub in order to be used.

DATEI /etc/default/grubFramebuffer related settings
# Use a custom font, converted using grub-mkfont utility
GRUB_FONT="/boot/grub/fonts/terminus32b.pf2"

Updating the GRUB configuration file grub.cfg will then activate the configuration with the new font.

root #grub-mkconfig -o /boot/grub/grub.cfg

Fehlerbehebung

Hinweis
For more troubleshooting, please refer to the Troubleshooting sub-article.

Most of the issues can be resolved by ensuring that the partition layout is correct. Make sure enough space is available before the first partition of the disk, or optionally make sure that a BIOS boot partition is available. Also verify that /boot/grub/grub.cfg was correctly generated with grub-mkconfig, or generate one with a custom menu entry.

os-prober funktioniert nicht

When running the grub-mkconfig command, os-prober is not running as expected, even though it is installed:

root #grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.11.14-gentoo-x86_64
Found initrd image: /boot/amd-uc.img /boot/initramfs-5.11.14-gentoo-x86_64.img
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done

This can be corrected by setting the GRUB_DISABLE_OS_PROBER variable to false in /etc/default/grub file.

DATEI /etc/default/grub
GRUB_DISABLE_OS_PROBER=false

Upon the next run, grub-mkconfig should find additional bootable partitions:

root #grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.11.14-gentoo-x86_64
Found initrd image: /boot/amd-uc.img /boot/initramfs-5.11.14-gentoo-x86_64.img
Warning: os-prober will be executed to detect other bootable partitions.
It's output will be used to detect bootable binaries on them and create new boot entries.
Found Windows Boot Manager on /dev/nvme0n1p2@/efi/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for UEFI Firmware Settings ...
done

Die Firmware des Motherboards findet die .EFI Datei nicht

Some especially older (pre-2020) motherboards from certain manufacturers seem to only support one location for the .EFI file in the EFI System Partition (ESP): the fallback or removable media path. If this seems to be the case, simply move GRUB's default file to the /efi/boot/ location. First, make sure the ESP is mounted. Presuming the ESP is mounted at /boot/efi (as suggested in the Handbook), execute:

root #mkdir -p /boot/efi/efi/boot
root #cp /boot/efi/efi/gentoo/grubx64.efi /boot/efi/efi/boot/bootx64.efi

On a 32-bit EFI implementation use bootia32.efi instead:

root #cp /boot/efi/efi/gentoo/grubia32.efi /boot/efi/efi/boot/bootia32.efi

The removable parameter can be used with grub-install command to generate this file automatically:

root #grub-install --efi-directory=/boot/efi --removable
Installation finished. No error reported.

This should aid the motherboard firmware in loading the GRUB executable. Reboot the system to see if the firmware now correctly loads GRUB.

os-prober und UEFI im chroot

The sys-boot/os-prober utility is used to discover alternate installs, such as Microsoft Windows. To function properly, it needs to have access to information from the live environment's udev to test for the EFI System Partition.

Run these commands in the host environment to provide the required files (example shows Gentoo mounted on /mnt/gentoo like in the Handbook):

root #mkdir -p /mnt/gentoo/run/udev
root #mount -o bind /run/udev /mnt/gentoo/run/udev
root #mount --make-rslave /mnt/gentoo/run/udev

Installation eines neuen Kernels

Whenever a new kernel is installed, GRUB must be reconfigured to recognize it. This can be done using grub-mkconfig, as shown below, or can be done manually.

Hinweis
Make sure the /boot partition is mounted for this step.
root #grub-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/kernel-3.3.8-gentoo
Found initrd image: /boot/initramfs-genkernel-x86_64-3.3.8-gentoo
Found linux image: /boot/kernel-3.2.12-gentoo
Found initrd image: /boot/initramfs-genkernel-x86_64-3.2.12-gentoo
done

Note that GRUB only needs to be reconfigured, not reinstalled to the boot drive's Master Boot Record (MBR). On the other hand, when GRUB itself has been upgraded it does need to be reinstalled on the boot drive, but usually does not need to be reconfigured.

Automatische Neukonfigurierung

If the package sys-kernel/installkernel-gentoo is installed and the USE flag grub is set, then on every installation of a kernel, grub-mkconfig will run automatically.

Siehe auch

  • In Chainloading the use of GRUB to boot other boot loaders is described. This is important to read when dual-booting systems, or when GRUB needs to be configured to boot ISO files.
  • In Advanced storage the necessary steps are documented on how to install and use GRUB on more advanced storage situations, such as software RAID, logical volumes or encrypted file systems.
  • In Configuration variables an exhaustive list of GRUB configuration variables, as used by /etc/default/grub, is documented.
  • In Troubleshooting a list of common GRUB errors (with their solutions) is presented.
  • In Hybrid partition table the use of a mixed MBR/GPT setup is documented, as well as how to use such hybrid partition layout with GRUB.

Externe Ressourcen

For more information, please see:

Einzelnachweise