1

I need to be able to update the grub config to remove the recovery mode boot option, programmatically. I got the initial info for how to do this (manually) from this question/answer:

How to disable recovery mode/single user mode?

So I wrote a simple script, which is packaged up with a replacement grub file. The script simple does:

# Move the new grub file contents into place
cat /path/to/replacement/grub > /etc/default/grub
# Update grub with the new settings
update-grub

In this script the "/path/to/replacement/grub" has these contents: http://paste.ubuntu.com/7328274/, and replaces the standard file http://paste.ubuntu.com/7328269/ that's in the system. The system is Ubuntu 12.04, and the script above is run as sudo.

The problem is that most of the time it works, but some of the time it completely nerfs grub, and when the system is rebooted, it lands at the grub command line, rather than booting normally. From the grub command line, I can load the kernel, boot linux, and then when at the bash command line, I can run:

sudo update-grub

Then reboot, and everything is then fine. But can anyone tell me why sometimes it doesn't just work as part of the script?

Notes:

  1. The goal is simply to remove the recovery mode boot option from the grub menu, with no user intervention other than running the script - the reasons for this are complex, but that's the way it is :)

  2. The only difference between the 2 grub files should be the uncommenting of the line 'GRUB_DISABLE_RECOVERY="true"'

  3. I cat the contents into the correct file (instead of cp'ing or mv'ing) because I figured it was the easiest way to ensure that file perms weren't messed up.

  4. The process usually works, and rebooting the system removes the recovery mode grub menu option (as desired). But just sometimes ... doesn't work

1 Answers1

0
sed -i "s,#GRUB_DISABLE_RECOVERY,GRUB_DISABLE_RECOVERY,g" /etc/default/grub
Eric Carvalho
  • 54,385
  • I had considered sed, but before I just try various things (sed'ing cp'ing, mv'ing) I was hoping to find someone who might have an idea as to specifically why it was failing using the method I had used ... – David Downes Apr 28 '14 at 12:44
  • I don't have an idea but you can try this to find out; Check the content of a non working grub (/etc/default/grub). Redirect the errors in a file to check them. cat /path/to/replacement/grub > /etc/default/grub 2> /root/errorgrub.log – Adrien Horgnies Apr 28 '14 at 13:01