Grub: Difference between revisions

From ALT Linux Wiki
(Created page with " == What is GRUB? == Wikipedia reports "GNU GRUB (English: GRand Unified Bootloader) is an operating system loader from the GNU project. GRUB allows the user to have several operating systems installed and, when the computer is turned on, select one of them to boot." GRUB 2 == Why do I need GRUB if I have LILO/ELILO? == * Support for Raid modules, LVM file systems, coupled with an interactive interface, allow you to choose what to download from any...")
 
Line 184: Line 184:
* Boot from rescue-cd, for example [[Rescue|ALT Linux Rescue]]
* Boot from rescue-cd, for example [[Rescue|ALT Linux Rescue]]
* If [[Rescue|ALT Linux Rescue]] is used:
* If [[Rescue|ALT Linux Rescue]] is used:
mount-system
    mount-system
chroot /mnt/system1
chroot /mnt/system1
* If there is no mount-system in the LiveCD used, we do it ourselves (assuming/knowing that the root is on /dev/sda2):
* If there is no mount-system in the LiveCD used, we do it ourselves (assuming/knowing that the root is on /dev/sda2):
mount /dev/sda2/mnt
    mount /dev/sda2/mnt
mount -o bind /dev /mnt/dev
    mount -o bind /dev /mnt/dev
mount -o bind /proc /mnt/proc
    mount -o bind /proc /mnt/proc
mount -o bind /run /mnt/run
    mount -o bind /run /mnt/run
mount -o bind /sys /mnt/sys
    mount -o bind /sys /mnt/sys
chroot /mnt/ /bin/bash
chroot /mnt/ /bin/bash
* Download the previous version of the package:
* Download the previous version of the package:
Line 198: Line 198:
rpm -Uvh --oldpackage /home/andy/grub2-pc-1.99-alt9.i586.rpm
rpm -Uvh --oldpackage /home/andy/grub2-pc-1.99-alt9.i586.rpm
* Reconfiguring the grub menu
* Reconfiguring the grub menu
grub-mkconfig -o /boot/grub/grub.cfg
    grub-mkconfig -o /boot/grub/grub.cfg


After the above, my operating system booted up.
After the above, my operating system booted up.

Revision as of 09:13, 29 January 2024

What is GRUB?

Wikipedia reports "GNU GRUB (English: GRand Unified Bootloader) is an operating system loader from the GNU project. GRUB allows the user to have several operating systems installed and, when the computer is turned on, select one of them to boot." GRUB 2

Why do I need GRUB if I have LILO/ELILO?

  • Support for Raid modules, LVM file systems, coupled with an interactive interface, allow you to choose what to download from anywhere "'during the download process'" (rather than installing a loader).
  • Multiboot capability (for downloading, for example, XEN)

How do I install GRUB?

Install the distribution from GRUB or migrate the bootloader manually.

apt-get install grub
grub-install /dev/sda # replace /dev/sda with the device where you want to install GRUB
grub-mkconfig -o /boot/grub/grub.cfg

The last point generates the GRUB config based on templates/scripts in /etc/grub.d/. It is not recommended to edit the resulting config manually because it will be destroyed by the next autogeneration (performed, for example, by installkernel).

Check the contents of /etc/sysconfig/grub2"': if there is no uncommented variable GRUB_AUTOUPDATE_DEVICE (it will not be manually changed when changing the bootloader, because it is added only by alterator-grub), add the device or their list; "'if root/boot is on md raid1, you should specify the list of disks on which it is placed"' -- for example, not '/dev/md0 ', but '/dev/sdb/dev/sda '. After that, you should run "'grub-autoupdate"'.

How do I pass my kernel boot parameters?

To change them once when loading GRUB, you should:

  1. press "e" with the cursor on the boot target corresponding to the ALT instance being used;
  2. in the editor that opens, find the line starting with "'linux /boot/vmlinuz"';
  3. add the required parameters to its end, separated by a space;
  4. press F10.

If you need these kernel parameters to be passed to the kernel at each boot, you need to register them in /etc/sysconfig/grub2 and give the command update-grub; for more information, see the next paragraph.

Where can I edit the kernel parameters?

To permanently apply other boot parameters, you should change the bootloader configuration.

  • Kernel parameters are contained in /etc/sysconfig/grub2
  • After editing this file, you need to call grub-mkconfig -o /boot/grub/grub.cfg

