Friday, May 25, 2007

Ubuntu - How To Edit Grub Boot Parameters

The reason that you will usually want to change boot parameters is to configure the default kernel to something specific to your hardware. Grub allows you to change a boot parameter temporarily , in which case it won't survive a system reboot, or permanently, which means that it will. When trying to fix something on your machine using kernel parameters, a reasonably safe way to proceed is to first make the changes temporarily, check that you get what you expect, and then make the change permanent.

If changing kernel boot parameters sound scary, it isn't. None of the boot parameters that I have come across are destructive in any way. The worst result could be that your machine hangs until you restart it. Even if you make the change permanently, you always still have the opportunity of intercepting the Grub boot and changing the parameter back.

1. Changing Boot Parameters Temporarily

Generally, this is used when you want to try a parameter change to see it is beneficial to your system. When the PC boots up, you will see the Grub countdown, which is set to 3 seconds by default. Press "Esc" to intercept this countdown and go enter a Grub menu. Then
  • Press 'e' to start editing.
  • Scroll down to the "kernel..." line. The is the line that tells Grub which kernel to boot with and the parameters to be passed to the kernel when it boots are placed at the end of this line.
  • Press 'e' again to edit this line.
  • Move to the end of the line. You will see any existing parameters and can add other new parameters to the end.
  • Parameters are separated by spaces and are mostly either a single word (e.g. nolapic), or an equation (e.g. acpi=off).
  • Once you have added the parameter to the end of the line, press Enter to accept the editing.
  • Then press 'b' to boot using that kernel and those parameters.

Remember, this change is not permanent. At next boot, it will be undone.

2. Making Boot Parameter Changes Permanent

Assuming that you booted with a new or changed parameter and would now like to make this a more permanent change, you need to edit the file that contains these settings. This file (/boot/grub/menu.lst) is owned by root and, therefore, requires root privileges to edit. There are a number of ways to do this depending on your editor of choice. For me
sudo vi /boot/grub/menu.lst
works. If you are not familiar with vi, then it might by something along the lines of
gksudo gedit /boot/grub/menu.lst
will edit this file in the Ubuntu gedit graphical text editor.

Now, there are two flavours of permanent to consider. The first is to make the change survive reboots, the second is to survive an upgrade.

2.1 Making a change survive reboots

Find the section shown below. The details will vary depending on which kernel(s) are installed on your machine.
## ## End Default Options ##

title Ubuntu, kernel 2.6.20-15-generic
root (hd0,0)
kernel /boot/vmlinuz-2.6.20-15-generic root=UUID=fccafcc7-d7cc-4594-9459-a8f0db7b9f7f ro quiet splash
initrd /boot/initrd.img-2.6.20-15-generic
quiet
savedefault
Add your parameters to the end of the line starting with "kernel...". This should be the same line that you would edit in the temporary change scenario above. Save the file and the change will survive a reboot.

2.2 Making a change survive upgrades

Depending on how frequently you upgrade your system, you might find that when a new kernel is installed, or grub is upgraded (there may be other scenarios), the /boot/grub/menu.lst file may be replaced by a newer version, or a new line might be added for the new kernel. In this case, your "permanent" changes might be as permanent as you thought.

The best way to address this is to change the "#kopt..." line in /boot/grub/menu.lst. Note that the line is not commented out, even though it starts with a "#". See the excerpt below.
### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below

## DO NOT UNCOMMENT THEM, Just edit them to your needs

## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specific kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
## kopt_2_6_8=root=/dev/hdc1 ro
## kopt_2_6_8_2_686=root=/dev/hdc2 ro
# kopt=root=UUID=fccafcc7-d7cc-4594-9459-a8f0db7b9f7f ro
Add the parameter changes to the end of the line "#kopt...". These parameters will then be automatically added to any new kernel entries and should also survive an upgrade of grub.

One last point: When installing Ubuntu, the very first screen you get to when booting with the install CD has an option to set boot parameters for your system. If you know ahead of time of boot parameters that need to be set to make your graphics card work, for example, then setting them here will not only make your installation much smoother, but they will also get added as default options, as in (2.2) above.

Technorati Tags: , , ,

21 comments:

mickbw said...

