17

I'm trying to update my grub config on ubuntu server 12.04.3 to include the GRUB_RECORDFAIL_TIMEOUT variable as described here: https://help.ubuntu.com/community/Grub2.

The procedure says run update-grub after making the change but it's doesn't appear to be on my system. How can I install this?

Braiam
  • 67,791
  • 32
  • 179
  • 269
Andy Arismendi
  • 273
  • 1
  • 2
  • 6

10 Answers10

36

The update-grub command was created to make things easier - it is simply a shell script in /usr/sbin/:

#!/bin/sh
set -e
exec grub-mkconfig -o /boot/grub/grub.cfg "$@"

If it is not there, you can make your own. To do that, run this, and paste in the above script:

sudo nano /usr/sbin/update-grub

Save with Ctrl+O, and exit with Ctrl+X.

Then run these:

sudo chown root:root /usr/sbin/update-grub
sudo chmod 755 /usr/sbin/update-grub

And you should now be able to run update-grub. :-)

dskecse
  • 103
Wilf
  • 30,194
  • 17
  • 108
  • 164
  • 1
    Thanks, since it was missing I reinstalled grub. Not sure if anything else might of went missing. – Andy Arismendi Feb 09 '14 at 19:42
  • 3
    This is a lifesaver if reinstalling grub is not an option because of a broken system. – plok May 05 '15 at 11:00
  • Yes, really, lifesaver. The update-grub command was on my system, but gave me a /cow error, this one gave no error output. – Quidam May 02 '20 at 08:24
  • Do you know how to regenerate grub.cfg from a live session? – Quidam May 02 '20 at 08:25
  • @Quidam https://askubuntu.com/q/145241/178596. Also tools such as Boot Repair AFAIK can do it sort of. Recovery Mode if you can access that is also an option (Dropping to a root shell prompt which can run commands after mounting partitons) – Wilf May 02 '20 at 09:37
  • Boot repair didn't. I tried many things from your link it seems, and got the /cow canonical path error. Looks like my system is messed up, I think the only option is a boot repairing live cd. – Quidam May 02 '20 at 10:05
13

I would reinstall grub by running the following command:

sudo apt-get update; sudo apt-get install --reinstall grub
jhilmer
  • 1,195
  • 9
  • 13
  • 2
    i lost update-grub after a do-release-upgrade. This worked for me. – boredcoding May 14 '17 at 20:07
  • 7
    I also did do_release_upgrade but don't know if I lost it after that. if I run the above command, this is what I get: Package grub is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source However the following packages replace it: grub2-common – nurp Sep 25 '18 at 09:32
  • Saved my life thrice, only solution that worked in chroot for me – testing_22 Oct 25 '21 at 19:15
3

you need to run it with root priviledges, run: sudo update-grub. Unless you removed it, its there in the system.

Bhavin Doshi
  • 2,466
  • 2
    It was definitely gone, not sure how it went missing. Re-install grub brought it back. – Andy Arismendi Feb 09 '14 at 19:43
  • It is NOT there on some Linux releases such as Fedora 31. Granted the question specifies Ubuntu but your answer could cover other releases using Grub. – Swiss Frank Sep 04 '22 at 09:14
2

If sudo update-grub doesn't work for you,

Try this

sudo grub-mkconfig -o /boot/grub/grub.cfg

It will make grub entry for you.

1

This is supplemental to Sajith Sajan's answer:

Take a look in /usr/sbin and /boot. You may need to run:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

instead.

1

If you get the following error:

$ sudo update-grub
sudo update-grub: command not found

That is caused by copying and pasting from the Ubuntu wiki not working. It turns the space into an invisible character. You have to manually type over the command to make it work.

Merlijn Sebrechts
  • 7,394
  • 1
  • 42
  • 70
0

For me, the issue was that I was the root user, at the time I attempted to run update-grub. When exit to my regular user account sudo update-grub works without error.

Lonnie Best
  • 2,194
  • 2
  • 35
  • 46
0

In my case, I tried this answer to do sudo apt-get update, but I get lock held by packagekitd process error with pid, even reboot still same.

I use ps alxww --forest to confirm pid of packagekitd. Then sudo strace -f -s 100 -p <PID> to attach pid to strace to see what's going on.

The log shows 2 paths get downloading, one of them is '/var/lib/apt/lists/partial/tw.archive.ubuntu.com_ubuntu_dists_focal-updates_Contents-amd64.gz'.

Simply use sudo watch ls -lathi '/var/lib/apt/lists/partial/' to watch the progress until it's done. Now sudo apt update is working. sudo apt-get install --reinstall grub shows Package grub is not available. But try again with sudo grub-update, the command is come back.

林果皞
  • 556
  • 6
  • 9
0

It could be that the update-grub script exists in another directory (eg. /usr/sbin) but that directory (/usr/sbin) is not on your system path.

If this is the case, you could run the script by specifying the exact path, eg. /usr/sbin/update-grub. However, to avoid another "command not found" error for grub-mkconfig, a better option would be to add the missing directory to the system path like this:

export PATH=$PATH:/usr/sbin
update-grub

This will let your system look up the /usr/sbin directory for update-grub as well as other executables in that directory.

Hippo
  • 517
DrInk
  • 1
  • 4
-1

I'm new to terminal and StackExchange, but I found a way around to **update-grub command not found **

:sudo apt-get update; sudo apt-get install --reinstall grub

I used the above command to reinstall GRUB, but it gave me

Package grub is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source However the following packages replace it: grub2-common:i386 grub-efi-amd64:i386 grub2-common grub-pc grub-efi-ia32 grub-efi-amd64

So i tried to reinstall above packages with :sudo apt-get install --reinstall (ABOVE 6 PACKAGES) EX: :sudo apt-get install --reinstall grub2-common

Then I used :sudo update-grub to update it, and it worked displaying

Adding boot menu entry for UEFI Firmware Settings ... done

then i used the following

:sudo apt install grub-efi-amd64:

:sudo update-grub:

:sudo grub-install:

Reboot and use the following

:sudo update-grub: