This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.
Please visit our production wiki at https://wiki.gentoo.org
Přechod na GRUB2
The goal of this guide is to provide readers with a smooth migration from GRUB Legacy to GRUB2.
Na pozadí
What's GRUB?
GRUB is one of the most commonly found boot loaders in use on non-embedded Linux machines. The role of GRUB is to facilitate the Linux kernel being loaded from the disk into memory and start executing the Linux kernel.
Why migrate?
Za prvé GRUB Legacy již není udržován a jako takový proto ani není nadále aktualizován. GRUB Legacy byl vytvořen v době, kdy měli vývojáři za to, že lze bezpečně učinit určité předpoklady, které se dnes již nezakládají na pravdě. Například, GRUB Legacy neumožňuje bootovat z disků větších než 2TB a rovněž předpokládá, že se neobjeví nové souborové systémy jako náhrada za /boot.
GRUB2 má za cíl poskytnout větší robustnost, přenositelnost, více možností a rovněž je udržován s čistějším kódem. GRUB2 podporuje více hardwarových konfigurací, více souborových systémů a způsobů uspořádání zařízení, než jeho předchůdce.
Přechod na GRUB2
Migration to GRUB2 is fairly straightforward: it will be pulled in as part of the regular upgrade process by the package manager. If it is not pulled in automatically, it can always be merged via the sys-boot/grub:2
package atom:
root #
emerge --ask sys-boot/grub:2
Boot drive
The first important part is to understand which drive is bootable. For those who followed the Gentoo Handbook it should be /dev/sda. For those who are uncertain, the easiest way to find out is to look at the existing GRUB Legacy configuration. Viewing the /boot/grub/grub.conf file is the main place to check.
Be sure the /boot partition is mounted to be able to view these files. It should be as simple as
root #
mount /boot
The grub.conf file will look something like this:
/boot/grub/grub.conf
default 0 timeout 30 splashimage=(hd0,0)/boot/grub/splash.xpm.gz title Gentoo Linux 3.2.12 root (hd0,0) kernel /boot/kernel-3.2.12-gentoo root=/dev/sda3 quiet dolvm initrd /boot/initramfs-genkernel-x86_64-3.2.12-gentoo
Based on the above file it is possible to know that (hd0)
is the boot drive but we must map this to a real device. To know this, look at the /boot/grub/device.map file. An example one is provided below.
/boot/grub/device.map
(fd0) /dev/fd0 (hd0) /dev/sda (hd1) /dev/sdb
When suspecting that /boot/grub/device.map is not accurate, run the following command to recreate the file:
root #
grub-install --recheck /dev/sda
Na základě výše uvedeného souboru tak víme, že /dev/sda je bootovacím zařízením.
Installing and configuring GRUB2
The next step is to install and configure GRUB2 for the /boot partition without removing GRUB Legacy from the drive's Master Boot Record (MBR). The example below uses /dev/sda — replace it with the correct boot drive path.
First install the necessary GRUB2 files to /boot/grub.
root #
grub-install --grub-setup=/bin/true /dev/sda
Installation finished. No error reported.
The
--grub-setup=/bin/true
option tells grub-install to not install GRUB2 in the MBR. If this option is omitted, GRUB Legacy will be overwritten and chainloading GRUB2 from GRUB Legacy later on will not be possible.If GRUB2 was emerged with the
multislot
USE flag, the grub-install command will still refer to GRUB Legacy. In this case, use grub2-install instead — and use grub2-mkconfig in place of grub-mkconfig in the next step.Now we can scan the available kernels and generate a suitable config file to /boot/grub/grub.cfg. Skip this step when using a Manual Configuration.
root #
grub-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ... Found linux image: /boot/kernel-3.2.12-gentoo Found initrd image: /boot/initramfs-genkernel-x86_64-3.2.12-gentoo done
GRUB2 uses the configuration file /boot/grub/grub.cfg whereas GRUB Legacy used /boot/grub/grub.conf so please make sure not to use the old file by mistake, e.g. by using tab-completion if the old file is still there.
grub-mkconfig has strict naming requirements for kernels and initramfs images. A kernel must be named
kernel-${version}
or vmlinuz-${version}
while an initramfs must be named initramfs-${version}.img
, initramfs-genkernel-${version}
, initramfs-genkernel-${arch}-${version}
, initrd-${version}.img
, initrd.img-${version}
, initrd-${version}.gz
, or initrd-${version}
. These files must be available in /boot.The file /etc/default/grub controls the operation of grub-mkconfig. If parameters need to be passed on to the kernel (for instance when using genkernel and booting from LVM or software RAID), edit that file before generating /boot/grub/grub.cfg like so:
root #
nano /etc/default/grub
GRUB_CMDLINE_LINUX
to specify parameters to be passed on the kernel command line.Zkouška nastavení spuštěním GRUB2 skrze GRUB Legacy
Protože špatná konfigurace GRUB může vést k tomu, že systém se stane nespustitelným, chceme nastavení GRUB2 otestovat, než jej učiníme trvalým. Proto spustíme GRUB2 přes GRUB Legacy. To uděláme tak, že přidáme novou položku do /boot/grub/grub.conf. Viz příklad níže.
Be aware that the root partition may be different from
(hd0,0)
used in the example, and make sure to reuse the same root value from the /boot/grub/grub.conf configuration file./boot/grub/grub.conf
default 0 timeout 30 splashimage=(hd0,0)/boot/grub/splash.xpm.gz title GRUB2 Chainload root (hd0,0) kernel /boot/grub/i386-pc/core.img boot title Gentoo Linux 3.2.12 root (hd0,0) kernel /boot/kernel-3.2.12-gentoo root=/dev/sda3 quiet dolvm initrd /boot/initramfs-genkernel-x86_64-3.2.12-gentoo
At this point the machine should be rebooted, and GRUB2 Chainload
selected from the GRUB menu when the machine begins to boot. Another GRUB menu will be presented which should advertise itself as GRUB 2.0.0 or higher at the top and show the available kernel(s) to boot. Should this not work, simply reboot the system and pick the normal boot option instead of GRUB2 Chainload
.
Výměna a odstranění GRUB Legacy
If everything worked successfully, replace GRUB Legacy and remove it from the system.
Since the system has been rebooted, it might be necessary to mount /boot again. Make sure to use the right boot drive path instead of /dev/sda as this is merely an example. If /boot is not mounted before running grub-install, the system will become unbootable.
As previously mentioned, if GRUB2 was emerged with the
multislot
USE flag then grub2-install must be used instead of grub-install. In this case, after GRUB Legacy is removed from the system in the next step, GRUB2 should be re-emerged without the multislot
USE flag so that grub-install and grub-mkconfig can become GRUB2 commands.root #
grub-install /dev/sda
Installation finished. No error reported.
At this point use the package manager to remove sys-boot/grub:0
.
root #
emerge -avC "=sys-boot/grub-0.97*"
The migration is now complete.
Údržba GRUB2
Whenever a new kernel is installed, perform the next step so that the GRUB2 configuration recognizes the new kernel (except when using a manual configuration).
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
This page is based on a document formerly found on our main website gentoo.org.
The following people contributed to the original document: Cardoe
They are listed here because wiki history does not allow for any external attribution. If you edit the wiki article, please do not add yourself here; your contributions are recorded on each article's associated history page.