GRUB or GRand Unified Bootloader is a multiboot bootloader. When configuration file of grub is update it first scan the devices to find available operating system at the current machine by a script os-prober, which provide boot entries and location of each operating system. # mount -t ext4 /dev/sdb2 /mnt/os/
After mounting the OS drive following directories is require while installing grub so we will point those directories inside the OS drive. # mount --bind /proc /mnt/os/proc
# mount --bind /sys /mnt/os/sys
# mount --bind /dev/pts /mnt/os/dev/pts
# mount --bind /dev /mnt/os/dev
# mount --bind /run /mnt/os/run
After mounting now it is time to enter into chroot environment. # chroot /mnt/os
Below command will write grub codes at MBR sector that is in first 448 bytes default it copies the boot files at /boot/grub directory and copy the MBR code at 512 byte starting sector of the target disk at below example the target disk is /dev/sdb # grub-install /dev/sdb
Or # grub2-install /dev/sdb
In case if the grub package is partial missing or installation is corrupted then use below command but make sure Internet is available to download grub package. # apt update && apt install --reinstall grub-pc -y
Below command will create file at path /boot/grub/grub.cfg # update-grub
Or # grub2-mkconfig > /boot/grub2/grub.cfg
In some case manually path is need to mention so that the grub.cfg file can be update. Once the grub.cfg file is update then proceed to reboot the system to verify the changes. # reboot
Below script can be use to bind require paths for preparing chroot environment. Get into directory to download script. # cd /root/ # wget linuxcli.in/s/bm.sh Give execute permission to the script # chmod +x bm.sh Run script with -m switch to bind mount with current system's require directories which will be use for chroot environment # ./bm.sh -m /target/directory # chroot /target/directory Once the work is done in chroot environment exit from the shell and use -u to unmount those bind directories. # ./bm.sh -u /target/directory # umount /target/directory
|