Is there a way to use a Grub Boot Parameter to specify that you want to run something on startup (like Apache)?

Warren Butler said...

mickbw,

I don't believe so. The Grub boot parameters are for the kernel and, therefore, for a much lower level. This is the level just above the BIOS, but not at the application level. So, the kernel has to boot first to provide the environment for applications to run.

In Linux, there are number of ways to do what you are looking for. A service like Apache should install itself to run continuously. But if there is something that you would like to start when the machine boots, there are a number of options:

1. In Ubuntu, you can set programs to start under System -> Preferences -> Sessions. Select "New" and add the command that would start the program from the command line.
2. Otherwise, you can investigate starting the application by adding a small shell file in the /etc/init.d/ directory and then linking to it from the /etc/rc2.d/ directory.

And there are some other options. It alls depends when the program needs to be started, what environment the programs needs to be running, and who needs to be able to access the application.

Cheers

Warren

ezekiel said...

Where can I find tutorials and some clear explanations regarding Grub boot parameters? (ide=noprobe, nolapic, acpi=off, etc

Warren Butler said...

This site is quite good. Also, this page at the Linux Documentation Project. Once you know which parameter you are interested in, then specifically searching on that should get the next level of detail.

Regards

Warren

Guy said...

I had to run sudo update-grub after editing the menu.lst file to get my kopt options loaded.

ravi said...

hi
m ravi sharma from msrit bangalore , yesterday i updated my ubunto but i lost my window boot loader options now only ubunto option is coming so i hav to format my window or give me suggestion as soon as possible.
lookforward_ravi_2008@hotmail.com

ravi said...

hi
m ravi sharma from msrit bangalore , yesterday i updated my ubunto but i lost my window boot loader options now only ubunto option is coming so i hav to format my window or give me suggestion as soon as possible.
lookforward_ravi_2008@hotmail.com

Warren Butler said...

ravi,

Unfortunately, I don't have any experience with dual-boot setups, so I can't be of much help here.

But I'm sure your favourite search engine will get you to where you want to be.

Regards

Warren

M Henri Day said...

Thanks for an interesting posting, Warren ! I'm running a triple-boot set-up (Windows XP Home and ditto Vista Business on one 250 GB harddisk (sda), and Feisty, which I installed from Canonical's 64-bit live CD on a second harddisk (sdb), all on an AMD 64 X2 5000+ machine. My GRUB entry for the Ubuntu in gedit (I'm running the Grub 2 beta) is as follows :

title Ubuntu, kernel 2.6.20-16-generic
root (hd1,0)
kernel /boot/vmlinuz-2.6.20-16-generic root=UUID=8da527e1-381a-4b9c-979f-65c6379afc8f ro quiet splash
initrd /boot/initrd.img-2.6.20-16-generic
quiet
savedefault

title Ubuntu, kernel 2.6.20-16-generic (recovery mode)
root (hd1,0)
kernel /boot/vmlinuz-2.6.20-16-generic root=UUID=8da527e1-381a-4b9c-979f-65c6379afc8f ro single
initrd /boot/initrd.img-2.6.20-16-generic

title Ubuntu, kernel 2.6.20-15-generic
root (hd1,0)
kernel /boot/vmlinuz-2.6.20-15-generic root=UUID=8da527e1-381a-4b9c-979f-65c6379afc8f ro quiet splash
initrd /boot/initrd.img-2.6.20-15-generic
quiet
savedefault

title Ubuntu, kernel 2.6.20-15-generic (recovery mode)
root (hd1,0)
kernel /boot/vmlinuz-2.6.20-15-generic root=UUID=8da527e1-381a-4b9c-979f-65c6379afc8f ro single
initrd /boot/initrd.img-2.6.20-15-generic

title Ubuntu, memtest86+
root (hd1,0)
kernel /boot/memtest86+.bin
quiets :

The dual kernel, 2.6.20-15 and 2.6.20-16, respectively, is due to the recent kernel update from the former to the latter in Feisty. Given that the 2.6.20-16 kernel seems to be performing perfectly, I find it difficult to conceive of a situation in which I should wish to boot to the earlier version. Can I simply remove the lines relating to 2.6.20-15 in gedit and then uninstall the related headers and images in Synaptic, or would you recommend that I leave all these parametres unchanged ? The point of removing them would be to free disk space and render my set-up less cluttered, but in fact, at present I am only using a small fraction of my resources, so this is hardly something that cries out be done immediately....

Henri

Warren Butler said...

Henri,

You might be looking for something as simple as 'sudo apt-get autoremove'. This should go through and remove any unused kernels and other files that are no longer dependencies for your system.

Regards

Warren

M Henri Day said...

Thanks, Warren for the tip ! I thought, in return, that I should give you som feedback on the results : Unfortunately «sudo apt-get autoremove» had no discernable effect on the kernels, but it did remove libotr2 pfb2t1c2pfb, thereby freeing 266kB on my system. So can it go !...

Henri

Raween said...

Thnx!
raween.nl

Rohan said...

Hi Ravi,

Try this link it should fix it;
http://www.computerhope.com/issues/ch000648.htm

If after windows issue is resolved, system boots directly to xp and u dun get all boot options follow this link and your dual setup should be perfectly fine then.

http://ubuntuforums.org/showthread.php?t=224351

Regards
Rohan (golwalkar.rohan@gmail.com)

dnew said...

I'm a Linux newbie. I've got a dual boot XP/Fedora Dell system using Grub as the boot loader. I've recently installed Ubuntu. I've edited the boot manu to allow Ubuntu as one of the boot choices, but I don't know how to configure the boot loader to actually load Ubuntu if that option is selected. I DO know which disk it is on. How do I do this?

Brenden said...

I'm using ubuntu 7.10 and everytime after i edited the lines and updated they switched back, but what I did was go to this section:

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not use 'savedefault' or your
# array will desync and will not let you boot your system.
default 0


and changed the default to 4. Which for me was the generic kernel. All you have to do is go down to your list of kernels, start counting at 0 till you get the one you want then replace it with the default. Worked like a charm for me.

M Henri Day said...

Brendan, Warren, when I scroll down to the «##default num» section, I see precisely the same thing that Brendan reported, i e :

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not use 'savedefault' or your
# array will desync and will not let you boot your system.
default 0

but, for some reason which I fail to understand, I am not allowed to change the default number from «0», when I attempt to type in a «3», in order to set up my Gutsy 2.6.22-14 kernel as default, rather than my Hardy a 6 2.6.24-12 kernel, which won't load, nothing happens. (In counting kernels, I count only the first instance of each kernel, rather than distinguishing between the «generic» and «recovery» versions of the same kernel, as per the following :

## controls how many kernels should be put into the menu.lst
## only counts the first occurence of a kernel, not the
## alternative kernel options
## e.g. howmany=all
## howmany=7
# howmany=all)

My question is, how was Brendan able to edit his «default 0» line to «default 4», while I cannot do so in my terminal ?...

M Henri Day said...

PS : The default line can, of course, be edited via the «gksudo gedit /boot/grub/menu.lst» command, but the odd thing is that when I do so and save the changes on gedit, nothing changes on the GRUB menu itself - it still wants to boot by default to the Hardy kernel, and to get it to boot to Gutsy, I have to use the arrow keys to scroll down to the 2.6.22-14-generic kernel. Go figure !...

Gagan said...

Thanks for posting valuable information.

I was having problem booting up ubuntu on my AMD64 hp tablet after installation.

Editing and saving boot parameter is now working fine for me.

I appended "irqpoll pci=noapic nolapic acpi=off" on the kernel line!

Thanks
Gagan

katya said...

Hello,
I installed Ubuntu after Windows and it won't boot. As it was almost dead already, I was trying to clean up the disk and reinstall it. But, there is no option to boot from CD in Grub. Consequently, only Super Grub CD can boot, but I don't know how to edit the .lst menu to offer boot from CD. Here is the copy of the .lst file:
# menu.lst - See: grub(8), info grub, update-grub(8)
# grub-install(8), grub-floppy(8),
# grub-md5-crypt, /usr/share/doc/grub
# and /usr/share/doc/grub-doc/.

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not change this entry to 'saved' or your
# array will desync and will not let you boot your system.
default 0

## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout 10

## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
#hiddenmenu

# Pretty colours
#color cyan/blue white/blue

## password ['--md5'] passwd
# If used in the first section of a menu file, disable all interactive editing
# control (menu entry editor and command-line) and entries protected by the
# command 'lock'
# e.g. password topsecret
# password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
# password topsecret

#
# examples
#
# title Windows 95/98/NT/2000
# root (hd0,0)
# makeactive
# chainloader +1
#
# title Linux
# root (hd0,1)
# kernel /vmlinuz root=/dev/hda2 ro
#

#
# Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST

### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below

## DO NOT UNCOMMENT THEM, Just edit them to your needs

## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specific kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
## kopt_2_6_8=root=/dev/hdc1 ro
## kopt_2_6_8_2_686=root=/dev/hdc2 ro
# kopt=root=UUID=7fd45131-277a-46a7-b01a-bc7eeaf39669 ro

## Setup crashdump menu entries
## e.g. crashdump=1
# crashdump=0

## default grub root device
## e.g. groot=(hd0,0)
# groot=(hd0,2)

## should update-grub create alternative automagic boot options
## e.g. alternative=true
## alternative=false
# alternative=true

## should update-grub lock alternative automagic boot options
## e.g. lockalternative=true
## lockalternative=false
# lockalternative=false

## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
# defoptions=quiet splash

## should update-grub lock old automagic boot options
## e.g. lockold=false
## lockold=true
# lockold=false

## Xen hypervisor options to use with the default Xen boot option
# xenhopt=

## Xen Linux kernel options to use with the default Xen boot option
# xenkopt=console=tty0

## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
## altoptions=(recovery) single
# altoptions=(recovery mode) single

## controls how many kernels should be put into the menu.lst
## only counts the first occurence of a kernel, not the
## alternative kernel options
## e.g. howmany=all
## howmany=7
# howmany=all

## should update-grub create memtest86 boot option
## e.g. memtest86=true
## memtest86=false
# memtest86=true

## should update-grub adjust the value of the default booted system
## can be true or false
# updatedefaultentry=false

## ## End Default Options ##

title Ubuntu, kernel 2.6.20-16-generic
root (hd0,2)
kernel /boot/vmlinuz-2.6.20-16-generic root=UUID=7fd45131-277a-46a7-b01a-bc7eeaf39669 ro quiet splash
initrd /boot/initrd.img-2.6.20-16-generic
quiet
savedefault

title Ubuntu, kernel 2.6.20-16-generic (recovery mode)
root (hd0,2)
kernel /boot/vmlinuz-2.6.20-16-generic root=UUID=7fd45131-277a-46a7-b01a-bc7eeaf39669 ro single
initrd /boot/initrd.img-2.6.20-16-generic

title Ubuntu, kernel 2.6.20-15-generic
root (hd0,2)
kernel /boot/vmlinuz-2.6.20-15-generic root=UUID=7fd45131-277a-46a7-b01a-bc7eeaf39669 ro quiet splash
initrd /boot/initrd.img-2.6.20-15-generic
quiet
savedefault

title Ubuntu, kernel 2.6.20-15-generic (recovery mode)
root (hd0,2)
kernel /boot/vmlinuz-2.6.20-15-generic root=UUID=7fd45131-277a-46a7-b01a-bc7eeaf39669 ro single
initrd /boot/initrd.img-2.6.20-15-generic

title Ubuntu, memtest86+
root (hd0,2)
kernel /boot/memtest86+.bin
quiet

### END DEBIAN AUTOMAGIC KERNELS LIST

# This is a divider, added to separate the menu items below from the Debian
# ones.
title Other operating systems:
root


# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/sda1
title Microsoft Windows XP dition familiale
root (hd0,0)
savedefault
makeactive
chainloader +1


Would be very grateful for any suggestions.

Good Books said...

hello katya

booting from a cd from GRUB is quite difficult, but can be done... but what YOU want is to change (at least temporarily) the boot sequence to boot from the cd-drive.
For this purpose, you have to edit the BIOS config, and this can be done by pressing F1 or F2 or Esc or... [but it should be precised in the user manual or at the bottom of the bios splash (the first screen you see at boot)...]

Anyway: find the BIOS, change the BOOT SEQUENCE, and then boot from the CD-DRIVE...

And you're on your way!

Hope that helps...

skygirl said...

good work!!thanks!happy new year!!