|GNU GRUB is a work in progress and the information in this website is incomplete and may be wrong and/or out of date. Please consult the official GNU GRUB 1.98-r2692 manual.|
The information in this page is current for GNU GRUB version 1.98~1ubuntu7 in Ubuntu Lucid Lynx.
Four Ways to Edit your grub.cfg
Custom Boot Entries
To view your /boot/grub/grub/cfg file, you might use the following command,
As the name suggests, grub.cfg is GNU GRUB's main configuration file. Changes to this file affect the appearance of our GRUB Menu, see GRUB2 Menu Mode, and also the way the operating system(s) in computer will boot.
We're not supposed to edit this file directly, as the sign at the top says.
Instead, this file will be built automatically for us by another program, and that program is called grub-mkconfig, probably that's short for grub make configuration file, and that's what it does.
The grub-mkconfig program runs other scripts and programs such as grub-mkdevice.map and grub-probe and then generates a new grub.cfg file. It also reads files in /etc/default/grub and the /etc/grub.d/debian theme file to tell it what to do. Those are the files we can edit or create for ourselves to change our GRUB settings. I'll show you more about that later.
Below here is an example of a grub.cfg for a new Ubuntu installation in a computer that already has one other Ubuntu installation dual booting with Windows XP.
I have highlighted the commented lines in yellow to draw your attention to them.
You should notice that they each mark the beginning and ending of their own section of the grub.cfg and they appear in numerical sequence starting from the /etc/grub.d/00_header at the top.
The last section of this file is the /etc/grub.d/40_custom area at the bottom of the grub.cfg file.
Each of these sections of the grub.cfg file are controlled by the scripts with the same names, and those are the ones we edit to make changes to our grub.cfg.
The changes will come into effect right after we run 'sudo grub-mkconfig -o /boot/grub/grub.cfg' to write the new grub.cfg file.
|Four Ways to Edit your grub.cfg|
1. Normal circumstances,
The easiest way to make changes to this file is to simply run sudo grub -mkconfig -o /boot/grub/grub.cfg to make a new grub.cfg file. We would want to do this after adding or removing operating systems to or from our computer. That command will run grub-mkconfig to scan your computer and update your grub.cfg file with boot entries for all of the operating systems you have in all of the discs you have plugged into your computer at that time. A list of boot entries for all of your bootable kernels in each operating system will be added to your grub.cfg.
2. Special customization
If you want to customize your /boot/grub/grub.cfg file yourself, you first need to edit /etc/default/grub and/or one of the files in /etc/grub.d and then run 'sudo grub-mkconfig'.
The 'sudo update-grub' or 'sudo grub-mkconfig' scripts will read /etc/default/grub and the files in /etc/grub.d in numerical sequence and update your /boot/grub/grub.cfg file with your changes. More on this subject will come up further down this page.
3. By another script or program
Another way to have this file edited for us will be to use scripts and programs that are currently still under development by members of the Ubuntu community. One that I have tried is called 'SUM', short for 'Start Up Manager', and it does support GRUB 2 but last time I tried it was still in the early stages of development for GRUB 2 and it didn't have very many functions enabled yet. Here's a link for more info about that, StartUpManager - Ubuntu Community Docs
4. Direct editing
If you have your GRUB 2 in a 'Dedicated GRUB 2 Partition', it's not necessarily under the control of the operating system but it is still possible to run sudo grub-mkconfig with the path to the mounted partition.
Some people still want to do things manually though, so what some people do is chmod their /boot/grub/grub.cfg to relax the file permissions on it so they can edit it manually and directly.
In this way it's possible to give our boot entires user freindly titles instead of just kernel numbers.
See How To Make a Dedicated GRUB 2 Partition - with an editable grub.cfg
Or How To Make a GRUB 2 USB Disk - with an editable grub.cfg
You can open /etc/default/grub file with the following command,
This is what it should look like,
The number at the end of this line can be changed to make the highlight bar or selection bar in the GRUB Menu appear automatically on any GRUB Menu entry we like.
0 (zero) tells GRUB we want the first or top GRUB entry automatically selected unless we over ride that selection with our up or down arrow key during boot-up.
Any number greater than 0 (zero) will mean boot entries further down the GRUB Menu will be selected instead.
Alternatively, replace the number here with the word 'saved' to enable the grub-set-default command to work.
See this thread, [ubuntu] How do I change boot order in 9.10? - Ubuntu Web Forums, especially post #14 by drs305,
TIP: Knowing how to change this setting might be useful when you want to have a particular operating system booted automatically when the computer is unattended.
For example, my ISP allows me a bandwidth of 40 GB per month during the 'off peak' hours between 01:00 and 09:00 hrs. I'm allowed another 40GB per month of bandwidth allowance for the 'peak' time period each day, which is most of the day, between 09:00 and 01:00.
I want to turn my computer off to save energy when I go to sleep, but I also want to share the latest Ubuntu .iso file I have downloaded in my computer using bittorrent.
To optimize the use of my bandwidth allowance, I want to share the file during the 'off peak' hours.
I will set my computer's BIOS to start the computer at 01:00.
There are several programs in Ubuntu that can start another program up at a preset time. Alarm Clock is one, Evolution Calendar is another and there's also the more traditional crontab. I can use any of those to run /usr/bin/transmission (start bittorrent) shortly after the time the computer is set to boot itself up. First of all though, I need the operating system containing the .iso file to be selected by default. If it doesn't happen to be the one that is first on the boot menu, I can easily to use grub-set-default to set GRUB to make sure it is selected.
Deleting the # mark will hide the GRUB Menu.
If you only have one operating system in the computer you might not need to see the menu, and you may want the timer left on 0 seconds for fast booting.
Sometimes people install Ubuntu in a computer they share with others who would be frightened and confused if they saw a GRUB Menu. If that's the case you can install Ubuntu and delete this hash mark to hide the GRUB Menu. If you set the timer to 3 seconds or so then others won't see the GRUB Menu so it won't annoy them.
The computer will still boot quickly enough, but if you press the shift key within the three second time limit you can bring up your GRUB Menu and boot Ubuntu.
When the menu is hidden, this hides the timer as well. Set it to false if you do want to display the timer.
This number sets the number of seconds we want GRUB to wait before automatically booting the default boot entry, unless any key is pressed to cancel the count-down timer.
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
!!! This line is not to be edited at all. If this line is edtied it will cause update-grub or grub-mkconfig to fail and display an error message about not being able to find whatever the name is the user put there. !!!
This line is for our standard kernel options and should be left as it is.
This is the place where we can insert any extra kernel options we may need.
Example Thread: [SOLVED] Ubuntu 9.10 And grub issue..... need help please.
Source: TWEAKING GRUB 2 - Dr.Lock
See also: Common Boot Options - Ubuntu Community Docs, and Kernel Parameters, www.kernel.org
# Uncomment to disable graphical terminal (grub-pc only)
I'm not sure about this line yet. Sorry.
# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
You can set a different resolution here, if you do so the font will appear smaller in your GRUB Menu and in your GRUB CLI mode, which may be a good thing because then you'll be able to see more of it.
If you have a splashimage, you'll be able to set a larger one if you set a higher resolution for GRUB, which usually means it will look even nicer. See How To Change Boot Menu Resolution for more information.
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
The comment above this line is sufficient to explain it.
# Uncomment to disable generation of recovery mode menu entrys
The comment above this line is sufficient to explain it.
You may open your /etc/grub.d/05_debian_theme with a command like the following,
Here's what you can expect it to look like,
You may edit this file and then run 'sudo grub-mkconfig -o /boot/grub/grub.cfg' to have the changes written persistantly to your /boot/grub/grub.cfg file.
If you have a background image, you can specify it here.
See GRUB2 Splashimages - How to make your GRUB Menu look beautiful
If you specified a background image and GRUB 2 can display it, GRUB 2 will make your menu and font colors according to what is specified in the next two lines.
You can specify any combintion of black (or transparent), dark-gray, light-gray, white, brown, yellow, red, light-red, blue, light-blue, green, light-green, cyan, light-cyan, magenta, light-magenta.
See GRUB2 Splashimages for more information.
cat << EOF
Not everybody cares about having a fancy background image. Very often just a colored menu can look just as nice, and is a little more practical since it's easier to read your text against a monocolored screen.
For a colored GRUB Menu just specify here any combintion of black (or transparent), dark-gray, light-gray, white, brown, yellow, red, light-red, blue, light-blue, green, light-green, cyan, light-cyan, magenta, light-magenta. If you don't then your GRUB Menu will just remain black and white.
|Custom Boot Entries|
You may want to add your own customized boot entries when,
The file name needs to begin with a two digits number followed by an underscore.
The numbers at the start of the file name determine where your entries will appear in your grub menu.
Numbers we can't use are numbers already occupied by existing scripts.
Existing scripts in /etc/grub.d include
Therefore we have no choice but to make our selves a new custom boot entry file with a number greater than 05 but less than 10 preceding its name. That will cause our script to be read between 05_debian theme and 10_linux, meaning our custom boot entries will be at the top of our GRUB Menus.
Several types of boot entries are popular.
The symlink boot entry
See Orientation - GRUB Legacy Page.
Link: see post #24 by phenest in the following thread, GRUB 2 Testing Question - Ubuntu Web Forums. Tested and worked for me when I tried it
A handy trick to remember all your file system UUID numbers is to copy the output from the 'sudo blkid' command and paste it to the file you're editing. I just leave mine there for future reference, but I make sure I hash them out first. Notes can be typed after them too.
The chainloader type of boot entry
We can boot another boot loader via a MBR or a Boot Sector.
In order for this to work, there needs to be some code written either in the MBR of the hard disk you want to boot or in the boot sector of the partition that points to an existing boot loader.
From there, the other boot loader will take over the booting process.
The chainloader boot entry is the second most reliable, and extremely versatile.
Tested and worked for me when I tried it
If you're trying to chainload a partition boot sector, you might need to use the -f option, which tells GRUB to ignore the fact that there might not be a bootable disc signature there, (!= 0xaa55). I'm not sure about exactly when that's needed or isn't needed yet. It seems to be only needed in CLI Mode GRUB.
The configfile boot entry.
The configfile command works beautifully well between two operating systems that both use GRUB 2, I like it. Tested and worked for me when I tried it
The configfile command can be a lot of fun, there are all kinds of inventive ways to use it.
We can also use the configfile command to direct GRUB to load another text file in our own file system, perhaps with our own customized boot entries in it. That would be another alternative way to organize our custom boot entries. It would also be a fun way to play with GRUB2. We could use the second grub.cfg for all kinds of experiments. It would need to be named something slightly different or located in a different directory to avoid overwriting our real grub.cfg file. The 'sudo grub-mkconfig' command can make grub.cfg files with the -o option with any path and file name we tell it to. See grub -mkconfig.
How To Add Custom Boot Entry and Boot an .iso File in the Hard Disk
A new kind of boot entry is the loopback boot entry for booting live CD .iso files.
This custom boot entry will boot my new Ubuntu Lucid Lynx Alpha1 .iso file, which remains in my Downloads directory where I can continue sharing it with bittorrent.
My Ubuntu Karmic Koala installation is in an SSD drive which I often remove from my computer and pop into a USB external case and carry around with me. Wherever I go I can plug the USB SSD external into a computer and boot my Ubuntu Karmic Koala installation.
With the .iso boot entry that this script adds to my Karmic Koala GRUB2 Menu, I now have the opportunity to boot the Lucid Lynx .iso file instead, and run it as a Live CD from inside my USB SSD drive.
The last time I tried I could not use an .iso file booted in this way for this for installing Ubuntu with.
See also this website's loopback (command, CLI Mode).
Here are links to two web pages giving examples of how to use the loopback command to boot .iso files containing a bootable Linux CD image when the bootable .iso is located in a hard drive,
Boot an ISO via Grub2 - Mika's Blog
MultiBoot USB with Grub2 (boot directly from iso files) - panticz , (thanks to pxwpxw for the link).
TIP: If you need to make a long line of kernel options as may be required for the .iso files of some live CDs, be sure to click 'Edit'-->'Preference' in your Gedit text editor and disable 'text wrapping', otherwise you may encounter lot of difficulties.
Tested and worked for me when I tried it
When you are finished putting all of your custom boot entries in your /etc/grub.d/06_custom file, it needs to be chmodded to make it executable,
Finally, don't forget to run either the 'sudo update-grub' or 'sudo grub-mkconfig' command.
Now you can reboot and see if it works. Good luck :)
See: memtest86+ - this website's GRUB Legacy Page
This section of the grub.cfg is under the control of our /etc/grub.d/30_os-prober and probably will not need any interferance from users.
All of our other operating systems should be automatically detected and appear in this section of our /boot/grub/grub.cfg files.
If not, check to make sure the disk is plugged in and working. If so, possibly you will need to make a custom entry for the operating systems that aren't being added automatically.
|Custom Boot Entries|
For this section of the grub.cfg, we have 31_<filename> to 39_<filename> open to us as possibilties for custom boot entries which we may want to have appearing at the bottom of our GRUB Menus, below all of our other operating system entries.
There is also /etc/grub.d/40_custom which is our designated custom boot entry file.
After that, we have 41_<filename> and greater open to us as possibilties for custom boot entries which we may want to have appearing right at the bottom of our menu.lst files.
See Custom Boot Entries for more information.