GRUB 2 places its files in three core locations:
/boot/grub/grub.cfg
- This is the main configuration file that replaces menu.lst. Unlike menu.lst, this file cannot be edited by hand! I strongly advise against trying to tamper with this file, using chattr command or anything of the sort. Let it be.
/etc/grub.d/
- This new directory contains GRUB scripts. These scripts are building blocks from which the grub.cfg file is built. When the relevant GRUB command is executed, the scripts are read in a certain sequence and grub.cfg is created.
/etc/default/grub
- This file contains the GRUB menu settings that are read by the GRUB scripts and written into grub.cfg. It is the customization part of the GRUB, similar to the old menu.lst, except the actual boot entries.
This means that if you want to change the GRUB menu, you will have to edit existing scripts or create new ones, then update the menu. This is more similar to LILO than GRUB legacy, which allow editing the menu on the fly.
https://www.dedoimedo.com/computers/grub-2.html
!!!!!!!Critical!!!!!!!
GRUB 2 uses PARTITION notation that starts with 1 and not 0 like GRUB legacy! This is terribly important to remember!
In other words, devices are still numbered from 0, but partitions start with 1. For example, this means that sda1 is now (hd0,1) and NOT (hd0,0) as before!
VERZEsudo grub-install --version
<===> jak zjistim verzi grubu napr (GRUB) 2.06-3~deb10u1
GRUB is a boot loader that allows users to boot multiple operating systems and kernel configurations.
all of GRUB’s settings is there >> /etc/grub.d
Priklad: GRUB menu pri bootovani ma tyto 4 polozky
Debian10
Advanced options for Debian10
MX Linux21
Advanced options for MX Linux21
v zakladnim nastaveni ma GRUB nabootuje tim uplne nahore (tj. Debian10 GNU/LINUX)
chceme-li zmenit zvirazneni urcite polozky pri startu, je nutne:
a) pro jistotu zazalohujeme GRUB <===> sudo cp /etc/default/grub /etc/default/grub.bak
b) editovat soubor /etc/default/grub (napriklad sudo nano /etc/default/grub nebo gksu gedit /etc/default/grub
)
c) najit si radek GRUB_DEFAULT=0
d) zmenit hodnotu na tu polozku, kterou chceme mit oznacenou - pozor polozky se pocitaj od 0 a ne od 1!!! takze 0 = Debian10 | 1 = Advanced options for Debian10 | 2 = MX Linux21 | 3 = Advanced options for MX Linux21 atd.
tudiz pokud chci nabootavat automaticky MX Linux21 tak zadam GRUB_DEFAULT=2
e) soubor /etc/default/grub ulozim
f) jeste je DULEZITE GRUB updatovat a to udelame prikazem <===> sudo update-grub
g) sudo reboot
a to je vse
Ostatni nastaveni:
GRUB_TIMEOUT=5
<===> cas po ktery PC vyckava, zda a co zvolite, pote spusti volbu defaultne zadanouGRUB_CMDLINE_LINUX_DEFAULT=”quiet”
<===> option is “quiet”, which means the boot process will be shown in text mode as in the screenshot belowGRUB_CMDLINE_LINUX_DEFAULT="splash"
<===> the boot process won’t be displayed in text mode; you will see a logo loading insteadGRUB_BACKGROUND=”ImageFilePath”
<===> muzeme si nahrat obrazek ktery se pri bootovani zobrazi v menu na pozadi | The image file must meet various specifications. GRUB supports JPG/JPEG images, but these are limited to 256 colors — so you probably won’t want to use a JPG image. Instead, you’ll probably want to use a PNG image that can have any number of colors. You could also use a TGA image file. if you need to replace the ImageFilePath with the actual path where your new background image resides. In our case, it was “/home/kbuzdar/BootLoader.jpeg”GRUB_DEFAULT=saved
<===> GRUB would automatically boot the last operating system you chose each time you boot If you choose GRUB_DEFAULT=saved, you also need to add a GRUB_SAVEDEFAULT=true line — otherwise it won’t work.GRUB_TIMEOUT=-1
<===> To prevent GRUB from booting automatically and always wait for you to choose an OS
sudo update-grub
<===> Máte počítač kde “C:” je Windows a k tomu je tam nějaký další disk (v mém případě dokonce dva, D: a F:). Na ten jste nainstalovali Ubuntu (boot USB klíčenky na kterou jste si dali čerstvé Ubuntu) a po dokončení a restartu zjistili, že to bootuje jen do Windows.
Dáno je to tím, že jste Ubuntu dali na další disk, zatímco první, kde jsou Windows, jste nechali nedotčený. Čistě teoreticky to mělo dopadnout dobře, protože při instalaci jste Ubuntu řekli ať umožní Dual Boot, ale nedopadlo.
Naštěstí je to snadno řešitelné vstupem do BIOSu a nastavením toho “dalšího” disku jako prvního v bootování a Ubuntu vám naběhne – v každém BIOSu (UEFI) je možné zvolit pořadí odkud se bootuje.
Jenže v Grub nemáte Windows z prvního disku a pokud byste chtěli nastartovat Windows, tak byste opět museli přes BIOS změnit pořadí.
Napravte to v Ubuntu spuštěním sudo update-grub
Mělo by v průběhu zobrazit něco jako “Found Windows 10 on /dev/sdb1”
Pak už při restartu v Grubu najdete Windows a můžete si vybírat mezi Ubuntu a Windows. Grub se bude ukazovat při každém zapnutí/restartu.
Reinstall GRUB
GRUB 2 can be installed even while you are booted in the OS. You do not need a live environment for that. Just execute the grub-install command against the device or the partition you desire.
grub-install "target"
"target" can be /dev/hda, /dev/sdb, /dev/sdc4, and so forth. It is important that you pay attention to the output produced by the command. If you have external disks connected at the time you run the command, it will add these disks to the list of mapped devices. There should be no big harm in that, but if some entries are incorrect, remove them.
GRUB vs GRUB2
The default menu for GRUB2 looks very similar to GRUB but there are some changes made in this.
Grub has two configuration files namely menu.lst and grub.conf whereas, Grub2 has only one main configuration file namely grub.cfg and it looks very close to a full scripting language. And this configuration file is overwritten by certain Grub 2 package updates, whenever a kernel is added or removed, or when the user runs update-grub. For any configuration changes, we need to run update-grub to make the changes effective.
In Grub, it is really hard for the normal user to modify the configuration. But Grub2 is more user-friendly, Grub-mkconfig will automatically changes the configuration.
In Grub, partition number starts from 0, whereas in Grub2 it starts with 1. The first device is still identified with hd0. These changes can be altered if needed by making some changes to device.map file of the '/etc/grub' folder.
Grub uses physical and logical addresses to address the disk, it can't even read from new paritions whereas, Grub2 uses UUID to identify a disk thus is more reliable. It supports LVM and RAID devices.
In today’s Linux Distros including (Ubuntu 16.04 and RHEL 7), GRUB2 will now directly show a login prompt and no menu is displayed now.
If you want to see the menu during boot you need to hold down SHIFT key. Even sometimes by pressing ESC you can also display the menu.
Users have also now choice of creating custom files in which they can place their own menu entries. You can make use of a file called 40_custom which is available in '/etc/grub.d' folder.
Even users can now change the menu display settings. This is done through a file called grub located in /etc/default folder.
POKUD NENABIHA PC 1.
nemam zatim overeno!
sednete k počítači, zapnete ho a ten na vás místo zavaděče GRUB> _
1. Stáhněte a nabootujte Netist ISO / mozna postaci jakykoli LIVE CD/Flash s Linuxem
2. Po načtení Netinst ISO obrazu zvolíme z výběru položku "Advanced option"
3. Na následující obrazovce zvolíme "Rescue mode"
4. Zvolíme jazyk CZECH
5. Vložíme jméno počítače stejné jako při instalaci
6. Domenove jmeno / Název domény - není potřeba nastavovat
7. Zvolíme oblast disku, kam jsme umístili při instalaci kořenový adresář // napr. /dev/sdd1
8. Nyní již máme k dispozici vytouženou volbu "Reinstalovat zavaděč GRUB"
9. Zvolíme oblast, kam se má GRUB nainstalovat, zpravidla se jedná o první oblast na disku
10. Proběhne oprava / instalace zavaděče GRUB
11. Restartujeme systém
12. Všechno už by mělo být v cajku / mela by se objevit obrazovka s GRUB a vyberem
POKUD NENABIHA PC 2.
-------------
jak to opravit s MX - melo by fungovat overoval sem
-------------
##sednete k počítači, zapnete ho a ten na vás místo zavaděče GRUB> _
1. nabootujeme z flasky kde je MX19
2. spustim MX oprava zavadece (ikona s cervenym krizem)
3. nejdriv zkusime oprava zavadece - pokud nezabere po restartu zkusime instalace zavadece
4. po restartu se znovu obevi klasicke GRUB MENU
Repairing from a GRUB - Prompt
Find your Hard drive
ls
Output Example:
(hd0) (hd0,msdos2) (hd0,msdos1)
List Root partition on each drive til you find your Install
ls (hd0,msdos2)/
Check for the directory listing, if nothing, move to next
Now that we have found the proper drive lets boot to it
grub> set root=(hd0,msdos2)
grub> linux /boot/vmlinu (tab complete) root=/dev/sda1 (or the root linux partition)
grub> initrd /boot/initrd (tab complete)
grub> boot
Repairing from a GRUB Rescue - Prompt
Find your Hard drive
ls
Output Example:
(hd0) (hd0,msdos2) (hd0,msdos1)
List Root partition on each drive til you find your Install
ls (hd0,msdos2)/
Check for the directory listing, if nothing, move to next
Now that we have found the proper drive lets boot to it
grub rescue> set prefix=(hd0,msdos2)/boot/grub
grub rescue> set root=(hd0,msdos2)
grub rescue> insmod normal
grub rescue> normal
grub rescue> insmod linux
grub rescue> linux /boot/vmlinu (tab complete) root=/dev/sda1 (or the root linux partition)
grub rescue> initrd /boot/initrd (tab complete)
grub rescue> boot
grub
Fix GRUB Permanently
Now that we are booted in from GRUB Rescue, we can begin work with repairing our grub permanently. First we rebuild the /boot/grub/grub.cfg file:
Debian-based Distributions use update-grub
Other Distributions use grub-mkconfig -o /boot/grub/grub.cfg
With the Configuration rebuilt, we now simply need to reinstall grub
grub-install /dev/sda
Note: /dev/sda is the DEVICE…NOT THE PARTITION.
Other Methods of Repairing GRUB
Use the [https://www.supergrubdisk.org/ image on a USB drive to repair][1]
Use a vanilla server distribution pen drive to boot to prompt, then chroot to your existing install and reinstall GRUB.
To check the GRUB bootloader, restart your PC while holding Shift. You should now see a list of the installed operating systems; navigate the menu using the arrow keys.
If not, then the problem is that the GRUB bootloader is broken or overwritten. Repairing the bootloader is the only solution. (If you're dual booting, you'll still be able to access Windows)
Repair the GRUB Bootloader to Boot Ubuntu
If GRUB is not loading, then Ubuntu won't boot. Fortunately, you can repair GRUB using the Ubuntu installation media. Restart the computer with the disc inserted and wait for it to load up.
Again, you may need to change the boot order, as described above. Make a note of the boot order before you change it!
With the installation media booted into the Live environment, confirm you have a network connection and then open a Terminal. Enter:sudo grub-install /dev/sda
You can also update GRUB with:sudo update-grub
You should now be able to restart your PC and boot into Ubuntu. Alternatively, it will be listed as an option in the GRUB bootloader menu.