https://tecporto.pt/wiki/index.php?title=Booting_the_Linux_Kernel_without_a_bootloader&feed=atom&action=historyBooting the Linux Kernel without a bootloader - Histórico de revisões2024-03-29T12:00:57ZHistórico de edições para esta página nesta wikiMediaWiki 1.34.0https://tecporto.pt/wiki/index.php?title=Booting_the_Linux_Kernel_without_a_bootloader&diff=97&oldid=prevJoão em 02h00min de 2 de junho de 20182018-06-02T02:00:56Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="pt">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Revisão anterior</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revisão das 02h00min de 2 de junho de 2018</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l10" >Linha 10:</td>
<td colspan="2" class="diff-lineno">Linha 10:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>mount /dev/sda2 /mnt/root # if this fails, try fsck'ing your partition first</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>mount /dev/sda2 /mnt/root # if this fails, try fsck'ing your partition first</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>mount -t proc none /mnt/root/proc</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>mount -t proc none /mnt/root/proc</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>mount --<del class="diffchange diffchange-inline">bind </del>/dev /mnt/root/dev</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>mount --<ins class="diffchange diffchange-inline">rbind </ins>/dev /mnt/root/dev</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>mount --<del class="diffchange diffchange-inline">bind </del>/sys /mnt/root/sys</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>mount --<ins class="diffchange diffchange-inline">rbind </ins>/sys /mnt/root/sys</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>chroot /mnt/root /bin/bash</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>chroot /mnt/root /bin/bash</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></syntaxhighlight></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></syntaxhighlight></div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l85" >Linha 85:</td>
<td colspan="2" class="diff-lineno">Linha 85:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>Make sure you have access to the EFI variables. How? Well, either your running kernel has already the support for it, <del class="diffchange diffchange-inline">your </del>you can load the appropriate module:</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>Make sure you have access to the EFI variables. How? Well, either your running kernel has already the support for it, <ins class="diffchange diffchange-inline">or </ins>you can load the appropriate module:</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><syntaxhighlight lang="bash"></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><syntaxhighlight lang="bash"></div></td></tr>
</table>Joãohttps://tecporto.pt/wiki/index.php?title=Booting_the_Linux_Kernel_without_a_bootloader&diff=66&oldid=prevCláudia em 16h13min de 1 de junho de 20182018-06-01T16:13:23Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="pt">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Revisão anterior</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revisão das 16h13min de 1 de junho de 2018</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l97" >Linha 97:</td>
<td colspan="2" class="diff-lineno">Linha 97:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>efibootmgr --create --part 1 --label "Linux" --loader '\efi\boot\bootx64.efi'</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>efibootmgr --create --part 1 --label "Linux" --loader '\efi\boot\bootx64.efi'</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></syntaxhighlight></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></syntaxhighlight></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This code creates an entry in the boot menu (--create), for the EFI boot partition which is partition 1 of the first drive (--part 1), labelled "Linux" (--label "Linux") and with the loader '\efi\boot\bootx64.efi' (--loader '\efi\boot\bootx64.efi' ) - which is the kernel. The path of the loader is relative to the EFI boot partition and not to the whole mounted filesystem tree.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This code creates an entry in the boot menu (--create), for the EFI boot partition which is partition 1 of the first drive (--part 1), labelled "Linux" (--label "Linux") and with the loader '\efi\boot\bootx64.efi' (--loader '\efi\boot\bootx64.efi' ) - which is the kernel. The path of the loader is relative to the EFI boot partition and not to the whole mounted filesystem tree.</div></td></tr>
</table>Cláudiahttps://tecporto.pt/wiki/index.php?title=Booting_the_Linux_Kernel_without_a_bootloader&diff=65&oldid=prevCláudia: Criou a página com "Since version 3.3.x, and '''ONLY''' on EFI machines, it is possible to boot the Linux kernel without using a bootloader such as iELILO or GRUB. You will experience shorter b..."2018-06-01T16:12:54Z<p>Criou a página com "Since version 3.3.x, and '''ONLY''' on EFI machines, it is possible to boot the Linux kernel without using a bootloader such as iELILO or GRUB. You will experience shorter b..."</p>
<p><b>Página nova</b></p><div>Since version 3.3.x, and '''ONLY''' on EFI machines, it is possible to boot the Linux kernel without using a bootloader such as iELILO or GRUB. You will experience shorter boot times by using this, but a less interactive boot in case you need to make some diagnostics. In any case, you can almost always resort to some kind of removable media when you get into trouble. If you are installing Linux on a machine where you will never, ever, have any kind of alternative booting method, I do not recommend you use this method and go with a bootloader instead. You may need them to save your life in the future.<br />
<br />
Take a note: for this step to work, you need to have booted your system using UEFI. If you have a system that can boot both in UEFI mode and MBR mode, you need to switch it to UEFI mode in the setup and boot it using UEFI compatible media. This document makes several assumptions about paths which you need to correct to apply to your particular installation. For example, this document assumes your root partition is /dev/sda2 and that your kernel sources are in the /usr/src/linux folder and that your UEFI boot partition is /dev/sda1. These need not be necessarily the same in your system.<br />
<br />
After booting, you need to chroot into your installation. Fire up a terminal and do this:<br />
<br />
<br />
<syntaxhighlight lang="bash"><br />
mkdir /mnt/root<br />
mount /dev/sda2 /mnt/root # if this fails, try fsck'ing your partition first<br />
mount -t proc none /mnt/root/proc<br />
mount --bind /dev /mnt/root/dev<br />
mount --bind /sys /mnt/root/sys<br />
chroot /mnt/root /bin/bash<br />
</syntaxhighlight><br />
<br />
<br />
Now, mount any additional partitions you require, including the EFI boot partition if you already have it set up.<br />
<br />
If you are using a customized kernel, you need to make sure your kernel has the following options active:<br />
<br />
<br />
<syntaxhighlight lang="bash"><br />
CONFIG_EFI=y<br />
CONFIG_RELOCATABLE=y<br />
CONFIG_EFI_STUB=y<br />
CONFIG_EFI_PARTITION=y<br />
CONFIG_EFI_VARS=m #or y works too.<br />
CONFIG_FB_EFI=y<br />
CONFIG_FRAMEBUFFER_CONSOLE=y<br />
</syntaxhighlight><br />
<br />
<br />
Your kernel needs to support the EFI stub loader, GPT and MBR partitions, your primary filesystem of choice, the MSDOS and VFAT filesystems, the EFI Framebuffer, the EFI variables and be relocatable. Stock kernels from binary distributions usually will not require any kind of customization and will already include support for everything you need. Also, don't forget to disable the "Tickless system".<br />
<br />
Since you're not using a boot loader but you still need your kernel to know where your root partition is, you need to set CONFIG_CMDLINE as well:<br />
<br />
<syntaxhighlight lang="bash"><br />
CONFIG_CMDLINE="root=/dev/sda2 ro"<br />
</syntaxhighlight><br />
<br />
<br />
This example was for a JFS formatted root partition as the second entry on the first drive - remember, JFS root partitions need to be mounted read-only (hence the "ro") at boot time and only mounted read-write during init.<br />
<br />
Recompile your kernel and install the modules. Usually you'll do something like this:<br />
<br />
<syntaxhighlight lang="bash"><br />
make && make modules_install<br />
</syntaxhighlight><br />
<br />
<br />
Since you are using EFI, you must also be using a harddisk partitioned using the GPT format. This means that you also must have an EFI boot partition. This is a FAT32 formatted partition over 200MB in size. In this example, the said partition is /dev/sda1.<br />
<br />
It is typical to mount such partition under /boot/efi. You can add an entry to your "fstab" file if you like:<br />
<br />
<syntaxhighlight lang="bash"><br />
/dev/sda1 /boot/efi vfat noauto 1 2<br />
</syntaxhighlight><br />
<br />
<br />
Make sure you have the partition mounted. This tutorial assumes the previous folder as mountpoint.<br />
<br />
Now, inside that partition, you should have an "EFI" folder. And, inside the "EFI" folder, you should have a "boot" folder. So, yes, you'll have a path like "/boot/efi/EFI/boot/".<br />
<br />
You now need to copy your kernel to that folder, giving it the name bootx64.efi. For example:<br />
<br />
<syntaxhighlight lang="bash"><br />
cp /usr/src/linux/arch/x86/boot/bzImage /boot/efi/EFI/boot/bootx64.efi<br />
</syntaxhighlight><br />
<br />
<br />
Did it hurt, so far? I'm guessing no. So, keep on reading.<br />
<br />
The kernel is in the right place, what are we missing? Adding it to the boot menu. For this we need the "efibootmgr" utility. If it's not installed, go for it. These are examples for Gentoo and Debian-based systems (which includes Ubuntu and it's derivatives).<br />
<br />
<syntaxhighlight lang="bash"><br />
emerge efibootmgr<br />
</syntaxhighlight><br />
<br />
or<br />
<br />
<syntaxhighlight lang="bash"><br />
sudo apt-get install efibootmgr<br />
</syntaxhighlight><br />
<br />
<br />
Make sure you have access to the EFI variables. How? Well, either your running kernel has already the support for it, your you can load the appropriate module:<br />
<br />
<syntaxhighlight lang="bash"><br />
sudo modprobe efivars<br />
</syntaxhighlight><br />
<br />
<br />
And you can now, finally, add your kernel to the EFI boot menu:<br />
<br />
<syntaxhighlight lang="bash"><br />
efibootmgr --create --part 1 --label "Linux" --loader '\efi\boot\bootx64.efi'<br />
</syntaxhighlight><br />
<br />
This code creates an entry in the boot menu (--create), for the EFI boot partition which is partition 1 of the first drive (--part 1), labelled "Linux" (--label "Linux") and with the loader '\efi\boot\bootx64.efi' (--loader '\efi\boot\bootx64.efi' ) - which is the kernel. The path of the loader is relative to the EFI boot partition and not to the whole mounted filesystem tree.<br />
<br />
Atention: efibootmgr, unless otherwise stated, assumes /dev/sda - in the case of this example it's the right drive, but in your case it may be different.<br />
<br />
Leave the chroot'ed environment, unmount all mounted filesystems, remove the additional EFI bootable media and reboot your system. If all goes well, you can now enjoy a faster booting machine.<br />
<br />
<br />
References:<br />
* http://en.gentoo-wiki.com/wiki/UEFI<br />
* http://en.gentoo-wiki.com/wiki/Grub2<br />
* http://wiki.gentoo.org/wiki/GRUB2<br />
* http://forums.gentoo.org/viewtopic-t-895270-highlight-normal+mod.html<br />
* https://wiki.archlinux.org/index.php/UEFI_Bootloaders<br />
* http://www.thinkwiki.org/wiki/Installing_Gentoo_on_a_ThinkPad_X220<br />
* https://bbs.archlinux.org/viewtopic.php?pid=1090040<br />
* http://www.rodsbooks.com/efi-bootloaders/<br />
* https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/Documentation/x86/efi-stub.txt?id=HEAD</div>Cláudia