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

GRUB2 Migração

From Gentoo Wiki (test)
Jump to:navigation Jump to:search
This page is a translated version of the page GRUB2 Migration and the translation is 69% complete.
Outdated translations are marked like this.

O objetivo deste guia é fornecer aos leitores uma migração suave do GRUB Legacy para o GRUB2.

Background

O que é GRUB?

GRUB é um dos inicializadores em uso mais comumente encontrados em máquinas Linux não embarcadas. O papel do GRUB é facilitar o kernel Linux a ser carregado do disco para a memória e iniciar a execução do kernel Linux.

Por que migrar?

Em primeiro lugar, o GRUB Legacy não é mais mantido e, como tal, não recebe mais atualizações. O GRUB Legacy foi criado num momento em que os desenvolvedores se sentiam seguros em fazer diversas suposições que já não são mais verdade hoje. Por exemplo, o GRUB Legacy é incapaz de inicializar a partir de discos maiores que 2 TB e assume que os novos sistemas de arquivos não viriam para substituir o /boot.

O GRUB2 pretende ser mais robusto, mais portável, mais poderoso e é mantido com uma base de código mais limpa. GRUB2 suporta mais configurações de hardware, mais sistemas de arquivos e mais layouts de unidades do que seu predecessor.

Migração para o GRUB2

A migração para o GRUB2 é bastante simples: ele será puxado como parte do processo de atualização periódica pelo gerenciador de pacotes. Se ele não for puxado automaticamente, ele sempre poderá ser instalado via pacote atom sys-boot/grub:2:

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

Drive de boot

A primeira parte importante é entender qual drive é inicializável. Para aqueles que seguiram o Manual do Gentoo ele deve ser o /dev/sda. Para aqueles que são incertos, a maneira mais fácil de descobrir é olhar a configuração existente do GRUB Legacy. O arquivo /boot/grub/grub.conf é o principal lugar para verificar.

Note
Certifique-se que a partição /boot está montada para ser capaz de ver estes arquivos. Deve ser tão simples como
root #mount /boot

O arquivo grub.conf será algo parecido com isto:

FILE /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

Com base no arquivo acima é possível saber que (hd0) é o drive de boot mas precisamos mapeá-lo para um dispositivo real. Para saber isto, veja no arquivo /boot/grub/device.map. Um exemplo é fornecido um abaixo:

FILE /boot/grub/device.map
(fd0) /dev/fd0
(hd0) /dev/sda
(hd1) /dev/sdb
Note
When suspecting that /boot/grub/device.map is not accurate, run the following command to recreate the file:
root #grub-install --recheck /dev/sda

Com base no arquivo acima sabemos que /dev/sda é o drive de boot.

Instalando e configurando o 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.
Warning
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.
Note
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
Warning
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.
Note
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.
Note
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
Have a look at GRUB2 configuration on the Gentoo Wiki or the official GRUB2 manual to decide how to modify the file. Most users will need to change GRUB_CMDLINE_LINUX to specify parameters to be passed on the kernel command line.

Carregando em série o GRUB2 a partir do GRUB Legacy para testar a configuração

Uma configuração quebrada do GRUB pode significar um sistema impossibilitado de inicializar, queremos testar nossa configuração do GRUB2 antes de torná-la permanente. Para fazer isto, vamos carregar em série o GRUB2 a partir do GRUB Legacy. Isto é feito através da adição de uma nova seção em /boot/grub/grub.conf. Um exemplo é mostrado abaixo.

Note
Esteja ciente de que a partição root pode ser diferente de (hd0,0) usado no exemplo, e certifique-se de reutilizar o mesmo valor do root do arquivo de configuração /boot/grub/grub.conf.
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

Neste ponto a máquina precisa ser reiniciada, e GRUB2 Chainload selecionada do menu do GRUB quando a máquina iniciar o boot. Um outro menu do GRUB será apresentado, que deve anunciar-se como GRUB 2.0.0 ou superior no topo e mostrar o(s) kernel(s) disponível(eis) para iniciar. Se isto não funcionar, basta reiniciar a máquina e escolher a opção de boot normal, ao invés de GRUB2 Chainload.

Substituindo e removendo o GRUB Legacy

If everything worked successfully, replace GRUB Legacy and remove it from the system.

Warning
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.
Note
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.

Neste ponto use o gerenciador de pacotes para remover o sys-boot/grub:0.

root #emerge -avC "=sys-boot/grub-0.97*"

A migração está concluída.

Mantendo o GRUB2

Sempre que um novo Kernel for instalado, execute o próximo passo para que a configuração do GRUB2 reconheça o novo kernel (exceto quando usar uma configuração manual).

Note
Certifique-se que a partição /boot está montada para esta etapa.
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.