Handbook:X86/Installation/Bootloader
Wybór programu rozruchowego
Z skonfigurowanym jadrem Linuksa, zainstalowanymi narzędziami systemowymi i z zmodyfikowanymi plikami konfiguracyjnymi, przyszedł czas na instalację ostatniej ważnej części systemu Linux: systemu rozruchowego.
System rozruchowy jest odpowiedzialny za uruchomienie jądra systemu Linux podczas startu komputera - bez niego, komputer nie wiedziałby co należy zrobić po wciśnięciu przycisku zasilania.
Dla x86, udokumentowaliśmy jak skonfigurować zarówno GRUB2 jak i LILO dla systemów opartych o BIOS, oraz GRUB2 i efibootmgr dla systemów UEFI.
W tej sekcji Podręcznika dokonano podziału pomiędzy "emerge" systemu rozruchowego, a "instalacją" systemu rozruchowego na dysk systemowy. Pojęcie "emerge" będzie używane do zapytania Portage o utworzenie pakietu oprogramowania dostępnego dla systemu. Pojęcie "instalacja" będzie oznaczało kopiowanie plików systemu rozruchowego lub fizyczną modyfikację stosownych sekcji dysku systemowego, w celu "uaktywnienia i przygotowania do działania" systemu rozruchowego na następne uruchomienie systemu operacyjnego.
Domyślnie: GRUB2
Domyślnie, większość systemów Gentoo korzysta teraz z GRUB2 (znajdującego się w pakiecie sys-boot/grub), który jest sukcesorem przestarzałego GRUB. Bez dodatkowej konfiguracji, GRUB2 wspiera starsze wersje BIOS. Z drobną konfiguracją, niezbędną przed kompilacją pakietu, GRUB2 może wspierać więcej niż tuzin dodatkowych platform sprzętowych. Więcej informacji znajdziesz w sekcji Wymagania wstępne artykułu GRUB2.
Emerge
Podczas korzystania z starszego BIOS, system wspiera jedynie tablicę partycji MBR. Nie ma potrzeby dodatkowej konfiguracji w celu zainstalowania systemu rozruchowego GRUB:
root #
emerge --ask --verbose sys-boot/grub:2
Informacja dla użytkowników UEFI: uruchomienie powyższej komendy wyświetli aktualną zawartość GRUB_PLATFORMS przed przystąpieniem do kompilacji. Użytkownicy systemów UEFI muszą zapewnić włączenie opcji GRUB_PLATFORMS="efi-64"
(jak ma to miejsce domyślnie). Jeżeli opcja nie jest włączona, GRUB_PLATFORMS="efi-64"
musi zostać dodane do pliku /etc/portage/make.conf przed przystąpieniem do kompilacji GRUB2, tak aby pakiet był skompilowany z funkcjonalnością EFI:
root #
echo 'GRUB_PLATFORMS="efi-64"' >> /etc/portage/make.conf
root #
emerge --ask sys-boot/grub:2
- Jeżeli GRUB2 został jakkolwiek skompilowany bez włączenia
GRUB_PLATFORMS="efi-64"
, linia ta (jak wyżej wskazano) nadal może zostać dodana do pliku make.conf, a zależności zbioru pakietów world ponownie obliczone poprzez użycie opcji--update --newuse
dla polecenia emerge:
root #
emerge --ask --update --newuse --verbose sys-boot/grub:2
Oprogramowanie GRUB2 zostało właśnie przyłączone do systemu, ale nie zostało jeszcze zainstalowane.
Instalacja
Następnie, zainstaluj niezbędne pliki GRUB2 do ścieżki /boot/grub/ poprzez komendę grub-install. Zakładając, że pierwszy dysk (ten z którego system się uruchamia) to /dev/sda, uruchom jedno z poniższych poleceń:
- Podczas korzystania z BIOS:
root #
grub-install /dev/sda
Podczas korzystania z UEFI:
- Ważne
Upewnij się, że partycja systemowa EFI została zamontowana przed uruchomieniem grub-install. Istnieje ryzyko, że grub-install zainstaluje plik GRUB EFI (grubx64.efi) w złej ścieżce bez podania jakiegokolwiek wskazania, że użyto złej ścieżki
root #
grub-install --target=x86_64-efi --efi-directory=/boot
- Informacja
Zmień parametr opcji--efi-directory
na partycję systemową EFI. Jest to niezbędne jeżeli partycja /boot nie została sformatowana jako FAT.
- Ważne
Jeśli grub-install zwraca błąd podobny doCould not prepare Boot variable: Read-only file system
, może być konieczne ponowne zamontowanie efivars w trybie do odczytu i zapisu, aby odnieść sukces:root #
mount -o remount,rw /sys/firmware/efi/efivars
Some motherboard manufacturers seem to only support the /efi/boot/ directory location for the .EFI file in the EFI System Partition (ESP). The GRUB installer can perform this operation automatically with the --removable
option. Verify the ESP is mounted before running the following commands. Presuming the ESP is mounted at /boot (as suggested earlier), execute:
root #
grub-install --target=x86_64-efi --efi-directory=/boot --removable
This creates the default directory defined by the UEFI specification, and then copies the grubx64.efi file to the 'default' EFI file location defined by the same specification.
Konfiguracja
Next, generate the GRUB configuration based on the user configuration specified in the /etc/default/grub file and /etc/grub.d scripts. In most cases, no configuration is needed by users as GRUB will automatically detect which kernel to boot (the highest one available in /boot/) and what the root file system is. It is also possible to append kernel parameters in /etc/default/grub using the GRUB_CMDLINE_LINUX variable.
Aby wygenerować końcową konfigurację GRUB2, uruchom polecenie grub-mkconfig:
root #
grub-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ... Found linux image: /boot/vmlinuz-5.15.52-gentoo Found initrd image: /boot/initramfs-genkernel-x86-5.15.52-gentoo done
The output of the command must mention that at least one Linux image is found, as those are needed to boot the system. If an initramfs is used or genkernel was used to build the kernel, the correct initrd image should be detected as well. If this is not the case, go to /boot/ and check the contents using the ls command. If the files are indeed missing, go back to the kernel configuration and installation instructions.
The os-prober utility can be used in conjunction with GRUB to detect other operating systems from attached drives. Windows 7, 8.1, 10, and other distributions of Linux are detectable. Those desiring dual boot systems should emerge the sys-boot/os-prober package then re-run the grub-mkconfig command (as seen above). If detection problems are encountered be sure to read the GRUB article in its entirety before asking the Gentoo community for support.
Alternatywa 1: LILO
Emerge
LILO, the LInuxLOader, is the tried and true workhorse of Linux boot loaders. However, it lacks features when compared to GRUB. LILO is still used because, on some systems, GRUB does not work and LILO does. Of course, it is also used because some people know LILO and want to stick with it. Either way, Gentoo supports both bootloaders.
Instalacja LILO to pestka; wystarczy użyć emerge.
root #
emerge --ask sys-boot/lilo
Konfiguracja
Aby skonfigurować LILO, najpierw utwórz plik /etc/lilo.conf:
root #
nano -w /etc/lilo.conf
In the configuration file, sections are used to refer to the bootable kernel. Make sure that the kernel files (with kernel version) and initramfs files are known, as they need to be referred to in this configuration file.
If the root filesystem is JFS, add an
append="ro"
line after each boot item since JFS needs to replay its log before it allows read-write mounting./etc/lilo.conf
Example LILO configurationboot=/dev/sda # Install LILO in the MBR
prompt # Give the user the chance to select another section
timeout=50 # Wait 5 (five) seconds before booting the default section
default=gentoo # When the timeout has passed, boot the "gentoo" section
compact # This drastically reduces load time and keeps the map file smaller; may fail on some systems
image=/boot/vmlinuz-5.15.52-gentoo
label=gentoo # Name we give to this section
read-only # Start with a read-only root. Do not alter!
root=/dev/sda4 # Location of the root filesystem
image=/boot/vmlinuz-5.15.52-gentoo
label=gentoo.rescue # Name we give to this section
read-only # Start with a read-only root. Do not alter!
root=/dev/sda4 # Location of the root filesystem
append="init=/bin/bb" # Launch the Gentoo static rescue shell
# The next two lines are for dual booting with a Windows system.
# In this example, Windows is hosted on /dev/sda6.
other=/dev/sda6
label=windows
Jeśli używany jest inny schemat partycjonowania i/lub obraz jądra, dostosuj go odpowiednio.
Jeśli initramfs jest konieczny, zmień konfigurację, odwołując się do tego pliku initramfs i informując initramfs, gdzie znajduje się urządzenie root:
/etc/lilo.conf
Dodawanie informacji o initramfs do wpisu rozruchowego'"`UNIQ--pre-00000004-QINU`"'
If additional options need to be passed to the kernel, use an append
statement. For instance, to add the video
statement to enable framebuffer:
/etc/lilo.conf
Adding video parameter to the boot optionsimage=/boot/vmlinuz-5.15.52-gentoo
label=gentoo
read-only
root=/dev/sda4
append="video=uvesafb:mtrr,ywrap,1024x768-32@85"
Users that used genkernel should know that their kernels use the same boot options as is used for the installation CD. For instance, if SCSI device support needs to be enabled, add doscsi
as kernel option.
Teraz zapisz plik i wyjdź.
Instalacja
To finish up, run the /sbin/lilo executable so LILO can apply the /etc/lilo.conf settings to the system (i.e. install itself on the disk). Keep in mind that /sbin/lilo must be executed each time a new kernel is installed or a change has been made to the lilo.conf file in order for the system to boot if the filename of the kernel has changed.
root #
/sbin/lilo
Alternative 2: efibootmgr
On UEFI based systems, the UEFI firmware on the system (in other words the primary bootloader), can be directly manipulated to look for UEFI boot entries. Such systems do not need to have additional (also known as secondary) bootloaders like GRUB in order to help boot the system. With that being said, the reason EFI-based bootloaders such as GRUB exist is to extend the functionality of UEFI systems during the boot process. Using efibootmgr is really for those who desire to take a minimalist (although more rigid) approach to booting their system; using GRUB (see above) is easier for the majority of users because it offers a flexible approach when booting UEFI systems.
Remember sys-boot/efibootmgr application is not a bootloader; it is a tool to interact with the UEFI firmware and update its settings, so that the Linux kernel that was previously installed can be booted with additional options (if necessary), or to allow multiple boot entries. This interaction is done through the EFI variables (hence the need for kernel support of EFI vars).
Be sure to read through the EFI stub kernel article before continuing. The kernel must have specific options enabled to be directly bootable by the system's UEFI firmware. It might be necessary to recompile the kernel. It is also a good idea to take a look at the efibootmgr article.
To reiterate, efibootmgr is not a requirement to boot an UEFI system. The Linux kernel itself can be booted immediately, and additional kernel command-line options can be built-in to the Linux kernel (there is a kernel configuration option called CONFIG_CMDLINE that allows the user to specify boot parameters as command-line options. Even an initramfs can be 'built-in' to the kernel.
Those that have decided to take this approach must install the software:
root #
emerge --ask sys-boot/efibootmgr
Then, create the /boot/efi/boot/ location, and then copy the kernel into this location, calling it bootx64.efi:
root #
mkdir -p /boot/efi/boot
root #
cp /boot/vmlinuz-* /boot/efi/boot/bootx64.efi
Next, tell the UEFI firmware that a boot entry called "Gentoo" is to be created, which has the freshly compiled EFI stub kernel:
root #
efibootmgr --create --disk /dev/sda --part 2 --label "Gentoo" --loader "\efi\boot\bootx64.efi"
Jeśli używany jest inicjalny system plików RAM (initramfs), dodaj do niego odpowiednią opcję rozruchu:
root #
efibootmgr -c -d /dev/sda -p 2 -L "Gentoo" -l "\efi\boot\bootx64.efi" initrd='\initramfs-genkernel-x86-5.15.52-gentoo'
The use of \ as directory separator is mandatory when using UEFI definitions.
With these changes done, when the system reboots, a boot entry called "Gentoo" will be available.
Alternative 3: Syslinux
Syslinux is yet another bootloader alternative for the x86 architecture. It supports MBR and, as of version 6.00, it supports EFI boot. PXE (network) boot and lesser-known options are also supported. Although Syslinux is a popular bootloader for many it is unsupported by the Handbook. Readers can find information on emerging and then installing this bootloader in the Syslinux article.
Ponowne uruchomienie systemu
Wyjdź z środowiska chroot i odmontuj wszystkie zamontowane partycje. Następnie wpisz magiczne polecenie, które inicjuje ostateczny, prawdziwy test: reboot.
root #
exit
cdimage ~#
cd
cdimage ~#
umount -l /mnt/gentoo/dev{/shm,/pts,}
cdimage ~#
umount -R /mnt/gentoo
cdimage ~#
reboot
Nie zapomnij usunąć medium instalacyjnego, w przeciwnym razie zamiast nowego systemu Gentoo może zostać ponownie uruchomione medium instalacyjne.
Po uruchomieniu świeżo zainstalowanego środowiska Gentoo, kontynuuj Finalizowanie instalacji Gentoo.