When Grub2 fails to boot, and you get grub rescue>, grub: or just the word GRUB in the upper left corner of the screen, don’t panic. There is an easy fix to your problem. Really.
You have to have /boot/grub installed, which comes with a LiveCD or a LiveUSB, or can be copied from another Linux partitition that has it. You normally have it on your root partition already. Then you can use there three commands, which can be entered separately or strung together with separating semi-colons or a pair of && symbols. If you use just the commands that appear here, you can copy and paste all three at once rather than do each one individually.
The commands are:
sudo rm /boot/grub/grub.cfg
sudo grub-install /dev/sda
That is essentially it. No need for boot-rescue or boot-rescue-disk, which presently does not catch this problem. The problem being that if /boot/grub/grub.cfg exists, it is only verified or ignored by update-grub. boot-rescue, and boot-rescue-disk. You are warned against modifying the conf.cfg file manually, but people feel they have to in order to set thingsd right.
But the best solution is to get rid of it with the rm (remove) command and force udate-grub to do it all over and do it right. But update-grub will make the present root partition the default, which may not be your preference, The solution is to reboot your PC and pick your preferred partition and repeat these steps. The third command can be modified to allow booting from any other device if you want, or skipped entirely if you used it previously and cam boot from the device you desire to boot from.
With the original grub, the file /etc/fstab had a " / " entry in it that defined which was the root, meaning boot, device. This could be in error, as the file could be manually altered and the needed executable vmlinuz file might not be at that location. Grub2 attempted to solve this with update-grub, which scans first for binary executables, and if it finds them, it looks for matching entries in /biit/grug/grub.cfg. Those it updates,
But it does not remove existing entries when there is no executable there anymore, or the UUID for that partition has changed, such as during a reformat or drive replacement, or a temporary USB drive drive that was mapped as bootable was removed, or even when a LivedCD image is mapped ito it manually, and the ISO file is later renamed, moved, or deleted. Just deleting /boot/grub/grup.cfg first and running sudo update-grub next takes care of these problems.
Not being an expert in all things Linux. I can still provide a rough script file outline for updating the install itself, then ensuring the grub.cfg file is amended correctly. This is the brute force way and overkillm as to ensure you get all updates and autoremoves through, it repeats the critical steps several times. You need to save it to a text file, which I have tentatively named “update”, then you need to go under the file’s Properties > Permissions and check the box Execute. Now it can be used, not just viewed and edited. From the terminal, you can type in “chmod +x update” instead if you want.
To run a script file from the GUI (referring to the Nautilus or other graphical File Manager). You can either make sure that you have the execute files feature enabled, or set up a desktop shortcut to it. In Ubuntu, the execution of script files is disabled by default. Enabling it is not hard, I install dconf-tools and use dconf-editor myself, but you may have the choice already in the rightmost button for the File Manager. To use dcong-editor, start it and go here and go to the preferences settings under your file manager’s name. For Ubuntu, it is org > gnome > Nautilus > preferences. You have to click on the little pointy arrows in front of each level’s name to open or close the subfolder windows. When you gwt there, you want to make sure tha the key executable-text-activation is set to ask, which is the best choice of the three.
If you are of a mind to do it from a terminal command line, this is what you need to enter:
sudo gsettings set org.gnome.nautilus.preferences executable-text-activation ‘ask’
With copy (highlight with left button on mouse and drag, or hols shift and used arrow keys), you copy selected text to the xlipboard with the Ctrl+C keys held down together.
The Ctrl. Alt, Special (has flag) and Shft keys are always held down first, then press C (for copy), X (for cut, think of mark out with an X), or V (paste, think of an arrow to where to put it it), and you can move the selection to and from a special place called the clipboard.
Only the last item X’d or C’d in this manner resides in the clipboard. There are alternatives that allow several past clippings to exist in the clipboard at once, but you can do pretty much the same thing by pasting the current contents to a temporary file. Text files are good for this if you are just concerned with keeping the text and dropping any graphics.
With terminals ansd the vi editor, you have to include the use of Shft along with the Ctrl key when doing these keyboard commands. The past is normally where the mouse was the last time the left mouse button was pressed, but could have moved in text as a result of using the keyboard. But with terminals, it is different: The paste is always to the cursor position on the command line.
For some reason, some installs can’t seem to maintain some settings, and this happens to be one of them. In such cases, you can edit a startup file like ,bashrc or ,profile and include the "sudo gsettings set org.gnome.nautilus.preferences executable-text-activation ‘ask’ " line in it, but without the double quotes. For different interfaces and different installs, the structure and location of such system and user settings may vary. But see how much simpler it can be to use the command line and even script these processes? That’s a worthy lesson in and of itself.
The remaing methods of actually executing a script file is to create a launcher (shortcut) to it. Or you can run it from within a terminal like so: sudo ./update. Now with most things done involving files, the assumption is that the file is in the present working directory which is found with the pwd command. But when it comes to execution a file, unlike Windows and DOS, the present working directory is ignored and the sought file myst be in one of the folders that is included in the automaticly passed $PATH variable. You can add your own $HOME folder to the $PATH variable if you want, and you have two choices in this matter:
(1) If you put it in any startup script, such as .bashrc or ,profile, the change is treated as being permanent.
(2) In other script files or in terminal mode, it is treated as just temporarym but it will appear permanent if one script calls another one. sort of a parent to child thing.
The other thing to consider is that folders and files whose names begin with a period (.) are normally kept hidden from view as presented by the file manager and somw other programs. Here we need to edit and use two hidden files. How do we make that work? Well, with a file manager yo enalbe it to display hidden folders and files, find it, and double left click it and open it with a text editor. Or since these are marked as executable, we can double-click on either and just pick Display. which opens it with the default text editor for us. Or we can right-click it and open it with the editor of our choice.
And while all text editors open additional files as tabs or shows them listed under or over Files, terminals generally give you a choice of opening a new tab or a new window. So multiple terminal windows, each doing its own thing, is no problem.
But to have multiple text editor windows open, you may need to use multiple text editors at once, and they won’t all appear or work the same. The text editors I chose to install and test include gedit, cream, leafpad, vim, Pluma, Mousepad, Kate, Kwrite, and others. I will whittle list down to about three, as that should be enough for what I have it in mind
I’m gpong to close with a copu of my update file content. <<<you may find this useful as a starting point for making your own version.
sudo apt-get -f install
sudo apt-get update
for a in 1 2 3 5 8; do
sudo apt-get -y dist-upgrade
sudo apt-get -y autoremove
b=$(sudo apt-get -f install)
sudo rm /boot/grub/grub.cfg
sudo grub-install /dev/sda