Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

My question is about how to add a few lines to the /etc/default/grub file so that it is automatically reflected each time /boot/grub/grub.cfg is regenerated. The details:

I'm running ubuntu on a Macbook Pro 8.2 and one of the things that I had to do to get it to run correctly was alter the grub.cfg so that it only loads one of the two graphics cards. To turn off one of the cards I added the text concerning i915 in the GRUB_CMDLINE_LINUX_DEFAULT /etc/default/grub:

GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash i915.lvds_channel_mode=2 i915.modeset=1 i915.lvds_use_ssc=0"
GRUB_CMDLINE_LINUX=""

The problem is that I must also have the following adding to /etc/grub.cfg:

  outb 0x728 1
  outb 0x710 2
  outb 0x740 2
  outb 0x750 0

Which I've added in context in grub.cfg as so:

menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-1e8685ef-b6a8-4bf3-abb8-62d0212cea7c' {
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
insmod part_gpt
insmod reiserfs
outb 0x728 1
outb 0x710 2
outb 0x740 2
outb 0x750 0
set root='hd0,gpt4'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt4 --hint-efi=hd0,gpt4 --hint-baremetal=ahci0,gpt4  21c34907-4da5-4356-b1c8-a5d2747411ed
else...

How can I add this to the /etc/default/grub file so that I don't have to manually add it to the grub.cfg every time Ubuntu updates? Currently it appears as if each time Ubuntu updates it regenerates the /boot/grub/grub.cfg file from the /etc/default/grub file and it'd be helpful if these four lines could be included as well.

share|improve this question

3 Answers 3

Do not edit the /boot/grub/grub.cfg file. Edit the /etc/grub.d/10_linux file:

Add your commands to the

  cat << EOF
    insmod gzio
EOF

section, so it should read:

  cat << EOF
    insmod gzio
    outb 0x728 1
    outb 0x710 2
    outb 0x740 2
    outb 0x750 0
EOF

This file is sourced every time update-grub is run, and it is rarely overwritten by updates. (Or at least it will ask when you update whether you want to update this file or keep your modified version.)

share|improve this answer

To be honest, easiest way would be to backup the 2 files and each time Ubuntu updates, you run a script as root ofc:

#!/bin/sh
rm /boot/grub/grub && /boot/grub/grub.cfg
cp /directory/grub /boot/grub/
cp /directory/grub.cfg /boot/grub/

One thing, change /directory/ to your directory to the files :)

share|improve this answer

You must edit the configuration scripts directly. There's no way to add outb 0x728 1 to the grub.conf file, since the scripts that sources the variables there doesn't know how to manage these entries. This is said in the info pages:

For more detailed customisation of 'grub-mkconfig''s output, you may edit the scripts in '/etc/grub.d' directly. '/etc/grub.d/40_custom' is particularly useful for adding entire custom menu entries; simply type the menu entries you want to add at the end of that file, making sure to leave at least the first two lines intact.

So, what to do, for the linux entries, you may want to edit the /etc/grub.d/10_linux file, very carefully. You may look for the linux () function and study it's internals. The whole thing is very complex and I wouldn't touch it without a backup. You can see the output of the file just running /etc/grub.d/10_linux in your shell, then look where you want to add your special lines, edit it, execute it again and see if you are happy with the results.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.