5W site logo 5W - мой домашний сайт-блог с картинками, кино и плюшками.

grub-arch.txt

BIOS systems
GUID Partition Table (GPT) specific instructions
On a BIOS/GPT configuration a BIOS boot partition is required. GRUB embeds its core.img into this partition.
Note:
Before attempting this method keep in mind that not all systems will be able to support this partitioning scheme. Read more on GUID partition tables.
This additional partition is only needed on a GRUB, BIOS/GPT partitioning scheme. Previously, for a GRUB, BIOS/MBR partitioning scheme, GRUB used the Post-MBR gap for the embedding the core.img). GRUB for GPT, however, does not use the Post-GPT gap to conform to GPT specifications that require 1_megabyte/2048_sector disk boundaries.
For UEFI systems this extra partition is not required, since no embedding of boot sectors takes place in that case. However, UEFI systems still require an ESP.




Create a mebibyte partition (+1M with fdisk or gdisk) on the disk with no file system and with partition type BIOS boot. Select BIOS boot and partition type number 4 for fdisk, ef02 for gdisk, and bios_grub for parted. This partition can be in any position order but has to be on the first 2 TiB of the disk. This partition needs to be created before GRUB installation. When the partition is ready, install the bootloader as per the instructions below.
The post-GPT gap can also be used as the BIOS boot partition though it will be out of GPT alignment specification. Since the partition will not be regularly accessed performance issues can be disregarded, though some disk utilities will display a warning about it. In fdisk or gdisk create a new partition starting at sector 34 and spanning to 2047 and set the type. To have the viewable partitions begin at the base consider adding this partition last.
Master Boot Record (MBR) specific instructions
Usually the post-MBR gap (after the 512 byte MBR region and before the start of the first partition) in many MBR (or 'msdos' disklabel) partitioned systems is 31 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 to 2 MiB is recommended to provide sufficient room for embedding GRUB's core.img (FS#24103). It is advisable to use a partitioning tool that supports 1 MiB partition alignment to obtain this space as well as to satisfy other non-512 byte sector issues (which are unrelated to embedding of core.img).
Installation
Install the grub package. It will replace grub-legacyAUR, where already installed.
Note: Simply installing the package will not update the /boot/grub/i386-pc/core.img file and the GRUB modules in /boot/grub/i386-pc. You need to update them manually using grub-install as explained below.
Install boot files
There are 4 ways to install GRUB boot files in BIOS booting:
Install to disk (recommended)
Install to external USB stick (for recovery)
Install to partition or partitionless disk (not recommended)
Generate core.img alone (safest method, but requires another BIOS bootloader like Syslinux to be installed to chainload /boot/grub/i386-pc/core.img)


Note: See https://www.gnu.org/software/grub/manual/html_node/BIOS-installation.html for additional documentation.
Install to disk
Note: The method below is specific to installing GRUB to a partitioned (MBR or GPT) disk, with GRUB files installed to the current /boot/grub directory and its first stage code installed to the 440-byte MBR boot code region (not to be confused with MBR partition table). To signal grub-install to install files to a different location, such as when migrating to new drives, use the --boot-directory flag, such as in #Install to external USB stick.
The following commands will:
Set up GRUB in the 440-byte Master Boot Record boot code region
Populate the /boot/grub directory
Generate the /boot/grub/i386-pc/core.img file
Embed it in the 31 KiB (minimum size - varies depending on partition alignment) post-MBR gap in case of MBR partitioned disk
In the case of a GPT partitioned disk it will embed it in the BIOS Boot Partition, denoted by bios_grub flag in parted and EF02 type code in gdisk


# grub-install --target=i386-pc /dev/sdx
# grub-mkconfig -o /boot/grub/grub.cfg

If you use LVM for your /boot, you can install GRUB on multiple physical disks.
Install to external USB stick
Assume your USB stick's first partition is FAT32 and its partition is /dev/sdy1

# mkdir -p /mnt/usb
# mount /dev/sdy1 /mnt/usb
# grub-install --target=i386-pc --debug --boot-directory=/mnt/usb/boot /dev/sdy
# grub-mkconfig -o /mnt/usb/boot/grub/grub.cfg

Optionally backup configuration files of grub.cfg:

# mkdir -p /mnt/usb/etc/default
# cp /etc/default/grub /mnt/usb/etc/default
# cp -a /etc/grub.d /mnt/usb/etc


# sync; umount /mnt/usb

Install to partition or partitionless disk
Warning: GRUB strongly discourages installation to a partition boot sector or a partitionless disk as GRUB Legacy or Syslinux does. This setup is prone to breakage, especially during updates, and is not supported by the Arch developers.
To set up grub to a partition boot sector, to a partitionless disk (also called superfloppy) or to a floppy disk, run (using for example /dev/sdaX as the /boot partition):

# chattr -i /boot/grub/i386-pc/core.img
# grub-install --target=i386-pc --debug --force /dev/sdaX
# chattr +i /boot/grub/i386-pc/core.img

Note:
/dev/sdaX used for example only.
--target=i386-pc instructs grub-install to install for BIOS systems only. It is recommended to always use this option to remove ambiguity in grub-install.




You need to use the --force option to allow usage of blocklists and should not use --grub-setup=/bin/true (which is similar to simply generating core.img).
grub-install will give out warnings like which should give you the idea of what might go wrong with this approach:

/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.
/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists.
However, blocklists are UNRELIABLE and their use is discouraged.

Without --force you may get the below error and grub-setup will not setup its boot code in the partition boot sector:

/sbin/grub-setup: error: will not proceed with blocklists

With --force you should get:

Installation finished. No error reported.

The reason why grub-setup does not by default allow this is because in case of partition or a partitionless disk is that GRUB relies on embedded blocklists in the partition bootsector to locate the /boot/grub/i386-pc/core.img file and the prefix directory /boot/grub. The sector locations of core.img may change whenever the file system in the partition is being altered (files copied, deleted etc.). For more info, see https://bugzilla.redhat.com/show_bug.cgi?id=728742 and https://bugzilla.redhat.com/show_bug.cgi?id=730915.
The workaround for this is to set the immutable flag on /boot/grub/i386-pc/core.img (using chattr command as mentioned above) so that the sector locations of the core.img file in the disk is not altered. The immutable flag on /boot/grub/i386-pc/core.img needs to be set only if GRUB is installed to a partition boot sector or a partitionless disk, not in case of installation to MBR or simple generation of core.img without embedding any bootsector (mentioned above).
Unfortunately, the grub.cfg file that is created will not contain the proper UUID in order to boot, even if it reports no errors. see https://bbs.archlinux.org/viewtopic.php?pid=1294604#p1294604. In order to fix this issue the following commands:

# mount /dev/sdxY /mnt #Your root partition.
# mount /dev/sdxZ /mnt/boot #Your boot partition (if you have one).
# arch-chroot /mnt
# pacman -S linux
# grub-mkconfig -o /boot/grub/grub.cfg

Generate core.img alone
To populate the /boot/grub directory and generate a /boot/grub/i386-pc/core.img file without embedding any GRUB bootsector code in the MBR, post-MBR region, or the partition bootsector, add --grub-setup=/bin/true to grub-install:

# grub-install --target=i386-pc --grub-setup=/bin/true --debug /dev/sda

Note:
/dev/sda used for example only.
--target=i386-pc instructs grub-install to install for BIOS systems only. It is recommended to always use this option to remove ambiguity in grub-install.




You can then chainload GRUB's core.img from GRUB Legacy or syslinux as a Linux kernel or as a multiboot kernel (see also Syslinux#Chainloading).