The following options are supported in /etc/sysconfig/grub2:

GRUB_AUTOUPDATE_CFG=true/false

whether to update the config file from the kernel installation/removal trigger (by default true)

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash your_point 1 your_point 2"

kernel boot options

GRUB_AUTOUPDATE_CFGNAME=/boot/grub/grub.cfg

name of the auto-updatable config file. (default is /boot/grub/grub.cfg)

GRUB_VMLINUZ_SYMLINKS=true/false/default

whether to add symlinks to the menu (add, do not add, add only /boot/vmlinuz [default])

GRUB_VMLINUZ_FAILSAFE=true/false/default

whether to add failsafe items (add, do not add, add only for /boot/vmlinuz [default])

How do I add my own menu items?

  • Theoretically, you shouldn't want to do this. Tell us (in the sisyphus@ newsletter, for example) why you wanted to do this - perhaps some new general case will come up.
  • If you still want to, add what you think is necessary in /etc/grub.d/40_custom

For example, if "Windows 10" is not automatically detected, this description of the menu item may help:

menuentry 'Windows 10' {
    search --fs-uuid --no-floppy --set=root <UUID>
    chainloader (${root})/EFI/Microsoft/Boot/bootmgfw.efi
}

Where UUID is the UUID of the Windows bootloader partition. To find out the UUID of a section, use the blkid command

  • After editing this file, you need to call #grub-mkconfig -o /boot/grub/grub.cfg

How do I choose the default boot kernel (the first point of grub)?

With the installkernel <kernel name> command, you can use the variable — for example, for the current one:

  1. installkernel $(uname -r)

