Professional Documents
Culture Documents
Updated: 9/11/09, 9/12/09, 9/20/09, 9/22/09, 9/23/09, 10/04/09, 10/6/09, 10/7/09, 10/9/09, 10/12/09 (Dual
booting, drivemap in Reply #1), 12/4/09 (edited References)
GRUB 2 Practical Reminders (a cheat sheet for those who know what they are doing)
See end of SECTION 4 Special Topics.
New:
Booting Windows XP on a non-first hard drive
See Reply #1
NEW Notes about some of the new GRUB 2 commands: See Reply #1
I have made the switch throughout the how-to (in the first post of this thread).
Note: update-grub
The command update-grub generates a new grub.cfg file and replaces the existing grub.cfg with the newly generated
grub.cfg (by default).
But, as explained next, you must specify the output file when using grub-mkconfig:
Note that
sudo grub-mkconfig
prints its output to the screen (default = stdout).
To print to the grub.cfg, use
sudo grub-mkconfig -o /boot/grub/grub.cfg
or
sudo grub-mkconfig --output=/boot/grub/grub.cfg
----------
TABLE of CONTENTS
SECTION 1
Introduction
History: GRUB Legacy, GRUB 2
Differences between GRUB Legacy and GRUB 2
GRUB 2 commands
Notes about some of the new GRUB 2 commands: See Reply #1
SECTION 2
Key Facts About the Boot menu, grub.cfg
Quick version -- Overview -- Details
/etc/grub/default --> /etc/grub.d --> /boot/grub/menu.lst
Rules for editing grub.cfg, /etc/default/grub, and the script files in /etc/grub.d
GRUB 2 device numbering is different: Partitions start at 1
Details
SECTION 4
Special Topics
Installing GRUB 2 to your PC
grub-install The most useful command
The various types of command modes.
"c," grub>, Konsole BASH, edit "e", emu
TAB Completion
How to get information about your drives and devices
At Konsole : sudo fdisk -lu
At the GRUB 2 prompt: grub> ls
Boot menu: Adding or removing an OS entry
Boot menu: Create a custom boot entry
Boot menu: Making your own custom grub.cfg
Boot menu: Changing resolution, text colors, setting background image
4 ways to boot an OS: configfile, symlinks, direct booting, chainloader
Boot menu: Background image editing tip for those with widescreen monitors
Dedicated GRUB 2 partition: How to build it
GRUB 2 Flashdrive: How to build it
Use of the term "root"
GRUB's Root Device, the Linux statement: root=UUID=,
--root-directory=DIR INSTALL_DEVICE
Dual booting: See Reply #1
Booting XP on a non-first hard drive (drivemap): See Reply #1
Appendix: Techniques
--- Installing Kubuntu--GRUB 2 placement
--- Working as root, editing a file
--- Permissions: read, write, execute; change the execute bit
--- Chroot -- how to
See also REPLY #1 below this post for more GRUB 2 topics:
Notes about some of the new GRUB 2 commands
Included: chainloader, ls, grub-emu, grub-mkconfig (many tips!), root, rootnoverify (is gone), grub-setup
grub-install: See SECTION 4 above.
drivemap: See Reply #17 below; See Reply #1
loopback: See Boot From ISO (below)
= = = = = = = = = = = = = = = = = = = =
SECTION 1
Introduction
History: GRUB Legacy, GRUB 2
Differences between GRUB Legacy and GRUB 2
GRUB 2 commands
Notes about some of the new GRUB 2 commands: See Reply #1
The original GRUB (GRand Unified Bootloader) was developed by Erich Stefan Boleyn, from which came the GRUB
most of us know, GRUB version 0.9x, and that is now referred to as GRUB Legacy (or even GRUB 1 by some writers).
GRUB 2 replaces GRUB Legacy. (GRUB 2 is actually the end result of versions GRUB 1.xx; e.g., 1,96, 1.97, ...)
GRUB 2 is cleaner, more efficient, powerful, and more elegant, in many ways it is simpler to use than GRUB Legacy.
GRUB 2: http://www.gnu.org/software/grub/grub-2.en.html
Its mailing list for development,
GRUB-devel: http://lists.gnu.org/mailman/listinfo/grub-devel
And the Wiki: http://grub.enbug.org/
GRUB 2 is the default bootloader in 9.10
https://lists.ubuntu.com/archives/ubuntu-devel-announce/2009-June/000573.html
From the user's view, the biggest difference between the two versions of GRUB concerns the boot menu
configuration file.
GRUB 2: /boot/grub/grub.cfg
GRUB Legacy: /boot/grub/menu.lst
The configuration file is used to generate the boot menu you see at boot time.
In GRUB Legacy, you can edit menu.lst directly and in any way you wish.
In GRUB 2, you should not edit grub.cfg directly. Instead, you edit the file /etc/default/grub (which contains some
default settings); this file feeds data to scripts in the folder /etc/grub.d. And you may edit the scripts (text files) in
the folder /etc/grub.d; these scripts are used to generate the configuration file /boot/grub/grub.cfg. When you
need a new grub.cfg, simply do sudo grub-mkconfig -o /boot/grub/grub.cfg.
The configuration file in GRUB 2 grub.cfg looks different than the GRUB Legacy menu.lst. For example, in GRUB
legacy, you use
default 0
timeout 5
In GRUB 2, default and timeout are variables, and it is
set default=0
set timeout=5
Note how the title line is changed in GRUB 2: Use menuentry instead, put the text in quotes, and start the boot
entry with a left brace {, ending it with a right brace }. Instead of kernel, the word linux is used; initrd is the same.
Instead of root=, in GRUB 2 it is set root= (in GRUB 2, root is a variable).
Device names have changed. In GRUB Legacy, the numbering of both hard drives and partitions start at zero.
(hd0,0) is the first hard drive (hd0), the first partition (partition zero). In GRUB 2, the numbering of hard drives also
starts at zero: hd0 is the first hard drive. But partition numbering starts at 1: (hd0,1) is the first hard drive, the first
partition (partition one).
In GRUB Legacy, we use the find command; e.g., grub>find /boot/grub/menu.lst. In GRUB 2, the search command
replaces the find command: grub>search /boot/grub/grub.cfg.
In GRUB Legacy, the geometry command (at the grub> prompt) is very useful for listing devices as GRUB sees them
on your PC. It is not used in GRUB 2. Instead the list command ls (at the grub> prompt) replaces the geometry
command.
GRUB Legacy uses stages: stage_1, stage_1.5, and stage_2. Those are replaced in GRUB 2 by boot.img (a 512-byte
file that corresponds to stage_1 and is installed to a MBR); there is no stage_1.5 in GRUB 2; and core.img in GRUB 2
takes the place of stage_2 (or, perhaps, of both stage 1.5 and stage_2). Details: See Section 4 the subsection "grub-
install: A key command."
= = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = =
SECTION 2 Key Facts About the Boot menu, grub.cfg
Quick version:
/etc/grub/default --> /etc/grub.d --> /boot/grub/menu.lst
Rules:
-- The file /boot/grub/grub/cfg generates the boot menu.
-- Do not directly edit /boot/grub/grub/cfg.
-- You may edit (as root) /etc/default/grub.
(timeout, default OS, kernel options, resolution of the boot menu)
-- You may edit (as root) the scripts in /etc/grub.d.
-- Together, /etc/default/grub and the scripts in /etc/grub.d generate /boot/grub/grub.cfg.
-- To create a script, start with a text file as root: kdesudo kate
-- To make filename executable: sudo chmod 744 /etc/grub.d/filename
or, sudo chmod +x /etc/grub.d/filename
-- To remove execute permission from filename: sudo chmod -x /etc/grub.d/filename
-- To open Konqueror (Dolphin) as root: kdesudo konqueror
-- Generate a new configuration file /boot/grub/grub.cfg after editing /etc/default/grub and after editing, creating,
or deleting scripts in /etc/grub.d, as follows:
sudo grub-mkconfig -o /boot/grub/grub.cfg
Examples of grub.cfg
http://svn.savannah.gnu.org/viewvc/trunk/grub2/docs/grub.cfg?root=grub&view=markup
Or: /usr/share/doc/grub-pc/examples/grub.cfg.
Also: http://grub.enbug.org/grub.cfg
Also: GRUB 2 Basics http://ubuntuforums.org/showthread.php?t=1195275
Details
The configuration file is called /boot/grub/grub.cfg, and it generates the boot menu you see on your screen when
you boot your PC (and so, /boot/grub/grub.cfg can be called the boot menu configuration file). You are NOT
supposed to edit it (it is read-only). It is generated from a folder of scripts called /etc/grub.d. Another key file is
/etc/grub/default and it feeds default data to the scripts in /etc/grub.d. You may edit /etc/grub/default (as root).
You may also edit the scripts in /etc/grub.d (as root). If you create a new file in /etc/grub.d, you must make it
executable if you want the entry included in the configuration file grub.cfg. If you do not want a script to execute
(and so remove that entry from grub.cfg), you must remove the execute bit (i.e., remove the execute permission).
You may edit the script files (as root) or create new ones. To create a new entry in grub.cfg, you simply create a new
script file: a text file that you make executable (like a program). To remove an entry from grub.cfg, remove the
execute permission from the corresponding script file in /etc/grub.d. (If the entry corresponds to a custom script
you wrote, you may also delete that script file from /etc/grub.d).
See SECTION 4 Special Topics -- Create a custom boot entry.
Quick reference
The (standard) files in /etc/grub.d (each is a script) are:
00_header
05_debian_theme: Set background, text colors, themes
10_hurd Locates Hurd kernels
10_linux Locates Linux kernels based on results of the lsb_release command.
The target are kernels located on the same partition as the root partition
of the current OS you are in (where this grub.cfg is located).
In contrast to: 30_os-prober (see below)
20_memtest86+: If the file /boot/memtest86+.bin exists, it is included in the boot menu.
30_os-prober: Searches for Linux and other OS's on all partitions; includes them in the boot menu.
40_custom: A template for adding custom boot menu entries.
See Appendix: permissions, working as root, making a file executable, Konsole, and other topics.
= = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = =
SECTION 3 Fixing Things
A checklist of things to try to fix a broken system
A Troubleshooting Outline
Ctrl+Alt+Del will reboot your PC
Super Grub Disk: Very Important
Key commands: grub-mkconfig and sudo grub-install
Timeout & Default OS, changing
Kernel options, changing
To see or to hide the boot menu
Missing OS entry in the boot menu
Editing the boot menu during booting: "e" key
The GRUB prompt grub> -- What to do with it
=> Getting information and booting an OS
Re-installing GRUB 2 using Live CD: A Key rescure method
Using a Live CD to edit files in your OS
Troubleshooting Outline
When you can't boot into your OS, there are two possible causes:
the boot menu is flawed, and/or
the GRUB 2 installation is flawed.
Now let's look at each of your two choices for fixing the problem.
--> How to boot into your OS when you can't seem to boot into your OS:
(1) SGD, or (2) use the grub>, or (3) use the "e" key.
Some tips and details:
> Use Super Grub Disk to boot into it. You may have SGD fix the boot (under GNU/Linux options), or simply use SGD
to boot the OS so you can get into it. If you use SGD to fix the boot, it will re-install GRUB to your drive, so make sure
that's what you want; also, it may do so using either GRUB Legacy or GRUB 2, depending on the SGD CD version you
are using. Of course, if you can get booted into the OS, then you can fix anything and everything, so maybe you
won't be feeling too picky at this point.
Note: Along these lines, you can also use your own GRUB 2 disk/flashdrive to boot your OS, if you built one.
> Boot into your OS yourself, manually, using the GRUB 2 prompt, grub>, ASSUMING you can get the prompt!
(Sometimes, you can't.) See the Subsection below titled "The GRUB prompt grub> -- What to do with it."
> Boot into your OS yourself by fixing the boot menu (editing it "on-the-fly" using the "e" key when you see it on the
screen). But sometimes, you don't see the boot menu. See the Subsection below titled "Editing the boot menu
during booting: 'e' key" If you are successful, since these "e" edits are only temporary, after booting into the OS, you
must make the changes permanent (by editing /etc/default/grub or the script(s) in /etc/grub.d and then generate a
new grub.cfg using grub-mkconfig -o /boot/grub/grub.cfg.
> Fix the problem from another Linux OS, ASSUMING you are able to boot into one!
From there, you can edit files in your broken OS and/or re-install GRUB 2 using grub-install.
(NOTE: From the second OS, or even from a Live CD, you'd have to mount the broken OS partition; or perhaps
looking in your file manager you'd see it is automatically mounted for you.)
grub-mkconfig
will generate a new boot menu /boot/grub/grub.cfg. To do so, it uses /etc/default/grub and the scripts in
/etc/grub.d. You should run this command after editing the default file or the scripts:
sudo grub-mkconfig -o /boot/grub/grub.cfg
or
sudo grub-mkconfig --output= /boot/grub/grub.cfg
See Reply #1 (to this post): Notes about some of the new GRUB 2 commands
Troubleshooting
-- After running grub-mkconfig, make sure that the line set default=(hdx,y) is correct (i.e., that the order of the
menuentries did not change the default OS position).
-- sudo grub-install --recheck [INSTALL_DEVICE]
=> If you get an error running sudo grub-install, try it again with sudo grub-install --recheck [INSTALL_DEVICE].
Example
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DEFAULT=0 selects boot entry #0 (i.e., the first entry) as the default OS to be booted automatically. Boot
entries can be seen in your /boot/grub/grub.cfg file; they start with a line
menuentry "some descriptive text" {
and end with
}
Boot entries are counted from zero; so the first menuentry is boot entry #0, the second menuentry is boot entry #1,
etc.
With the # sign present, you will see the boot menu upon booting your PC.
With the # removed, you will not see the boot menu.
Editing the boot menu during booting using the "e" key
When you boot/re-boot your PC, the boot menu appears. If you select an entry (an OS to boot into) and get an
error, and if you are able to return to the boot menu (or re-boot again to get it), you may be able to fix things or to
experiment with your boot menu to see if something will work. See the help tips at the bottom of the boot menu.
At the boot menu, highlight an entry, press the "e" key, and you'll see the menuentry statements for that OS. See
the help tips at the bottom of that menu. If you highlight a line, press the "e" key, that line will be displayed so you
can edit it (using arrow keys, delete, etc.). Pressing ESC returns you to the previous screen.
The edits you make to the boot menu are "on-the-fly" edits and are not permanent. To make them permanent,
you'll have to edit /etc/default/grub and/or the script files in /etc/grub.d, perhaps even making a custom boot entry
if necessary (SECTION 4 Special Topics Boot menu: Create a custom boot entry), then generate a new
/boot/grub/grub.cfg file using grub-mkconfig.
> "c" key: You re-boot and upon seeing the boot menu, press the "c" key to get the grub>. (Or Control+c at the
Edit mode menu.) (By pressing the ESC key, you get back to the boot menu.)
Or:
> No boot menu! Perhaps, you re-booted your PC and didn't see any boot menu but instead got dropped to the
GRUB 2 prompt: grub>.
Or:
> You get a grub> when re-booting using your own GRUB 2 flash drive (which is what is usually supposed to
happen!).
grub>
Use the ls command to see how GRUB 2 sees your drives and partitions:
grub>ls
From the output, you may decide to use ls again, this time listing files in certain directories.
For example, to investigate (hd0,8), you can list the files under the root directory of (hd0,8), like this:
grub>set root=(hd0,8)
grub>ls /
And then to see the kernel(s) under /boot,
grub>ls /boot
Or, if you do
grub>ls (hd0,8)
you'll get the filesystem type and UUID.
Another way to see what's under the root:
grub> ls (hd0,8)/
(note the slash, no spaces)
Suppose you see or confirm that the OS you want to boot is on (hd0,8) (= sda8).
Then, you might try to boot that OS using symlinks like this:
grub>set root=(hd0,8)
grub>linux /vmlinuz root=/dev/sda8 ro quiet splash
grub>initrd /initrd.img
grub>boot
But what if you can't remember the kernel options ro quiet splash ?
Then this way will also work:
grub>set root=(hd0,8)
grub>linux /vmlinuz root=/dev/sda8
grub>initrd /initrd.img
grub>boot
(The read-only option, ro, is important, but it is a default option if not specified directly. Thanks goes to dibl for this
information.)
Example Chainloader
Suppose you had previously installed GRUB 2 to the boot sector of the (hd0,8) partition containing your OS. (You
would have done that using sudo grub-install /dev/sda8) Then you may boot that OS using chainloader as follows:
grub>set root=(hd0,8)
grub>chainloader +1
grub>boot
Or,
grub>chainloader (hd0,8)+1
grub>boot
(NOTE about using the boot command When booting at the grub> prompt, you must use the boot command to
make it go. However, in the configuration file /boot/grub/grub.cfg, you do NOT need to use the boot command--it is
implied there.)
Re-installing GRUB 2 using Live CD: Key Rescue Method
There are two main ways of doing this: By chrooting into the broken partition and by not chrooting. For the
chrooting way, see GRUB 2 Live CD Install Guide: http://grub.enbug.org/Grub2LiveCdInstallGuide For details about
chrooting, see the Appendix in the first post (above).
For "my" way, I'll call "Method 1," of re-installing GRUB2 from a live CD, read on.
Your Kubuntu Live CD contains GRUB 2 files; specifically, in a live session, you will find the master GRUB 2 "image"
files in /usr/lib/grub/i386-pc. Thus, they can be used to install or re-install GRUB 2. Here's how ...
[End of Method 1]
----------
Using a Live CD to edit files in your OS
This is done as you would normally do it. Of course, if you wish, you may use Super Grub Disk to boot into your OS
and do the editing from there. Here is an outline of a standard way to use your Kubuntu Live CD.
Boot the Live Kubuntu CD, open Konsole, then as root make a directory, mount the filesystem containing the file you
need to edit, open that file (possibly as root), edit it, save, quit, unmount the filesystem, exit.
Example
If the file you need to edit is called file_name and is on sdb3 (=(hd1,3)), start a Live CD Kubuntu session, open
Konsole:
sudo fdisk -lu # to see/check your partitions, if necessary
Make a directory called /media/sdb3:
sudo mkdir /media/sdb3
Mount device sdb3 on directory /media/sdb3:
sudo mount /dev/sdb3 /media/sdb3
Change to that directory:
cd /media/sdb3
Then you may proceed in various ways:
Open Konqueror/Dolphin as root, then open the file_name:
in 8.10 or later: kdesudo konqueror (or dolphin)
in 8.04: kdesu konqueror (dolphin)
Make your edits, then File > Save, File > Quit.
Or, open file_name as root using Kate, then do the edits:
in 8.10 or later: kdesudo kate /path_to file_name
in 8.04: kdesu kate /path_to file_name
Make your edits, then File > Save, File > Quit
Unmount the directory; note the spelling of umount:
sudo umount /media/sdb3
= = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = =
SECTION 4
Special Topics
Installing GRUB 2 to your PC
grub-install The most useful command
The various types of command modes.
"c," grub>, Konsole BASH, edit "e", emu
TAB Completion
How to get information about your drives and devices
At Konsole : sudo fdisk -lu
At the GRUB 2 prompt: grub> ls
Boot menu: Adding or removing an OS entry
Boot menu: Create a custom boot entry
Boot menu: Making your own custom grub.cfg
Boot menu: Changing resolution, text colors, setting background image
4 ways to boot an OS: configfile, symlinks, direct booting, chainloader
Dedicated GRUB 2 partition: How to build it
GRUB 2 Flashdrive: How to build it
Use of the term "root"
GRUB's Root Device, the Linux statement: root=UUID=,
--root-directory=DIR INSTALL_DEVICE
Dual booting: How to set it up
Booting XP on a non-first hard drive: The drivemap command in GRUB 2
To install GRUB 2 to your PC so it boots your PC into your OSs, two steps are required.
1 You need to get the GRUB 2 files installed to your PC, somewhere in the Kubuntu filesystem.
2 Then use those GRUB 2 files to install GRUB 2 to your PC's drives or devices so it can serve as a bootloader to boot
your PC into your Kubuntu and your other OSs.
Check it: Open your file manager (Konqueror or Dolphin or other), and see the GRUB 2 files under
/usr/lib/grub/i386-pc (called the GRUB 2 image directory, and contains a set of "master" GRUB files).
To install GRUB 2 files to your PC, open Konsole and run the commands
sudo apt-get update
sudo apt-cache search grub-pc
(returns: grub-pc - GRand Unified Bootloader, version 2 (PC/BIOS version))
sudo apt-get install grub-pc
Then, install GRUB 2 to the Master Boot Record of your first BIOS boot drive. For example, if that MBR is sda, the
command would be
sudo grub-install /dev/sda
And then update grub.cfg:
sudo grub-mkconfig -o /boot/grub/grub.cfg
Reboot to see what happens.
The old GRUB may also still be there (in which case you saw an entry on the boot menu to chainload into GRUB 2), in
which case you may run
sudo update-from-grub-legacy
to replace GRUB Legacy with GRUB 2 IF YOU WISH TO DO SO.
Troubleshooting
Installing GRUB 2 to the MBR: using --recheck
Example
sudo grub-install /dev/sda
grub-probe: error: cannot find a GRUB drive for /dev/sda.
Auto-detection of a filesystem module failed.
Please specify the module with the option `--modules' explicitly.
So, try this:
sudo grub-install --recheck /dev/sda
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.
(hd0) /dev/sda
-----
[Start subsection]
grub-install The most useful command
Examples:
INSTALL_DEVICE may be /dev/sda, /dev/sda1, hd0, hd1, etc.
grub-install /dev/sda installs GRUB 2 to the MBR of drive sda.
grub-install /dev/sda1 installs GRUB 2 to the boot sector of partition sda1.
grub-install hd0 installs GRUB 2 to the MBR of drive hd0.
grub-install --root-directory=/media/sdb1 /dev/sda
sets up GRUB 2 files in the mounted partition /media/sdb1
and then installs GRUB 2 to the MBR of drive sda using /media/sdb1/boot/grub files.
(If there is no /boot/grub directory in sdb1, it will be created and filled with GRUB 2 files.)
grub-install --recheck --root-directory=/media/sdb1 /dev/sda
Do it again, and probe the /boot/grub/device.map (again).
A master script
grub-install is a master script, called a utility, that invokes many other utilities (scripts) to help do its work. You issue
this command at Konsole (Terminal) as root (using sudo). It does everything for you; it's a master fix-it-all command.
/usr/lib/grub/i386-pc
The master set of GRUB 2 files in your OS are kept in the GRUB 2 image directory /usr/lib/grub/i386-pc. They get
there when you install GRUB 2 to your PC (or OS) using your package manager or using (sudo) apt-get install grub-pc.
> The command sudo grub-install copies the GRUB 2 files from /usr/lib/grub/i386-pc to the directory /boot/grub. If
/boot/grub does not yet exist, it is created.
> It probes your partition type and partitions (using grub-probe).
> It builds a custom version of core.img for your setup, one of two very important files (along with boot.img). (In
GRUB LEGACY terms,, boot.img corresponds to stage_1 and core.img to stage_2.)
> Finally it installs GRUB 2 to your PC so it can boot some OS(s) for you. (It uses grub-setup to do this, setting
boot.img in the MBR of your first BIOS boot drive and installs core.img either after the MBR or to a file system (e.g.,
your OS partition boot sector). See the note below for a few details.)
--recheck
If your grub-install command fails, complaining about a filesystem or not finding something, try it again with the
option --recheck; like this example:
sudo grub-install --recheck --root-directory=/media/sdb1 /dev/sda
--root-directory=DIR
Very useful. Instead of setting up your GRUB files in /boot/grub under the root directory of your OS, you can use this
option to build a /boot/grub directory anywhere, and then use those GRUB 2 files to install GRUB 2 to a hard drive
MBR, or to a partition boot sector, or elsewhere (e.g., USB drive or dedicated GRUB 2 partition).
DIR is a directory, and so it is mounted. Thus, if using partition sdb1, for example, you must mount it, as say,
/media/sdb1, and then it would be: --root-directory=/media/sdb1.
When working with GRUB, you must work with root privileges and so you must use sudo and kdesudo. For example,
sudo grub-install /dev/sda, kdesudo konqueror, etc.
The command modes you may use in GRUB 2 are the following.
-- Konsole (BASH), in Kubuntu, at your regular prompt (as root), ~#:
-- GRUB 2 emu (from Konsole, issue sudo grub-emu [OPTION]; this gives you a grub> prompt)
=>TODO: More on this later.
-- GRUB 2 command line interface (CLI), grub>.
When you re-boot your PC, get the boot menu, and press the "c" key, you get a GRUB 2 prompt, grub>. That is the
GRUB 2 CLI. You will also get "grub>" upon re-booting if you don't have a boot menu, grub.cfg, or if your boot menu
is broken. (See SECTION 3, the subsection titled "The GRUB prompt grub> -- What to do with it")
-- Edit mode. Editing on the fly: when you re-boot and see your GRUB 2 boot menu, you can use the "e" key to edit
your boot menu on a temporary basis (the edits are not permanent unless you later make them so). (See SECTION 3
-- Editing the boot menu during booting: "e" key.)
=> In all cases, help is nearby, and the commands are generally the same (or nearly so) in all modes, with a few
differences.
Help
Konsole BASH CLI:
Appending --help to a command in CLI; for example: grub-mkconfig --help.
GRUB CLI (grub>):
At the GRUB 2 prompt simply type help and press Enter.
To get help with a command, type help <command name>.
Example: grub>help ls tells you about the command ls.
Edit mode:
The key tips are at the bottom of the screen after your press "e"
to enter the edit mode from your on-screen boot menu.
Also, at that point, you can press Control+c to get a grub>,
then type help and/or use TAB completion.
-----
How to get information about your drives, devices, and files
Key: at Konsole sudo fdisk -lu; and grub> ls
We'll look at two cases: At the command line in Kubuntu (Konsole); and at the grub> prompt.
-- Adding or removing OSs from your PC. After doing so,
generate a new grub.cfg: sudo grub-mkconfig -o /boot/grub/grub.cfg.
-- Add a boot menu entry by making your own custom boot entry, then run:
sudo grub-mkconfig -o /boot/grub/grub.cfg
to generate a new grub.cfg.
(See subsection below: "Boot menu: Create a custom boot entry")
Troubleshooting: Sometimes when you run grub-install or grub-mkconfig, it will fail to detect one of your OSs and
excludes it from the boot menu grub.cfg. In that case, you could make a custom entry for it (as a script file in
/etc/grub.d).
Direct booting To get a model for some of the entries, you have two choices: (1) Get it from your old boot menu
(/boot/grub/menu.lst) from GRUB Legacy (if that is available on your PC). Or, it may also be here, made by GRUB 2:
menu.lst_backup_by_grub2_postinst. (2) Go into the operating system itself (the one you wish to include), or
perhaps access its filesystem using a live CD, and get the information from its own boot menu.
Example
Making a custom entry for sidux. Method: Direct booting.
It helps if you have a model for some of the entries. In the old boot menu (/boot/grub/menu.lst) from my GRUB
Legacy, I had this boot entry for sidux:
Using a template (e.g., /etc/grub.d/40_custom), create an executable file for the sidux boot entry:
Open an empty text document (as root)
kdesudo kate
Save the new file as, say, /etc/grub.d/41_sidux_sda3
Copy the kernel & initrd lines from menu.lst, change “kernel” to “linux,” adjust the sidux partition number to
conform to GRUB 2 convention:
Legacy GRUB: (hd0,2)
GRUB 2: (hd0,3)
Also, double check the UUID for sda3 by running sudo blkid.
Result:
The file /etc/grub.d/41_sidux_sda3 looks like this:
#!/bin/sh
The echo statement causes a line to be printed to the screen after executing grub-mkconfig that says “sidux on
sda3” so you can see it got done (i.e., that sidux got incorporated into the grub.cfg).
To incorporate the sidux file 41_sidux_sda3 as a boot entry in the boot menu configuration file /boot/grub/grub.cfg,
run
sudo grub-mkconfig -o /boot/grub/grub.cfg
Check that sidux is in your boot menu by opening /boot/grub/grub.cfg.
Boot menu: Making your own custom grub.cfg
This is easy. (For another example, see the subsection below "Dedicated GRUB 2 partition: How to build it.")
Taken directly from drs305 excellent, detailed guide, GRUB 2 Basics:
http://ubuntuforums.org/showthread.php?t=1195275
Building a Totally Customized Menu: Ok, admit you are a control freak and you want to see only what you build
yourself - customized titles, no "memtest86+" and no extra kernels. Here is how you do it:
-- Run sudo update-grub [or use grub-mkconfig] to get the current available kernels.
-- Copy the desired "menuentry" listings from /boot/grub/grub.cfg to /etc/grub.d/40_custom The entry begins with
the line starting with "menuentry" and ends with a line containing "}".
-- Add any other "menuentry" items you wish to see on the boot menu.
-- Edit the titles of the "menuentry" line if desired (between the quotation symbols). Do not change the lines
following the "menuentry" line. Each entry should start with a "menuentry" line and end with a "}" on the last line.
-- Remove the executable bit from /etc/grub.d/10_linux, /etc/grub.d/20_memtest86+ and /etc/grub.d/30_os-prober
Removing the executable bit from any file in /etc/grub.d will exclude the file from being included in GRUB updates.
To do it:
sudo chmod -x /etc/grub.d/grub.d/10_linux /etc/grub.d/20_memtest86+ /etc/grub.d/30_os-prober
-- Run "sudo update-grub" [sudo grub-mkconfig -o /boot/grub/grub.cfg]
-- The updated /boot/grub/grub.cfg file should now contain only sections for "00_header", "05_debian_theme" and
"40_custom".
-- The grub.cfg file will not be updated with the addition of a new kernel. To add a new kernel, make
"10_linux" executable, run "sudo update-grub" [sudo grub-mkconfig -o /boot/grub/grub.cfg] to refresh the available
kernels, and repeat these instructions.
Boot menu: Background image editing tip for those with widescreen monitors
See Oceanwatcher, Reply #36 below
4 Ways To Boot an OS
configfile, symlinks, direct booting, chainloader
NOTE: These are done the same as in GRUB Legacy but with a new format.
But see the note on configfile below.
That tells your GRUB 2 to access partition (hd1,2), find the file /boot/grub/grub.cfg, show you that file so you can
make a choice of which OS to boot, then boot the OS you choose. The GRUB doing the work is your native GRUB,
the one you are using, not the GRUB in (hd1,2). Your native GRUB must be able to interpret the commands it finds in
the grub.cfg of the OS you wish to boot.
ls -a -l /
lrwxrwxrwx 1 root root 33 2009-08-02 11:01 initrd.img -> boot/initrd.img-2.6.24-24-generic
lrwxrwxrwx 1 root root 33 2009-04-19 17:14 initrd.img.old -> boot/initrd.img-2.6.24-23-generic
lrwxrwxrwx 1 root root 30 2009-08-02 11:01 vmlinuz -> boot/vmlinuz-2.6.24-2 4-generic
lrwxrwxrwx 1 root root 30 2009-04-19 17:14 vmlinuz.old -> boot/vmlinuz-2.6.24-23-generic
The symlink for the kernel is vmlinuz, and vmlinuz points at the NEWEST kernel.
The symlink for the initrd is initrd.img, and initrd.img points at the NEWEST initrd.
NOTE: The "l" at the left indicates "link." Note how the links point at their target files following the symbol ->. Note
that the symlinks are stored in your OS at the root level.
NOTE: If you wish to make a boot entry for the older kernel and initrd, you must use the symlinks for them,
vmlinuz.old and initrd.img.old.
If you use direct booting, you have to write out the exact kernel and initrd names:
linux /boot/vmlinuz-2.6.24-24-generic root=UUID= vb687f89-ggjd-6ach-7755-77241i4b4fk3 ro quiet splash
initrd /boot/initrd.img-2.6.24-24-generic
With symlinks, vmlinuz starts at root and points at vmlinuz-2.6.24-24-generic and initrd.img starts at root and
points at initrd.img-2.6.24-24-generic, so you can write more simply,
linux /vmlinuz root=UUID= vb687f89-ggjd-6ach-7755-77241i4b4fk3 ro quiet splash
initrd /initrd.img
However, to simplify this when you are in an emergency trying to boot at the GRUB prompt (grub>), do it this way:
Suppose this OS is Kubuntu 9.10 in (hd0,8) = sda8. Then you'd have
or even simpler, when you can't remember the kernel options "ro quiet splash":
(ro = Read-Only and is the default. Thanks to dibl for this information.)
Another Example
Example
NOTE: For this to work, a bootloader must first be installed to the target MBR or a partition boot sector.
A Linux example
"chainloader +1" says to go to sector 1 (of (hd1,7)) and turn control over to the bootloader found there.
For this example to work, a bootloader (e.g., GRUB 2) must be installed to the partition (hd1,7).
To install GRUB 2 to the boot sector of partition sdb7 (=(hd1,7)):
sudo grub-install /dev/sdb7
If a bootloader (e.g., GRUB 2) has been installed to the Master Boot Record of drive sdc (= hd2), the menuentry will
boot that hard drive by turning control over to the bootloader in its MBR.
For this example to work, a bootloader (e.g., GRUB 2) must be installed to the Master Boot Record of drive sdc (=
hd2). To install GRUB 2 to the Master Boot Record of drive sdc:
sudo grub-install /dev/sdc
Example
Windows XP on sda1
menuentry “Windows XP on sda1, by chainloader” {
set root=(hd0,1)
chainloader +1
}
2 Create grub.cfg.
In your home directory, create a text file called grub.cfg and build your custom boot menu for the dedicated GRUB 2
partition. (For a sample, see below.)
(To create the text file, two ways: (1) Right-click on your Desktop, Create New > Text File; or (2) open text editor
Kate to an empty document by typing at Konsole kate and save it under the name grub.cfg in your home directory
only! To do this as root, use kdesudo kate, but that is not necessary at this point.)
Caution: You may want to completely build your boot menu now and have it ready to go. To make your boot entries
in your grub.cfg, see the subsection above "4 Ways To Boot an OS."
4 As root, copy your grub.cfg from your home directory to the GRUB 2 partition under the folder /boot/grub. (To
do this in GUI, open your file manager as root and work from there; e.g., kdesudo konqueror or kdesudo dolphin.)
5 Set the boot flag on your dedicated GRUB 2 partition and re-boot to test it.
# grub.cfg
# This is my custom boot menu, called /boot/grub/grub.cfg, located in my dedicated Grub 2 partition sda1.
For the principles of installing GRUB 2, see the discussion under "Installing GRUB 2" and "The grub-install
Command."
Example
(This is the device.map on the flash drive, /boot/grub/device.map. I will ignore this! Doesn't matter too much. You
could edit it as root to read
(hd0) /dev/sda
as seen from the point of view of the flash drive when it is used as a boot drive.)
Let's move on, now ...
Check to see that /boot/grub is created and filled with GRUB 2 files.
Reboot, setting BIOS to boot from the flash drive (USB booting).
The next thing I saw on the screen was:
grub>
I used the GRUB 2 command ls to see my drives and partitions (on the PC):
grub>ls
Since the PC booted from the flash drive, it was seen as hd0 with partition (hd0,1). (The drive that the PC actually
boots from is always seen during its booting session as hd0--this is a general fact.)
My regular HDD, normally seen as hd0 was now seen as hd1 and my Kubuntu 9.10 was in (hd1,8).
So, to boot into Kubuntu, I did
grub>chainloader (hd1,8)+1
grub>boot
NOTE:
Previously I had already installed GRUB 2 to the partition boot sector of Kubuntu in case I ever needed to chainload
into it. (I used at Konsole in Kubuntu, sudo grub-install /dev/sda8, where sda8 is my Kubuntu partition when there is
no other drive attached to the PC.) Had I not already done this, I could could NOT chainload into Kubuntu and would
have to boot into Kubuntu in some other way, for example using symlinks:
grub>ls
would show me that Kubuntu is on (hd1,8) when booting from my GRUB 2 flash drive, and so to boot it, I'd do:
grub>set root=(hd1,8)
grub>linux /vmlinuz root=/dev/sda8
grub>initrd /initrd.img
grub>boot
Or, you could do this (if you remembered how!):
grub>set root=(hd1,8)
grub>linux /vmlinuz root=/dev/sda8 ro quite splash
grub>initrd /initrd.img
grub>boot
Technical Note: To do so, you will probably have to work as root, say by opening Konqueror or Dolphin as root
(kdesudo konqueror), or by opening Kate as root (kdesudo kate). However, you do not necessarily need a grub.cfg
on the flash drive. You can simply use it as I did to explore your drives and then boot into an OS. If you do build a
grub.cfg for it, you might include the OS(s) on your hard drive(s), and use the GRUB 2 flash drive to boot in
emergencies, as you would use Super Grub Disk. Just remember that from the point of view of the grub.cfg on your
flash drive, the other drives in your PC are shifted by 1 since upon booting the flash drive, it will be seen as hd0. If
adrian15 builds Super Grub Disk for GRUB 2 and includes his usbshift function, then the story changes--for the
principle of "USB drive shifting," see my how on building a GRUB flash drive:
-- How To Make GRUB Thumb Drive
http://kubuntuforums.net/forums/index.php?topic=3081748.0
Example
Consider this menuentry:
### BEGIN /etc/grub.d/10_Linux ###
menuentry "Ubuntu 8.04.3 LTS, kernel 2.6.24-24-generic" {
set root=(hd1,2)
linux /boot/vmlinuz-2.6.24-24-generic root=UUID=0df17bc5-0056-4ef7-bfca-251194b6eb44 ro quiet splash
initrd /boot/initrd.img-2.6.24-24-generic
}
The line
set root=(hd1,2)
sets the GRUB root device. The GRUB root device is the partition containing the kernel vmlinuz and initrd files. Thus,
it is the partition containing the directory /boot. Also, since the GRUB boot files are contained in /boot/grub, the
GRUB files are in that same /boot partition. Note this part of the linux line: root=UUID=0df17bc5-0056-4ef7-bfca-
251194b6eb44. The UUID corresponds to the partition containing the root filesystem (/) of the OS (in this case,
Ubuntu 8.04.3 LTS, kernel 2.6.24-24-generic) That partition (identified by its UUID) is passed to the Linux kernel
using root=UUID=0df17bc5-0056-4ef7-bfca-251194b6eb44 in the linux line.
So, the line "set root=(hd1,2)" is a message to GRUB 2; and "root=UUID=0df17bc5-0056-4ef7-bfca-251194b6eb44" is
a message to the Linux kernel.
Normally, for most users, the GRUB root partition (location of the kernel & initrd files) is the same as the root
partition of the OS. In this case, the GRUB root device (partition) (hd1,2) would be the same as the root of the
Kubuntu filesystem (and thus the UUID would be that of (hd1,2)). However, this need not be the case. If you have a
separate /boot partition (separate from the root filesystem of the OS), then the
set root=(hdx,y)
statement and the
root=UUID=xxx
statement in the linux line will correspond to two different partitions.
Another use of the word "root" and setting a "root" for GRUB occurs in the statement
sudo grub-install --root-directory=DIR INSTALL_DEVICE; for example
sudo grub-install --root-directory=/media/sdb1 /dev/sda
where DIR is /media/sdb1 and INSTALL_DEVICE is /dev/sda (i.e., the MBR of drive sda). This directs GRUB to install
GRUB images to INSTALL_DEVICE (using the files in the GRUB image directory /usr/lib/grub/i386-pc/ of the Kubuntu
OS you are working in) under the directory DIR (instead of the root directory (/) of the OS) and then to install GRUB 2
to the MBR of drive sda using GRUB 2 files in /media/sdb1/boot/grub. The directory DIR specified in --root-
directory=DIR becomes the GRUB root directory of this specific GRUB installation.
--------------------
Cheat Sheet
GRUB 2 Practical Reminders -- for those who know what they are doing
Permissions
Executable: sudo chmod 744 /etc/grub.d/file; Remove: sudo chmod -x /etc/grub.d/file
Read only, everyone: sudo chmod 444 /etc/grub.d/file
GUI: kdesudo konqueror (dolphin), rt-click on file, Properties, Permissions
grub.cfg: sudo chmod +w /boot/grub/grub.cfg; sudo chmod -w /boot/grub/grub.cfg
Edit a script
GUI, kdesudo konqueror, rt-click on script file, Open With Kate/Kwrite.
CLI, kdesudo kate /etc/grub.d/script_name
Edit the file, File>Save, Exit. New grub.cfg: sudo up-date grub; sudo grub-mkconfig
Flash drive /dev/sdc, sdc1 mounted at /media/disk; set boot flag; install GRUB 2:
sudo grub-install --root-directory=/media/disk /dev/sdc
= = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = =
Appendix: Techniques
= = = = = = = = = = = = = = = = = = = =
Installing Kubuntu--GRUB 2 placement
Live CD method
The Live CD method of installing Kubuntu is easy, fast, and convenient because afterwards, you then have a Live CD
to use for rescue and repair of your system.
GRUB 2 is standard on Kubuntu starting with 9.10. During its installation from the Live CD, you can specify if you
want GRUB 2installed, and if so, where to put it. Here's how:
Caution:
> If you install GRUB to a MBR (sda, sdb, sdc, etc.), it will overwrite any other bootloader already installed to that
MBR, and the GRUB 2 from the OS you are currently installing will then control the boot menu you see when you
boot up your PC. That is OK, just so you know.
> If you install GRUB 2 to the partition boot sector where you are currently installing the OS (e.g., sdan, for some
n=1,2,3,4...), when you re-boot your PC, you will have to manually boot into your new OS you just installed. Do so
using chainloader, as follows:
-- Re-boot
-- If you get some boot menu (from a prior Linux OS installation), press the "c" key to get a GRUB prompt, grub>. If
you don't get a boot menu but only the GRUB prompt grub>, then that's OK, too.
-- Let's say your new Kubuntu OS was installed to sda9. That is the same as (hd0,9). Then
grub>chainloader (hd0,9)+1
grub>boot
and you will boot into your new OS.
> In your new OS, you can build a full boot menu simply by doing sudo grub-mkconfig -o /boot/grub/grub.cfg.
> In your existing OSs, you can re-build boot menus to include the new OS the same way:
Konsole
sudo grub-mkconfig -o /boot/grub/grub.cfg
> Worst case, if for some reason that doesn't work, you can make a custom boot entry to include your new OS. See
SECTION 4. To get the details of the menuentry for the new OS for the existing grub.cfg, you might have to boot
into the new OS and copy details from its grub.cfg. Or, simply boot your new OS using symlinks or chainloader (from
another OS's boot menu), for which you do not need any details specific to the new OS. See SECTION 4, "4 Ways to
boot an OS."
= = = = = = = = = = = = = = = = = = = =
Working as root
Opening a text editor (e.g., Kate, Kwrite, etc.) to see the file and/or to edit it:
kdesudo kate path-to-file
Example: kdesudo kate /etc/fstab
= = = = = = = = = = = = = = = = = = = =
Permissions: read, write, execute; change the execute bit
See Part 2 of
Commands at Konsole: Beginners: 3 parts
http://kubuntuforums.net/forums/index.php?topic=3091607.0
Ownership and Permissions Use ls -l to see them; chown & chmod to change them.
See tuxfiles
http://www.tuxfiles.org/linuxhelp/filepermissions.html
(symbolic mode)
Here's a brief reminder sheet for those who know this stuff:
CLI
owner--group--others
For each class: read, write, execute
ls -l: list files, use a long listing format => shows ownership and permissions
0: ---; 1: --x; 2: -w-; 3: -wx; 4: r--; 5: r-x; 6: rw-: 7: rwx
744: Owner can do anything, Group can only read, Others can only read
= = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = =
-----
GRUB 2 Bugs and Questions
GRUB Legacy
-- How To GRUB Methods - Toolkit
http://kubuntuforums.net/forums/index.php?topic=3081671.0
Grub 2 Manual
http://grub.enbug.org/Manual
We hope this will be all you need, along with the man pages.
StartUp-Manager
https://help.ubuntu.com/community/StartUpManager
Bootloader
http://en.wikipedia.org/wiki/Boot_loader
GNU GRUB
http://en.wikipedia.org/wiki/GRUB
Boot Options
https://help.ubuntu.com/community/BootOptions
Kernel Parameters
http://www.kernel.org/doc/Documentation/kernel-parameters.txt
Grub Legacy
-- How To GRUB Methods - Toolkit
http://kubuntuforums.net/forums/index.php?topic=3081671.0
GParted Live CD
http://gparted.sourceforge.net/livecd.php
For partitioning, formatting your hard drive.
GRUB 2 installation
http://www.techenclave.com/guides-and-tutorials/grub-2-installation-92883.html
GRUB2 Theming
http://ubuntuforums.org/showthread.php?t=1182436
KernelTeam/Grub2Testing
https://wiki.ubuntu.com/KernelTeam/Grub2Testing
Using UUID
https://help.ubuntu.com/community/UsingUUID
HOWTO: Booting LiveCD ISOs from USB flash drive with Grub2, by JustRon.
http://ubuntuforums.org/showthread.php?t=1288604
Tweaking GRUB 2
http://www.drlock.com/blog/2008/07/11/tweaking-grub-2/