GRUB sucks sometimes. BASh script that could fix it automatically.
I am talking about this specific error. I have seen it so many times that I have grown tired of manually fixing this. With this BASh script I aim to automate the second half of the repair process.
Where you store the script is important. This is because. when you chroot into an existing installation, you mount to your Root Account Partition. So please, store it there!
It is not that hard to run it. First of all, don't panic. Your installation is not lost. Second, grab your Arch Linux install USB, plug it into your computer and boot to it. Then:
mkdir /mnt/arch
This will be used for the root partitionmkdir /mnt/arch/boot
This will be used for the boot partition
3) Mount the root and boot partition to the previously mentioned directories with mount
. Select the partitions with the help of the lsblk
command. I hope you remember how you set up your Arch Linux installation. Else, I don't know.
mount /dev/sdx/sdt /mnt/arch
(Where X is your Linux installation partition, and T is the specific partition where the root account is stored)mount /dev/sdx/sdy /mnt/arch/boot
(Where X is your Linux installation partition, and Y is the specific partition where the boot stuff is stored)
arch-chroot /mnt/arch
5) Run the script and follow the instructions! (Make sure to navigate to the location the script is stored at. Use cd [location (i.e. /home)]
to navigate somewhere.)
Run with sh grubrepairscript.sh
. If there are issues with permissions, run with sudo
but there shouldn't be any.
You can inspect the code, take a look at what commands run, and execute them manually. If that fails too, keep trying. If there's an actual error, give me a message, along with the error, and I will try to fix it.
You can look at the code even if the OS doesn't work. Straight out of the install disk. Just type nano grubrepairscript.sh
and it should open.
In case I lose access to my account or there is a modification to this that I didn't approve of, LOOK AT WHAT COMMANDS RUN! BEWARE OF sudo rm -rf /
IN PARTICULAR SINCE THAT WILL WIPE YOUR DISK! ALSO CHECK FOR ANY SUSPICIOUS PACKAGES THAT MIGHT BE IN THERE IN THE VERY RARE OCCASION I LOSE ACCESS! PACMAN SHOULD ONLY BE INSTALLING THE LINUX KERNELS!
This script can also fix the error where GRUB complains about Invalid magic number
. These steps actually were meant for that error but it also covers this (for me at least).
This error can occur many times. Or so it did for me. You can just follow these instructions whenever it happens.
Fun fact: many other steps can be automated, such as the creation of the directories, the mount
commands, the chroot, but all those would need the file to be stored at the install disk which is not possible, because the disk doesn't retain any info when its modified other than just the ISO's contents. Maybe the distro's maintainers could do something like including this file if its not considered bloat.
Second fun fact: the first time this occured, it took me 3 hours to fix my installation. So fun.