«
»

Tech Tip

Tweaking Grub 2

07.11.08 | 2 Comments

A little while ago I wrote about my problems booting Linux on a Dell Optiplex 320 the solution was to install Grub 2 and tweak the boot options. Since then I have run into a couple other problems which have required me to learn a little more about managing Grub 2 on a Debian based system (Ubuntu in my case). Specifically, I want my changes to grub.cfg to persist between kernel upgrades. So here is what I have learned.

Background

Every time a new kernel is installed, /usr/sbin/update-grub is called. This re-writes /boot/grub/grub.cfg. So any changes you make to grub.cfg directly are obliterated. However, the new grub.cfg is generated from:

  • /boot/grub/grub.cfg
  • /etc/grub.d

So if I know how to edit those files, I can make my changes persistent.

Changing default kernel options

/etc/default/grub allows you to set parameters that appear in the grub.cfg file. In my case I wanted every “linux” command to have the “acpi=off” option appended. So I added the following line to /etc/default/grub:
GRUB_CMDLINE_LINUX=acpi=off

Now just run
sudo /usr/sbin/update-grub
and presto! All the “linux” commands have acpi=off appended.

Adding a boot option

My other problem was that everytime grub.cfg was updated, my Windows boot option was deleted. To fix that I needed to add a new file to /etc/grub.d. Read /etc/grub.d/README for more details, but the summary is:

  1. Create a file named “21_windows”
  2. Put the following code in the file:
    #!/bin/bash
    set -e
    cat << EOF
    menuentry "Other Operating Systems" {
    set root=(hd0,1)
    title Other Operating Systems
    }menuentry "Microsoft Windows XP Professional" {
    set root=(hd0,1)
    chainloader +1
    boot
    }
    EOF
  3. Make the file executable:
    sudo chmod 755 /etc/grub.d/21_windows
  4. Re-run
    sudo /usr/sbin/update-grub

That is all, hope it helps.

2 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

You must be logged in to post a comment.


«
»