# Setup scenario
rm /boot/grub/grub.cfg # delete file
sudo grub-install /dev/sda
sudo reboot
# After reboot, you're in grub mode
# Locate the partition to boot to
grub> ls
(hd0) (hd0,msdos1)
grub> ls (hd0,msdos1)/ # can use tab completion
# Once you locate the partition to boot to:
grub> set root=(hd0,msdos1)
grub> linux /boot/vmlinuz-linux (tab complete) root=/dev/sdaX
grub> initrd /boot/initrd (tab compelete)
# example: initrd.img-4.19.0-0.bpo.4-amd64
grub> boot
# You should be able to boot and login as normal
# After login, generate grub configuaration file
sudo -i
update-grub # debian-based distro
# or
grub-mkconfig -o /boot/grub/grub.cfg # other distro
grub-install /dev/sdX
reboot
# Setup scenario
sudo -i
cd /boot
rm -rf grub/
reboot
# After reboot, you're in grub rescue mode
grub rescue>
# Insert the Live CD/ media and reboot
# Inside Live CD/ media as root
mount /dev/sdaX /mnt # set mount point
chroot /mnt # run shell with root under /mnt
mkdir /boot/grub # rebuild grub
update-grub # debian-based distro
# or
grub-mkconfig -o /boot/grub/grub.cfg # other distro
cd /boot/grub/
ls
# You should see have 1 file: grub.cfg
grub-install /dev/sdX
ls
# You should see other files in addition to grub.cfg
exit
reboot