0

So i did a mistake of using Grub Customizer and then did another while trying to restore previous config by following instructions in /etc/grub.d/backup/RESTORE_INSTRUCTIONS, which led to corrupting my grub config files.

Now when i try to run sudo update-grup i get

Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Script `/boot/grub/grub.cfg.new' contains no commands and will do nothing
Syntax errors are detected in generated GRUB config file.
Ensure that there are no errors in /etc/default/grub
and /etc/grub.d/* files or please file a bug report with
/boot/grub/grub.cfg.new file attached.

The resulting grub.cfg.new is empty (it contains only the initial comment about it being generated).

I have tried to reinstall the grub according to this answer by

sudo apt-get purge grub-pc grub-common

but it no longer works. First the apt complained about unmet dependencies and when i added grub2-common grub-pc-bin to the list to be removed, it told me it needs to install these instead

... grub-common:i386 grub-efi-amd64 grub2-common:i386 ...

After some hesitation i accepted it, and let those packages install with the intention to replace them back aftewards, but i ran into this again during installation

Script `/boot/grub/grub.cfg.new' contains no commands and will do nothing
...
dpkg: error processing package grub-pc (--configure):
 installed grub-pc package post-installation script subprocess returned error exit status 1

So apparently the update-group is now part of the post-install script, and if it fails the package fails to install. So now i'm in a state where dependencies are broken in both ways and neither of the grub versions is properly installed and cannot be fixed.

The configuration files of the grub (/etc/default/grub and /etc/grub.d/*) were never removed and overwritten during the purge. And if i delete them manually, they are never installed again.

Is there anything i can do to save my installation of the OS now?

Youda008
  • 163

2 Answers2

1

apt purge is almost always the wrong solution for this kind of situation. That route is likely to remove stuff that is critical and if you remove enough stuff you'll back yourself into a corner that will require a reinstall to fix. The only time removing packages helps is if they replaced other packages that you are trying to reinstall.

Instead, I would recommend using dpkg -V to find corrupted files and permissions, and use apt install --reinstall to reinstall packages that have been corrupted. This will replace core corrupted files, but may leave config files corrupted. But it's a start.

When you find corrupted config files, you can try fixing them or renaming them, and use dpkg --reconfigure for the relevant package to try to rebuild the config files. dpkg --configure might help if the configs are completely messed up or deleted.

Another possibility is that there are extra files in the config directories that have corrupted your configuration. Again, apt purge will not remove those and won't fix anything. Finding those extra files needs to be done by process of elimination, but isn't impossible.

user10489
  • 5,533
0

The problem was the permissions, not missing/corrupted files or bad syntax, but wrong permissions. The backup files created by Grub Customizer in /etc/grub.d/backup/etc_grub_d do not have the execute flag. That's why empty grub.cfg was generated. And i couldn't see it because the error message of update-grub is misleading.

So it's not enough to just follow RESTORE_INSTRUCTIONS in /etc/grub.d/backup/ and copy /etc/grub.d/backup/etc_grub_d back to /etc/grub.d. You also have to

sudo chmod +x 0* 1* 2* 3* 4*

But i also think this should be reported as issue to the package maintainers. It's not ok that successful installation of a package requires running a script that depends on breakable user config. And it's not ok that trying to temporarily uninstall and reinstall that package results in a i386 subsystem being installed.

End of rant, thanks to all who helped.

Youda008
  • 163