A proposal has been made (altbug #38888) by adding the -d, --default options to the update-kernel utility. Whether it will be implemented is unknown.

How do I choose what will be loaded automatically?

"this item is very similar to the following, but there are links to this item"

  • Select the item you need once when downloading. savedefault should save your choice for the future.
  • Don't like this behavior? Disable GRUB_SAVEDEFAULT in /etc/sysconfig/grub2
  • NB: in 2.00+, the behavior has changed, now additional cores for the same root are hidden in the "Advanced options" submenu.

How to wean GRUB2 from remembering the last selected item?

The behavior of Grub in terms of remembering items depends on the GRUB_DEFAULT and GRUB_SAVEDEFAULT variables in the /etc/sysconfig/grub2 file. GRUB_DEFAULT can contain a menu item for loading, or the service word 'saved'. If GRUB_DEFAULT='saved' (in ALT by default), the download is determined by the contents of the file /boot/grub/grubenv: the grub-set-default utility sets the value of the saved_entry variable, the grub-reboot utility sets the value of the next_entry variable (used once at the next boot, then it is cleared). The grub-entries utility (Template:Altbug) displays a list of existing options (although incomplete in terms of acceptable spellings: mixed options and selection based on the ID of menu items are not displayed). If GRUB_SAVEDEFAULT=true (in ALT by default), the savedefault command is added to the Grub menu items, causing the saved_entry variable to be changed in the /boot/grub/grubenv file.

Method 1

In the /etc/sysconfig/grub2 file, change the value of GRUB_SAVEDEFAULT to false, regenerate the grub config:

grub-mkconfig -o /boot/grub/grub.cfg

view the available list of options for downloading the grub-entries utility:

grub-entries

for example

0       ALT p8 starter kit
1>0     Advanced options for ALT p8 starter kit>ALT p8 starter kit, vmlinuz
1>1     Advanced options for ALT p8 starter kit>ALT p8 starter kit, vmlinuz (recovery mode)
1>2     Advanced options for ALT p8 starter kit>ALT p8 starter kit, 4.14.97-un-def-alt0.M80P.1
1>3     Advanced options for ALT p8 starter kit>ALT p8 starter kit, 4.9.154-std-def-alt0.M80P.1

2 Memtest86+-5.01 set the desired download option:

grub-set-default "Advanced options for ALT p8 starter kit>ALT p8 starter kit, 4.14.97-un-def-alt0.M80P.1"

or

grub-set-default "1>2"

is better not to use the numeric option, since the line numbers change when removing and adding kernels, but it can be used to specify the option for the next reboot with the grub-reboot utility.

Attention! There was a possibility of a sudden change in the letter name Template:Altbug


Method 2

In the /etc/sysconfig/grub2 file, change the line

 GRUB_DEFAULT='saved'

to GRUB_DEFAULT=n where n is the number of the menu item, or to

 GRUB_DEFAULT='exact name of the menu item'

The name option is preferable because after the kernel update, the number of menu items will increase and the numbering of some items will change. Attention!"' Item numbering starts from 0. The list of items can be obtained by command

grep menuentry /boot/grub/grub.cfg | nl -v0

For example, let's say we have the following menu items (this example does not take into account the current state with a submenu; left as an example, it is more convenient to use grub-entries, as in the first option):

# grep menuentry /boot/grub/grub.cfg | nl -v0
0	menuentry "ALT Linux 6.0.1 KDesktop" --class gnu-linux --class gnu --class os {
1	menuentry "ALT Linux 6.0.1 KDesktop (failsafe mode)" --class gnu-linux --class gnu --class os {
2	menuentry "ALT Linux 6.0.1 KDesktop, 3.0.8-std-def-alt0.M60P.1" --class gnu-linux --class gnu --class os {

3 menuentry "Windows Vista (loader) (on /dev/sda1)" --class windows --class os { 4 menuentry "Memtest86+-4.20" {

and we want Windows to load by default. Then in /etc/sysconfig/grub2 we write

 GRUB_DEFAULT='Windows Vista (loader) (on /dev/sda1)'

Then in the terminal from the root user:

grub-mkconfig -o /boot/grub/grub.cfg

Reboot. Since GRUB_DEFAULT has a specific value, and not 'saved', the GRUB_SAVEDEFAULT variable has no value.

How to load an arbitrary menu item once?

Sometimes it is convenient to boot with an arbitrary menu item, but not change the current option. This is convenient, for example, for testing a new kernel, when you need to be able to return the old kernel with a simple reboot. To do this, configure Grub in accordance with method 1 of the previous paragraph, after which you can set the menu item for the next boot with the grub-reboot command and run the reboot command. When the boot starts, the Grub configuration will automatically return to its original state, and the next computer boot will take place in the old way. This is similar to using the -R option of the Lilo loader.

How do I download Xen?

Xen is loaded using multiboot:

  • check that you are using grub2 >= 1.98-alt11
  • apt-get install xen xen-libs xen-runtime xen-hypervisor
  • run grub-mkconfig -o /boot/grub/grub.cfg
  • select the appropriate item when loading (savedefault will remember the selection for the future)

How do I enable serial port operation?

With lines like this in /etc/sysconfig/grub2: GRUB_TERMINAL='console serial'

GRUB_SERIAL_COMMAND='serial --unit=0 --speed=115200'

(see also). Don't forget about grub-mkconfig.

Booting Linux and Windows from different hard drives

Grub is loaded from the main disk on which Linux and Windows are installed to an additional hard disk. In 40_custom, add: menuentry "Windows XP" { drivemap -s (hd1) ${root}

set root='(hd1)'
chainloader +1
}

If there are more than two hard drives, we play with hdX.

How do I set a password for editing kernel parameters?

By default, any user can add/change parameters when downloading. This can be avoided by setting a password. The easiest way to do this is in the system management center. To do this, you will need the alterator-grub package and perform the following actions:

  • Log into the CCC (acc), switch to expert mode, and in the "System" section open the "GRUB Loader".
  • Select the "Set or reset password" checkbox and enter the required password.

After clicking on the "Install" button (GRUB reconfiguration occurs automatically), when starting the system and trying to either change the boot parameters (E key) or select another item in the boot menu, a login /password will be required. The default login is now "'boot"' (Template:Altbug)

Note: The login/password (the last one in hashed form) is written to the file /etc/grub.d/50_password:
#!/bin/sh
cat << EOF
set superusers="boot"
password_pbkdf2 boot grub.pbkdf2.sha512.10000.<hash>
EOF


Also, to limit the download (both with and without changing the parameters), you can add the following lines to the /etc/grub.d/40_custom file: set superusers="user" password user password

Attention! In this case, do not forget to prohibit ordinary users from reading this file (see Template:Altbug). And best of all, use hashed passwords. To do this, use password_pbkdf2 and the command grub-mkpasswd-pbkdf2.


For 6.0 series distributions, disable graphics in /etc/sysconfig/grub2 (see Template:Altbug): GRUB_TERMINAL_OUTPUT='console'

To protect the ability to download with the changed parameters with a password, you will have to add to the CLASS variable in the /etc/grub.d/10_linux script the option --unrestricted ("'attention"': this script is by as of version 2.00-alt20 is included in the grub-common package and is "not" marked as %config, so it will be overwritten when updating!).

After such operations, the configuration should be regenerated with the command grub-mkconfig -o /boot/grub/grub.cfg (or grub-mkconfig, depending on the distribution). If you use alterator-grub, this is not required.

How do I reinstall GRUB?

After upgrading to grub2-pc-2.00-alt1 The operating system may not boot. In this case, it is necessary to have any live disk at hand. Next:

   mount-system

chroot /mnt/system1

  • If there is no mount-system in the LiveCD used, we do it ourselves (assuming/knowing that the root is on /dev/sda2):
   mount /dev/sda2/mnt
   mount -o bind /dev /mnt/dev
   mount -o bind /proc /mnt/proc
   mount -o bind /run /mnt/run
   mount -o bind /sys /mnt/sys

chroot /mnt/ /bin/bash

  • Download the previous version of the package:

http://ftp.altlinux.org/pub/distributions/archive/Sisyphus/2012/10/30 /

  • Setting the rpm

rpm -Uvh --oldpackage /home/andy/grub2-pc-1.99-alt9.i586.rpm

  • Reconfiguring the grub menu
   grub-mkconfig -o /boot/grub/grub.cfg

After the above, my operating system booted up.

Based on the motives: http://edoceo.com/notabene/grub-probe-error-cannot-find-device-for-root

How do I install/restore the grub boot record?

Similar to the previous paragraph (see also Restoring Boot Record_#grub:

mount-system chroot /mnt/system1

  • If there is no mount-system in the LiveCD used, we do it ourselves (assuming/knowing that the root is on /dev/sda2):

mount /dev/sda2/mnt mount -o bind /dev /mnt/dev mount -o bind /proc /mnt/proc mount -o bind /run /mnt/run mount -o bind /sys /mnt/sys chroot /mnt/ /bin/bash

After the preparatory steps have been carried out and the root has been made, it is necessary to perform

grub-mkconfig -o /boot/grub/grub.cfg
grub-install /dev/sda # replace /dev/sda with the device where you want to install GRUB
Note: If you run the grub-install command in legacy mode, you get an error:
# grub-install /dev/sda
grub-install: error: cannot find EFI directory

then run the command:

# grub-install --target=i386-pc /dev/sda


if EFI mode is used, you may need to restore the bootloader in the ESP partition (EFI System Partition), which is mounted in /boot/efi:

mount -a # it is enough to mount the mount point /boot/efi grub-efi-autoupdate

What are the complaints about BIOS Boot Partition?

When booting under the PC BIOS, the MBR and a small free area of the disk after it (31 kilobytes up to the 63rd sector) are used - respectively, the first stage and core.img; when using UEFI, a GPT partition of the boot disk is expected, in which there is neither MBR nor this area. Hence, there is a need to embed the second stage of the loader somewhere else. This is the place where we decided to take the BIOS Boot Partition type defined in GPT.

The disk partitioning tool in the ALT Linux installer will make such a partition automatically under UEFI, if you split manually or a large disk for BIOS, you may need to create a minimum volume partition (RED Hat recommends 1 megabyte) with the type "bios boot partition" in the terminology alterator—vm or the label "bios_grub" in the terminology of parted.

See tj. archive article.

The picture is distorted during Windows boot, what should I do?

If, when booting, for example, Windows 7, part of the screen contains "noise", perhaps vaguely resembling the GRUB screensaver image -- try to align the VESA video modes used:

  • in the /etc/sysconfig/grub2 file, change GRUB_GFXMODE='800x600' to GRUB_GFXMODE='640x480'[1];
  • run the command update-grub or grub-mkconfig -o/boot/grub/grub.cfg

You can make the screensaver text-based by specifying GRUB_GFXMODE='console'.

Where else can I read?

And also in the operating system: info grub info -f grub -n 'Simple configuration'

  • ...well, you should at least call it by name os-prober

Notes

  1. you may need to adjust the resolution, for example 1024x768 -- see tj. here and here