Thursday, June 1, 2023

Install grub boot loader + Fix Windows instalation

GRUB (GRand Unified Bootloader)

BIOS will read the first sector of a storage device for a boot partition table.
MBR( master boot record) - 4 partitions
To boot mbr you need UEFI set to boot mode:  Legacy BIOS.

For UEFI - you need a GPT partition table and a fat16/fat32 partition anywhere on the disk  with an EFI folder - 100mb for windows 200mb linux (has all drivers here).
Kernel 10mb + initramfs 75mb ~ 100mb + 30mb windows bcd.
GPT (Globally Unique Identifier Partition Table) - 128 partitions
EFI partition - FAT16, FAT32 or VFAT

UEFI will look into
<EFI_SYSTEM_PARTITION>\EFI\
Will read folders from here - and display them in UEFI boot menu
Everyfolder must have a xxx.efi boot file

FIX Windows BOOT

The System Reserved partition is optional and is created by the windows setup for the BitLocker only as it stores un-encrypted data in order to decrypt and boot main partition
It also has the BCD (Boot Configuration Data) folder.

To avoid it press SHIFT+F10 at windows setup it opens a cmd :
diskpart
select disk 0
create partition primary
and continue with graphical setup.

Install a boot manager - boot windows install media, press SHIFT+F10 to open a CMD promt

diskpart
select disk 0
list volume
select volume 2 (pick the fat32 one)
assing letter k:
exit

Create a BCD store. - required to boot windows.
bcdboot c:\Windows /l en-GB /s K: /f ALL
Bcdboot.exe c:\windows /s c:
 
/s k: = install to k:

Grub doesnt see ext4 unknown filesystem --- remove metadata_csum
sudo dump2fs /dev/sda1 | head -20

install package e2fsprogs
sudo tune2fs -O ^metadata_csum /dev/sda1  -- remove
sudo tune2fs -O metadata_csum /dev/sda1  -- add
sudo e2fsck -f /dev/sda1

Edit grub on windows

open diskpark - type ar run or cmd
list volume
select volume 1
assign letter=z

You will get access denied efi partition windows when you try to access the partition.
Right click on start menu - and select PowerSheel (admin)
Type z:  then use cd and ls to navigate
To edit grub.cfg type notepad grub.cfg at the proper path

remove letter=z in diskpart again to remove it from explorer

Install GRUB

mount /dev/xxx /mnt  --- efi partition
--boot-directory=/mnt -- it will install under /mnt/grub - grub files
--efi-directory=/mnt -- it will install under /mnt/EFI/os_name (Microsoft/Debian/Ubuntu etc)
grub-install --boot-directory=/mnt --efi-directory=/mnt --target=x86_64-efi
grub-mkconfig > /mnt/grub/grub.cfg
grub-update is equivalent to grub-mkconfig
grub-mkconfig -o /boot/efi/EFI/grub/grub.cfg

ls 
grub> ls (hd1,gpt3)/
grub> set root=(hd0,1) grub> linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1 grub> initrd /boot/initrd.img-3.13.0-29-generic grub> boot

optional (insmod part_gpt, insmod chain)
set root=(hd0,gpt1)
use tab after / or after each folder to explore contents - bootmgr is for bios, bootmgfw.efi for uefi.
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
boot

Grub: no suitable video mode found boot in blind mode
insmod all_video

Edit grub.cfg :

insmod all_video
insmod part_gpt
insmod ext2
insmod gzio
insmod gfxterm
insmod gettext

font=unicode

set gfxmode=auto
set lang=en_US
set timeout=5
set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue

# For booting Microsoft Windows
menuentry "Microsoft Windows 7" {
    set root=(hd0,2)
    chainloader +1
}

menuentry 'Debian' {
set root='hd0,gpt2'
echo 'Loading Linux ...'
linux /boot/vmlinuz-5.10.0-11-amd64 root=/dev/sda2 ro
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-5.10.0-11-amd64
}

menuentry 'UEFI Firmware Settings' $menuentry_id_option 'uefi-firmware' {
fwsetup
}

Manual boot from GRUB menu

chainloader /efi/Microsoft/Boot/bootmgfw.efi
boot

iso images:
loopback lo (hd0,4)/image.iso
linux (lo)/artix/vmlinuz boot=casper iso-scan/filename=${isofile}
initrd (lo)/artix.initrd.gz
boot

ls - shows disks
ls (hd0,1)/    +tab = browse partitions

If you get to grub boot menu grub 0.x
root (hd0,0) --- this will mount the partition
kernel /boot/vmlinuz... root=/dev/sda1
initrd /boot/initrd....
boot

Grub 2
ls
set root=(hd0,msdos1)
linux /boot/vmlinuz... root=/dev/sda1
initrd /boot/initrd...
boot

Grub custom font

# Generate a GRUB-compatible font with specified size
# from a TTF (type-type font)

sudo grub-mkfont --output=/boot/grub/fonts/DejaVuSansMono36.pf2 --size=36 /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf


Slow loading of linux from USB on old laptops

Grub calls the BIOS to read from the USB.
Some usb sticks are not compatible with bios drivers for high speed usb. Other sticks might work at faster speeds.
 
 Grub uses bios driver to load vmlinuz and initramfs from usb and it is using USB 1.0 - it has a speed of around 1.5Mbps = 0.2MB/s. 75mb/0.2 = 375 = 5-10 min.

For old laptops / pcs:

The Plop Boot Manager is a small program to boot different operating systems.
The boot manager has a built-in ide cdrom and usb driver to access that hardware without the help/need of a bios.

https://www.plop.at/en/bootmanager/intro.html

No comments:

Post a Comment