Announcement

Collapse
No announcement yet.

GRUB 2: A Guide for Users

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    GRUB 2: A Guide for Users

    GRUB 2 A Guide for Users

    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, 12/4/09, January 2014, 5/29/15, 5/30/15, 8/23/15

    ]]]]]]]]]]

    GRUB 2 update for EFI
    We have various versions of GRUB floating around:
    Grub Legacy, GRUB 2 for BIOS+MBR, GRUB 2 for EFI

    For Grub Legacy, there's this: HOW TO: GRUB Methods - Toolkit
    https://www.kubuntuforums.net/showth...ethods-Toolkit

    For GRUB2-EFI, see:

    UEFI Simplified, a quicker version

    https://www.kubuntuforums.net/showth...l=1#post379977

    This covers all the topics and more of the longer, more tutorial version.
    Or, try the longer, more tutorial version:

    UEFI for Kubuntu--simplified. And ... some dual-booting tips for Kubuntu
    https://www.kubuntuforums.net/showth...l=1#post373198

    GPT, UEFI -- Study Guide
    https://www.kubuntuforums.net/showth...l=1#post346604

    A new PC build and Kubuntu-only UEFI installation
    https://www.kubuntuforums.net/showth...l=1#post368216

    Dual-booting: How to Use Multiple ESPs
    https://www.kubuntuforums.net/showth...l=1#post376040

    Dual-booting Kubuntu: A summary of your options
    https://www.kubuntuforums.net/showth...l=1#post376269

    Labels on UEFI Boot Entries -- using efibootmgr -L
    https://www.kubuntuforums.net/showth...229#post378229

    rEFInd
    https://www.kubuntuforums.net/showth...l=1#post372221

    rEFInd: Make a live CD to boot into your system
    https://www.kubuntuforums.net/showth...l=1#post376838

    rEFInd: Make a live USB Flash Drive to boot into your system
    https://www.kubuntuforums.net/showth...l=1#post379352

    Remove GRUB from UEFI -- Instead, use rEFInd and/or UEFI firmware boot menus
    https://www.kubuntuforums.net/showth...l=1#post378317

    Fix UEFI+GPT with Testdisk & gdisk -- Deleted partitions & damaged GPT structure
    https://www.kubuntuforums.net/showth...417#post372417

    Re-install GRUB2 from Live DVD/USB flash drive
    https://www.kubuntuforums.net/showth...l=1#post374017

    Building a Kubuntu live USB installer using dd
    https://www.kubuntuforums.net/showth...aller-using-dd

    NEW: Building a Kubuntu live USB installer using dd
    https://www.kubuntuforums.net/showth...712#post378712

    Using Your Live Kubuntu DVD/USB to Fix Things
    https://www.kubuntuforums.net/showth...l=1#post379485

    Installing Kubuntu -- Using the "Manual" Installation Type, with your own partitioning
    https://www.kubuntuforums.net/showth...688#post377688

    ]]]]]]]]]]
    May 2015: Updating /boot/grub/grub.cfg

    Ubuntu and Debian systems use sudo update-grub.

    Kubuntu, Ubuntu, Mint, etc.: Use sudo update-grub.
    Other systems may use grub2-mkconfig -o /boot/grub/grub.cfg, or grub-mkconfig -o /boot/grub/grub.cfg

    update-grub VERSUS grub-mkconfig
    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, you must specify the output file when using grub-mkconfig:
    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

    Note: grub-install --root-directory=DIR, VERSUS sudo grub-install --boot-directory=DIR
    Another apparent change or new feature? -->
    sudo grub-install --root-directory=/media/sda2 /dev/sda VERSUS
    sudo grub-install --boot-directory=/media/sda2/boot /dev/sda (new in the GRUB Manual: https://www.gnu.org/software/grub/ma...ub_002dinstall)

    As recently as January 2014, I've used the former. If that fails on you, try the latter.
    - - - - - - - - - -
    To search the Kubuntu forum using google:
    site:kubuntuforums.net "additional drivers" + sound -Windows
    site: gives you results from only the site you type; "quotes" gives you exactly what you put in quotes; + will make sure that word is there; - (minus sign) will omit the word.

    [[[[[[[[[[

    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/default/grub --> /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
    --- Removing old kernels so they don't take up space and so your grub.cfg boot menu isn't so long:See Appendix at the very end, preceding the References

    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: Key Rescue Method
    Using a Live CD to edit files in your OS

    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 Post #2
    Booting XP on a non-first hard drive (drivemap): See Post #2

    -->> Cheat sheet: GRUB 2 Practical Reminders

    Appendix: Techniques

    --- Removing old kernels so they don't take up space and so your grub.cfg boot menu isn't so long.

    --- Installing Kubuntu -- GRUB 2 placement
    --- Working as root, editing a file
    --- Permissions: read, write, execute; change the execute bit

    References and Tutorials
    List of GUI GRUB 2 help-repair-editing packages to make things easier

    * * * * * * * * * * * * * * *
    See Post #2 below for more GRUB 2 topics
    :
    https://www.kubuntuforums.net/showth...l=1#post193706
    Contents of Post #2:

    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 of Post #1
    drivemap: See Post #17 below
    loopback: See Boot From ISO (below)

    Dual booting: How to set it up
    Installing two or more Linux operating systems
    RECOMMENDED METHOD
    PROBLEMS
    Messing up the booting -- fixing GRUB without re-installing Kubuntu
    Windows topics
    Installing XP (or 7? or Vista?) & Kubuntu:
    How to set up dual booting (recommended outline)
    Re-installed XP and now can't boot Kubuntu
    XP on a non-first hard drive: (hdx,y), x > 1

    Booting XP on a non-first hard drive
    The drivemap command in GRUB 2

    Boot From ISO -- use of GRUB 2 loopback
    Boot your Kubuntu Live CD ISO from your flashdrive

    GPT: GUID Partition Table
    ... for Kubuntu 9.10 and GRUB 2
    => Overcoming the "2 TB disk size limit"associated with the conventional MBR
    => Testing GRUB 2 on your GPT-partitioned flash drive

    UEFI issues, links: note the subforum started by Steve Riley:
    UEFI Assistance:
    https://www.kubuntuforums.net/forumd...EFI-assistance

    You'll find excellent tutorial material on UEFI, GPT, Secure Boot, other boot managers (UEFI will boot your Kubuntu OS; you don't need GRUB to do the booting; GRUB is also a boot manager, though; however, there are also other boot managers you can use instead of GRUB; etc.), legacy issues, and just about everything else you might want to know as you get started with UEFI.


    = = = = = = = = = = = = = = = = = = = =
    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 Post #2


    History: GRUB Legacy, GRUB 2
    "Briefly, boot loader is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the operating system kernel software (such as the Hurd or the Linux). The kernel, in turn, initializes the rest of the operating system (e.g. GNU)." (gnu.org)

    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, ...)

    For the history of GRUB and some interesting links, see
    http://www.gnu.org/software/grub/

    GRUB 2 is cleaner, more efficient, powerful, and more elegant, in many ways it is simpler to use than GRUB Legacy.
    GRUB 2: GRUB 2: http://www.gnu.org/software/grub/manual/grub.html


    Its mailing list for development,
    GRUB-devel: http://lists.gnu.org/mailman/listinfo/grub-devel
    And the Wiki: https://help.ubuntu.com/community/Grub2

    GRUB 2 is the default bootloader in 9.10
    https://lists.ubuntu.com/archives/ub...ne/000573.html

    Differences between GRUB Legacy and GRUB 2

    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.

    It is conceptually simple in GRUB 2:
    You can edit the file /etc/default/grub and you can edit the scripts in /etc/grub.d, then run the command sudo grub-mkconfig -o /boot/grub/grub.cfg, and the file grub.cfg is automatically generated.

    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

    A boot entry in GRUB Legacy menu.lst might look like this:
    title Ubuntu 8.04.3 LTS, kernel 2.6.24-24-generic
    root (hd1,2)
    kernel /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

    In GRUB 2 grub.cfg, it would look like this:

    ### 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
    }
    ### END /etc/grub.d/10_Linux ###

    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).

    sudo grub does not get you a GRUB 2 shell at Konsole
    In GRUB Legacy, the user may open a GRUB shell by typing sudo grub, and then use it to install/re-install GRUB (root-setup-quit) to a Master Boot Record or to a partition boot sector. In GRUB 2, there is no such option. Instead, the key command is the Konsole (BASH) command grub-install. At Konsole, as root, you will use sudo grub-install to install/re-install GRUB 2 to a Master Boot Record or to a partition boot sector.

    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."


    GRUB 2 Commands -- compared to GRUB Legacy
    Comparison chart:
    See: http://www.gnu.org/software/grub/manual/grub.html#Commands

    Key useful items to note:

    GRUB Legacy <--> GRUB 2

    find is replaced with search
    geometry is gone and replaced by ls
    kernel (in menu.lst) is replaced by linux (and other terms for different OSs)
    title (in menu.lst) is replaced by menuentry (in grub.cfg)
    root is still used but is now a variable
    setup is gone; the work is done by grub-install
    map is replaced by drivemap
    device is replaced by loopback (makes a drive out of a file)
    set is a GRUB 2 term used to set a variable

    Notes about some of the new GRUB 2 commands: See Post #2.

    = = = = = = = = = = = = = = = = = = = =
    = = = = = = = = = = = = = = = = = = = =
    SECTION 2 Key Facts About the Boot menu, grub.cfg

    Quick version -- Overview -- Details
    /etc/default/grub --> /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
    -->> Removing old kernels so they don't take up space and so your grub.cfg boot menu isn't so long: See Appendix at the very end, preceding the References


    Quick version
    :
    /etc/default/grub --> /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 or run update-grub


    Examples of grub.cfg
    /usr/share/doc/grub-pc/examples/grub.cfg.
    GRUB 2 Basics http://ubuntuforums.org/showthread.php?t=1195275

    GRUB 2 device numbering is new: Partitions start at 1
    In GRUB 2 (as in GRUB Legacy), hard drives start at zero: hd0 is the first hard drive. In GRUB 2 (unlike GRUB Legacy), partition numbering starts at 1: (hd0,1) is the first partition in the first hard drive; (hd0,2) is the second partition in the first hard drive; (hd1,2) is the second partition in the second hard drive.

    Linux device notation is the same as in GRUB Legacy
    sda is the first hard drive; sdb is the second hard drive; sdc is the third; etc.
    sda1 is the first partition of the first hard drive; sda2 is the second partition of the first hard drive; etc.

    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/default/grub and it feeds default data to the scripts in /etc/grub.d. You may edit /etc/default/grub (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).

    >>> Key reminder:
    Generate a new grub.cfg after changing anything in /etc/default/grub or /etc/grub.d by:
    grub-mkconfig -o /boot/grub/grub.cfg or run update-grub

    Experts: Editing grub.cfg
    The file is read-only, so change permission to include Write:
    sudo chmod +w /boot/grub/grub.cfg
    Then do the edits as root and Save. When grub-mkconfig is run, the file returns to read-only (chmod 444 or 400), AND your edits may be overwritten (and therefore gone).
    Optional: After editing, restore permissions to disallow writing:
    sudo chmod -w /boot/grub/grub.cfg or
    sudo chmod 444 /boot/grub/grub.cfg

    The default settings file /etc/default/grub
    This file feeds data to the scripts in /etc/grub.d. It contains the Default operating system, the Timeout, kernel options, resolution of the graphical boot menu, and other default settings. You may edit this file with root privileges.

    The folder of scripts /etc/grub.d
    These scripts generate /boot/grub/grub.cfg when the grub-mkconfig command is run (as root). The order of the entries in grub.cfg corresponds to the order of the files in /etc/grub.d, starting with 00_header, then 01_scriptname, etc., through all files starting with NN_ where NN is a 2-digit number and _ is the underscore (Shift+(minus sign)); then comes scripts whose names start with a letter (e.g., a_anotherscript).

    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.

    Editing the script files in /etc/grub.d:
    Do your work as root.
    To make the file /etc/grub.d/filename executable:
    sudo chmod 744 /etc/grub.d/filename
    To remove the execute bit from the file filename:
    sudo chmod -x /etc/grub.d/filename
    When done, run
    sudo grub-mkconfig -o /boot/grub/grub.cfg
    to generate a new boot menu configuration file /boot/grub/grub.cfg.
    GUI: How to set permissions
    Open Konqueror or Dolphin as root (e.g., kdesudo konqueror).
    Open the file.
    Right-click > Properties > Permissions, Advanced Permissions

    Tip: To open a file in /etc/grub.d (as root)
    The files in /etc/grub.d are scripts. So, as root, if you click on one, it will want to execute or run like a program. Instead, to open a script for editing/viewing, right-click on the script file, Open With Kate or Kwrite. That opens the file as a text file. Now you can read it or edit it.
    Details:
    GUI, working as root: Open Konqueror (Dolphin) as root and work from there:
    kdesudo konqueror
    CLI, working as root: kdesudo kate /etc/grub.d/script_name


    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: sudo grub-mkconfig and sudo grub-install
    Timeout & Default OS, changing
    Hide/Unhide the boot menu
    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 rescue method
    Using a Live CD to edit files in your OS
    -->> Removing old kernels so they don't take up space and so your grub.cfg boot menu isn't so long: See Appendix at the very end, preceding the References


    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.

    To fix it, you have two choices:
    boot into the OS somehow and fix it;
    or
    fix it from outside the OS (e.g., live CD, another OS, or live flash drive).

    Before looking at these two choices, note two important things:
    > To fix the boot menu means to fix its configuration file /boot/grub/grub.cfg. You can sometimes do that temporarily using the edit-on-the-fly "e" key (see subsection below). To fix it permanently, you do NOT edit grub.cfg directly; but rather you edit the file /etc/default/grub and/or you edit the script(s) in /etc/grub.d, and then you use the command grub-mkconfig to generate a new grub.cfg.
    > To fix the GRUB 2 installation, that usually means re-installing GRUB 2 using, at Konsole, the command grub-install. You can do this from inside the OS (if you can boot into it somehow), or from a Live Kubuntu CD or from another Linux OS on your hard drive. You cannot do it from the GRUB 2 prompt (grub>) when booting the PC. (In GRUB Legacy, you could do it by getting the grub> prompt and using the root and setup commands.)

    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 Grub2 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).


    --> How to fix the problem from outside the OS:
    (1) Use a Live CD, or (2) Fix it from another OS.
    Some details:

    > Use a Live CD. (Or, simply use Super Grub2 Disk or another GUI Grub repair CD--see References.)

    From a Live Kubuntu CD (or most any live Linux CD), you can re-install GRUB and/or perform edits on files (/etc/default/grub or the script(s) in /etc/grub.d). See the subsections below: "Re-installing GRUB 2 using Live CD: Key Rescue Method" and "Using a Live CD to edit files in your OS."

    > 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.)

    [End of Troubleshooting Outline]


    Ctrl+Alt+Del will reboot your PC
    If your PC freezes up during the experiments/testing/troubleshooting of your bootloader, use Ctrl+Alt+Del to re-boot the PC. Be prepared to do something, though!
    Examples of what to do:
    -- Before using Ctrl+Alt+Del, put the Super Grub Disk CD in the CD tray so you can re-boot to it and rescue your OS.
    -- Be prepared to press the key required to enter your BIOS setup. That will buy you some time, or give you a chance to change hard drive booting order, or put a live CD or SGD in the CD tray, or get your notes ready, etc.
    -- If you have been getting a boot menu, let the PC reboot into it, then enter Edit mode (pressing the "e" key) or enter the GRUB 2 CLI (pressing the key "c"), then try to fix things from there.


    Super Grub Disk: Very Important
    Whether you think you need it or not, get it now, free, as a bootable CD which will get you booted into your operating system in case you can't. SGD can be downloaded here: http://www.supergrubdisk.org/ . Look for a CD ROM iso version, download it, burn it as an iso image to a CD (using K3b), test it briefly (by running it and stepping through a few menus but not choosing anything; then Quit; or, use it to boot into your OS).


    Key commands: sudo grub-mkconfig and sudo grub-install
    Use these two commands to "freshen up" your GRUB 2 installation.
    grub-mkconfig: builds a new boot menu configuration file boot/grub/grub.cfg.
    grub-install: builds a complete, fresh GRUB 2 installation, including /boot/grub/grub.cfg.

    grub-mkconfig (See the comment at the very beginning of this how-to regarding grub-install.)
    grub-mkconfig )

    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 Post #2 (to this post): Notes about some of the new GRUB 2 commands
    You should also run grub-mkconfig after running grub-install.

    sudo grub-install [INSTALL_ DEVICE]
    installs or re-installs GRUB 2 to INSTALL_DEVICE.

    See SECTION 4: grub-install: A key command
    For now, here's some highlights.

    sudo grub-install /dev/sda
    installs GRUB 2 to the Master Boot Record of drive sda. And
    sudo grub-install /dev/sda1
    installs GRUB 2 to the boot sector of the partition sda1.
    In doing so, grub-install does a complete job of setting up everything.
    Here's what it does: It builds the directory /boot/grub (if it doesn't already exit), copies GRUB 2 files to it from the "master" image directory /usr/lib/grub/i386-pc, probes your drives and devices and partition table, makes a new device.map, builds and installs boot.img (to MBR) and core.img, and builds /boot/grub/grub.cfg. -->>> But it does not run grub-mkconfig; so you should do so after running grub-install to build a new grub.cfg file.

    > Man page: (8)GRUB-INSTALL - Install GRUB on your drive.
    http://grub.enbug.org/FranklinPiat/grub-install.manpage

    Troubleshooting
    -- After running grub-mkconfig, make sure that the line set default=(hdx,y) in grub.cfg 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].


    Timeout and Default OS, changing
    The timeout is the length of time in seconds before the (highlighted) default OS is automatically booted (if you do not intervene by touching a key). To change these values, open the file /etc/default/grub as root, make the changes, Save, exit, then generate a new /boot/grub/grub.cfg by running sudo grub-mkconfig -o /boot/grub/grub.cfg.

    Opening /etc/default/grub as root
    If your file manager supports it, open the file manager, navigate to /etc/default/grub, right-click on the file, Actions, Edit as Root. Otherwise:
    Open the file manager as root and work from there:
    kdesudo konqueror
    kdesudo dolphin
    Or, open the file as root using Kate or Kwrite:
    kdesudo kate /etc/default/grub

    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.

    GRUB_TIMEOUT=5 causes the boot menu to be displayed for 5 seconds.

    Hide/Unhide the boot menu (to see the boot menu when booting the computer)
    To display the boot menu, open /etc/default/grub as root (kdesudo kate /etc/default/grub), find the line GRUB_HIDDEN_TIMEOUT=0, place a # symbol at the start of it:
    # GRUB_HIDDEN_TIMEOUT=0
    Of course, make certain that DEFAULT_TIMEOUT is set to some positive (integer) value. For example,
    GRUB_TIMEOUT=5
    causes the boot menu to be displayed for 5 seconds.

    With the # sign present, you will see the boot menu upon booting your PC.
    With the # removed, you will not see the boot menu.

    Troubleshooting Tip: Check default OS setting after grub-mkconfig
    If you recently added/removed a boot entry (by editing a /etc/grub.d script) and ran grub-mkconfig to generate a new boot menu, you might have to check and edit the line "GRUB_DEFAULT= " (in /etc/default/grub) if the default sequence number changed.

    Kernel options, changing
    To change these values, open the file /etc/default/grub as root, make the changes, Save, exit. (See Timeout and Default OS above for editing tips.) The line in /etc/default/grub looks like this (or similar):
    GRUB_CMDLINE_LINUX="quiet splash"

    Missing OS entry in the boot menu
    If you run grub-mkconfig, and there is a missing entry in your boot menu, you can add that entry as a custom entry. See SECTION 4 below, Special Topics Boot menu: Create a custom boot entry.

    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.


    The GRUB prompt grub> -- What to do with it
    => Getting information and booting an OS

    You may get the GRUB prompt grub> in three ways:

    > "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!).

    From the grub> prompt, you may be able to issue commands to
    help you gather information about your drives
    or
    boot your computer.

    Use these resources:
    SECTION 4 Special Topics, the subsection
    "4 ways to boot an OS" -- direct booting configfile, symlinks, chainloader
    SECTION 4 Special Topics, the subsection
    "How to get information about your drives and devices"
    => In particular, take special note of the ls command and the use of TAB completion.

    Example Booting using symlinks; and using the ls command

    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 If you need to re-boot or shut down the PC
    To reboot, get the GRUB 2 prompt by pressing "c" key, and then
    grub>reboot
    To shut down
    grub>halt

    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

    If your GRUB 2 is somehow messed up, but you can boot into your OS, then you can fix things from within the OS: fixing the boot menu grub.cfg (using grub-mkconfig), and/or re-installing GRUB 2 from Konsole (using grub-install).


    If your GRUB 2 is messed up and you can NOT boot into your OS, then you must try to fix your GRUB 2 using a Live CD, somehow. Your options are:

    -- Use a bootable CD containing a GUI GRUB 2 repair program.
    Keep it simple with Super GRUB Disk--definitely recommended:
    Super Grub2 Disk
    http://www.supergrubdisk.org/super-grub2-disk/

    Or, try:

    GRUB2 Editor
    A KDE Control Module for configuring the GRUB2 bootloader
    http://sourceforge.net/projects/kcm-grub2/

    Boot-Repair-Disk
    http://sourceforge.net/projects/boot-repair-cd/?source=navbar

    kde-config-grub2

    UNetbootin - Homepage and Downloads
    http://unetbootin.sourceforge.net/
    Makes a bootable USB thumb drive for you, using your distro or using an iso.

    Grub Customizer
    http://ubuntuforums.org/showthread.p...3#post10340183

    Or,
    -- Use your Live Kubuntu CD to repair the GRUB 2 in your OS (use the same version of Kubuntu Live CD as the Kubuntu installation you are trying to fix; for example, if you are fixing a 12.04 Kubuntu system, use a Kubuntu 12.04 Live CD).

    There are two ways of doing this: by chrooting; and by not chrooting.
    One advantage of chrooting is that you can not only install GRUB 2, but you can (I believe) then generate a new grub.cfg by running update-grub.

    If you do not chroot, you can still install the GRUB 2 files into the broken OS. When you reboot, if your grub.cfg menu file is OK, you'll successfully re-boot into your Kubuntu OS. If something is wrong with your grub.cfg menu file, when you re-boot, you will probably boot to a GRUB 2 prompt: grub>. Then you must use GRUB commands to try to boot into your Kubuntu OS from there (by direct booting, symlinks, configfile, or chainloading). Chances are that your existing grub.cfg will be 'good enough' to get you into your OS. After you do get in, then you can easily fix everything--the GRUB installation and the boot menu grub.cfg, at Konsole, using grub-install and grub-mkconfig.

    Method 1: Installing or re-installing GRUB 2 using a Live CD

    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 ...

    Start your Kubuntu Live CD.
    Choose the option to try Kubuntu without installing.
    Open Konsole (Terminal): K-Menu > System > Konsole
    Explore your partitions using
    sudo fdisk -lu
    Determine your root partition. In this example, ours is sda2.
    Make a mount point (directory) for partition sda2:
    sudo mkdir /media/sda2
    Mount sda2 on the mount point:
    sudo mount /dev/sda2 /media/sda2
    Install (or re-install) GRUB 2 (into the MBR of drive sda) using the GRUB 2 files in sda2:
    sudo grub-install --root-directory=/media/sda2 /dev/sda
    (If that doesn't work, try this:
    sudo grub-install --boot-directory=/media/sda2/boot /dev/sda)

    You may get this error:
    grub-probe: error: Cannot find a GRUB drive for /dev/sda2. Check your device.map.
    Auto-detection of a filesystem module failed.
    Please specify the module with the option `--modules' explicitly.

    If so, try this:
    sudo grub-install --recheck --root-directory=/media/sda2 /dev/sda
    Maybe you'll get lucky and see this:
    Installation finished. No error reported.
    This is the contents of the device map /media/sda2/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

    (=> and so this was successful)

    Then, unmount both filesystems:
    sudo umount /dev/sda2 /media/sda2
    Leave Konsole:
    exit
    Test it:
    Exit out of the Live CD, reboot, see if you fixed your booting problem (by booting into the broken partition).

    [End of Method 1]
    - - - - - - - - - -

    Method 2, by chrooting

    Two fairly clear links on using chroot to do this are an Ubuntu page:
    https://help.ubuntu.com/community/Gr...ing#via_ChRoot
    and a SystemRescueCd page (which may be more clear than the Ubuntu page):
    http://www.sysresccd.org/Sysresccd-P...a-damaged-Grub
    Note their first method, which uses the SystemRescueCd without chroot.

    - - - - - - - - - -

    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

    Cheat sheet: GRUB 2 Practical Reminders
    - - - - -

    Installing GRUB 2 To Your PC

    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.

    Step 1: Get the GRUB 2 files
    Install the GRUB 2 package in your Kubuntu OS using your package manager. Or, at Konsole, issue the following command:
    sudo apt-get install grub-pc

    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).

    Step 2: Install the GRUB 2 files so they serve as a bootloader: sudo grub-install

    Suppose your first BIOS boot drive is sda (as seen in Kubuntu using at Konsole the command sudo fdisk -lu). Then, install GRUB 2 to the Master Boot Record of sda:
    sudo grub-install /dev/sda

    This also copies the GRUB 2 files into /boot/grub.
    Then to generate a fresh boot menu configuration file (/boot/grub/grub.cfg), run
    sudo grub-mkconfig -o /boot/grub/grub.cfg.

    More Details About This

    CAUTION, fair warning:
    Have a bootable Super Grub2 Disk CD handy in case this messes up booting your PC.

    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

    Full form: grub-install [OPTION] INSTALL_DEVICE

    Two very important options are
    --recheck
    Probe a device map even if it already exists
    --root-directory=DIR (or ... --boot-directory=DIR -- see following COMMENT)
    Install GRUB images under the directory DIR instead of the root directory
    (See discussion below.)

    (COMMENT, January 2014: I am still using the option --root-directory=DIR, like this: sudo grub-install --root-directory=/media/disk /dev/sda. I see others using it. However, I have read that it was 'replaced' by --boot-directory=DIR, like this: sudo grub-install --boot-directory=/media/disk/boot /dev/sda. Be aware that you might try both; or, if you wish, stick with the option --boot-directory=DIR (which is the one you will find in the GRUB 2 Manual). In this latter case, DIR would be the /boot directory, not the root directory.)

    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 (under /media/sdb1/boot/grub) 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).

    Use the command sudo grub-install for these purposes:
    to refresh the entire GRUB 2 installation; or when you are re-installing GRUB 2 to fix a problem; or when you are installing GRUB 2 to another place or to a dedicated GRUB 2 partition or to a USB (flash) drive.

    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. --> Note: it does NOT run grub-mkconfig; to generate a boot menu configuration file, you must run grub-mkconfig separately. (some people are using update-grub for this).

    /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.

    grub-install does the following for you:

    > 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.)
    --> grub-install does NOT build the boot menu configuration file, grub.cfg.

    You may do so by building a custom grub.cfg boot menu; or, by running grub-mkconfig.

    Two useful options
    --recheck
    Probe a device map even if it already exists
    --root-directory=DIR (or use --boot-directory=DIR)
    Install GRUB images under the directory DIR instead of the root directory

    --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.

    Dedicated GRUB 2 partition
    Suppose your OS is on some partition on one of your hard drives. And suppose you wish to build a dedicated GRUB 2 partition in sdb1, and that your first BIOS boot drive is sda, and that you wish to setup GRUB 2 files in sdb1 and use those to install GRUB to the MBR of sda. Here's the command:
    sudo grub-install --root-directory=/media/sdb1 /dev/sda
    (And then you may wish to build a custom boot menu -- see below.)

    Note that sdb1 is mounted as /media/sdb1; also that sda is specified as a device: /dev/sda (not just sda).
    See the subsection below titled "Dedicated GRUB 2 partition: How to build it"

    USB flash drive (Tested again, January 2014.)
    Suppose your flash drive is seen in Kubuntu as /dev/sdc and it is mounted as /media/flashdrive. Then the command to setup and install GRUB 2 to it is:
    sudo grub-install --root-directory=/media/flashdrive /dev/sdc
    and to build the grub.cfg file:
    sudo grub-makconfig -o /media/flashdrive/boot/grub/grub.cfg
    See the subsection below titled "GRUB 2 Flashdrive: How to build it"

    A few details about installing boot.img and core.img
    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); it is built specific to your PC setup. The boot.img points at core.img; core.img is embedded in some fixed location (on a disk), but usually that location is in the same "cylinder" as the MBR that contains boot.img. (Details: the MBR goes into sector 1 and is 512 bytes, and that's where boot.img goes. This first cylinder has 63 sectors, so that leaves 62 sectors or 31,744 bytes (=62*512) where core.img may be embedded. This first cylinder (of 63 sectors containing boot.img and core.img) precedes the start of the first partition on that disk, which would start at sector 63 (counting of sectors (in LBA) starts at zero, so 63 sectors take us to the end of sector 62 = the start of sector 63). You will see this if you run as root fdisk -lu.)

    [End of subsection: grub-install The most useful command]
    - - - - -

    The various types of command modes
    "c," grub>, Konsole BASH, edit "e", emu

    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)
    -- 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.

    TAB completion (grub>)
    While typing after the grub>, try pressing the TAB key and see what happens: in many cases, GRUB will try to help you complete the line with something meaningful or with choices. So type as much as you can recall or type a guess, then press TAB, then you may have to type another guess and press TAB again, and so on until you complete the line the way you want it.

    GRUB 2 device numbering is different
    (hdx,y): hard drive x, partition y
    Hard drives start at zero (x=0), same as for GRUB Legacy.
    Partitions start at 1 (y=1); in GRUB Legacy, partitions start at zero.

    - - - - -
    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.

    Konsole (BASH) command line

    Exploring your hard drive(s): sudo fdisk -lu
    => sudo fdisk -lu is very useful, very important.
    GRUB version number: grub-install -v
    Drive space: df -h -T
    UUIDs (see NOTE below):
    blkid (or try sudo blkid); also:
    ls /dev/disk/by-uuid/ -alh
    grub.cfg, to see it: cat /boot/grub/grub.cfg
    fstab (filesystem table), to see it: cat /etc/fstab
    Mounting, how filesystems are mounted: cat /etc/mtab or: mount
    Boot directory /boot, to find it: df /boot
    Kernel version and gcc version (gcc=the GNU compiler used to build the kernel):
    cat /proc/version
    Kernel version: uname -r
    Linux version/name: lsb_release -a
    (hold the Shift key and the minus sign key to get _ . LSB = Linux Standard Base)
    KDE version (KDE=K Desktop Environment)
    for KDE 3.5: kde-config –version and for KDE 4: kde4-config --version

    NOTE: UUID = Universally Unique Identifier
    Starting with Kubuntu version 8.10, UUIDs are used to identify partitions. A UUID is a 16-byte number (= 128 bits). In canonical form, a UUID consists of 32 hexidecimal digits, displayed in 5 groups separated by hyphens.

    At a GRUB prompt, grub> (remember to use Tab completion, as needed)

    Exploring your hard drive(s): grub> ls
    => Very useful, very important.
    (in GRUB Legacy, the geometry command is used instead of ls)

    The ls command is very useful
    grub>ls
    gives you a list of your hard drives and partitions as GRUB sees them, in (hdx,y) GRUB 2 device notation.
    grub>ls /
    shows you the files under the current GRUB 2 root device. You can set that device using set root=. For example:
    grub>set root=(hd0,8)
    grub>ls /
    shows you all files under root. Or: grub>ls (hd0,8)/ .
    grub>ls /boot
    shows you all files--including kernels--under /boot.

    UUIDs and filesystem type
    grub>ls (hd0,8)
    shows you information about the partition (hd0,8) including its filesystem type and its UUID.

    The contents of a directory: grub>ls -l /directory
    Example
    grub>ls -l /boot
    shows you the kernel and initrd files.
    (The option -l indicates "long form" and gives more information. To see all files, including hidden files, use the option -a: grub>ls -a -l /boot; or grub>ls -al /boot)

    GRUB 2 emulation sudo grub-emu
    At Konsole, to get a grub> prompt, type sudo grub-emu.
    To exit emu and return to Konsole, type exit.
    >>> IMPORTANT sudo grub-emu and then grub>ls
    While you are working at Konsole in Kubuntu, you may need to know how GRUB sees your drives and partitions, the (hdx,y)'s. You can switch into emulation mode (sudo grub-emu)) and issue the list (ls) command at the GRUB prompt (grub>ls) to see your drives and GRUB devices. Type exit to return to BASH mode in Konsole.

    Using search and cat
    GRUB files, what partitions they are in: grub>search /boot/grub/boot.img
    Boot menu, what partition(s) it is in: grub>search /boot/grub/grub.cfg
    Kernel, where it is: grub>search /vmlinuz
    Boot menu, to see it: grub>cat (hdx,y)/boot/grub/grub.cfg
    fstab, to see it: grub>cat (hdx,y)/etc/fstab
    Device.map, to see it: grub>cat (hdx,y)/boot/grub/device.map (if you have one).

    (NOTE: In GRUB Legacy, the find command is used instead of search.)

    Restart (reboot), or shutdown (halt) your PC at a command line
    At Konsole:
    sudo shutdown -r now (re-boots the PC)
    sudo shutdown -h now (shuts down the PC)
    In GRUB:
    grub>reboot (re-boots the PC)
    grub>halt (shuts down the PC)
    - - - - -


    Boot menu: Adding or removing an OS entry to grub.cfg
    Rule: You do NOT edit grub.cfg directly. Instead, you work with script files in the folder /etc/grub.d or with settings in /etc/default/grub.

    -- Linux operating systems, added automatically
    Look at your grub.cfg. The section
    ### BEGIN /etc/grub.d/10_linux ###
    ### END /etc/grub.d/10_linux ###
    contains Linux operating systems that were automatically detected by GRUB 2 using the script file /etc/grub.d/10_linux. Most of your Linux OSs should be detected this way and included in the boot menu grub.cfg. If not, you can create a custom boot entry (see below, "Boot menu: Create a custom boot entry").

    -- Windows and other OSs added automatically
    This is done by the script /etc/grub.d/30_os-prober.

    -- 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")

    -- Removing a boot entry from grub.cfg:
    Two choices.
    (1) Simply remove the execute bit from the script file in /etc/grub.d that corresponds to (i.e., generates) the boot entry.
    Example: If that file is named 43_MyOS-1, then run the Konsole commands
    sudo chmod -x /etc/grub.d/43_MyOS-1
    sudo grub-mkconfig -o /boot/grub/grub.cfg
    (2) Or, remove the script file (for the boot entry) from the folder /etc/grub.d. Then run
    sudo grub-mkconfig -o /boot/grub/grub.cfg to generate the new grub.cfg file.
    NOTE: If a custom file contains more than one boot entry, you may remove any number of them, leaving the rest. Then use grub-mkconfig to generate your new boot menu, grub.cfg.


    Boot menu: Custom boot entry
    This is easy, usually.
    -- There are 4 ways to make a boot entry (see "4 Ways To Boot an OS").
    -- There is a custom template at /etc/grub.d/40_custom. <-- There may not be!
    -- After you write the script file for your custom boot entry, make it executable.
    -- Then generate a new grub.cfg by running sudo grub-mkconfig -o /boot/grub/grub.cfg.

    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:

    Debian GNU/Linux, sidux kernel 2.6.28-5.slh.3-sidux-686
    root (hd0,2)
    kernel /boot/vmlinuz-2.6.28-5.slh.3-sidux-686 root=UUID=306d94a5-107b-4c9e-ae03-a159e18dc1c7 ro quiet vga=791
    initrd /boot/initrd.img-2.6.28-5.slh.3-sidux-686

    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

    echo "Adding sidux" >&2
    cat << EOF
    menuentry "sidux on sda3" {
    set root=(hd0,3)
    linux /boot/vmlinuz-2.6.28-5.slh.3-sidux-686 root=UUID=306d94a5-107b-4c9e-ae03
    a159e18dc1c7 ro quiet vga=791
    initrd /boot/initrd.img-2.6.28-5.slh.3-sidux-686
    }
    EOF

    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).

    Make the file executable (it is a script, a type of program):
    sudo chmod 744 /etc/grub.d/ 41_sidux_sda3
    Or,
    sudo chmod +x /etc/grub.d/ 41_sidux_sda3
    Or, in GUI,
    As root, open Konqueror (kdesudo konqueror), access /etc/grub.d, right click on 41_sidux_sda3, Properties, and check the “Executable” box; check Advanced Permission while you are at it.

    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: Changing resolution, text colors, setting background image
    The default resolution is 640x480 and applies only to the GRUB 2 boot menu you see when you boot your PC. For changing graphical settings that apply to your boot menu, see kubicle, Post #30 below.

    Boot menu: Background image editing tip for those with widescreen monitors
    See oshunluvr, Post #36 below

    4 Ways To Boot an OS
    configfile, symlinks, direct booting, chainloader

    You can use these methods
    -- in a boot menu
    -- at a grub> prompt (at the GRUB CLI)
    to boot OSs. If you use them at the GRUB CLI, you must type the command boot at the end to make the methods symlinks, direct booting and chainloader work. You do not need the command boot in a configfile menu. You do not need the boot command in grub.cfg (it is implied there).

    NOTE: These are done the same as in GRUB Legacy but with a new format.
    But see the note on configfile below.

    NOTE: Each boot entry starts with a line
    menuentry "...some text..." {
    and ends with
    }

    >>> Configfile booting
    This is easy and flexible; however, there's a caveat:
    Both OSs must use the same version of GRUB--both the OS you are working in (where the main boot menu is kept) and the OS you are booting.

    For example, consider these two statements in a menuentry:
    set root=(hd1,2)
    configfile /boot/grub/grub.cfg

    An equivalent way of doing it is this:
    configfile (hd1,2)/boot/grub/grub.cfg

    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.

    When to avoid configfile
    When there is a mixture of GRUB versions on your PC, it is best to avoid using configfile.
    Instead, use chainloader or symlinks.

    Example (Taken from a grub.cfg. The # sign indicates a comment.)

    # Kubuntu 8.04.3 on sdb2, by configfile
    menuentry “Kubuntu 8.04.3 on sdb2, by configfile” {
    set root=(hd1,2)
    configfile /boot/grub/grub.cfg
    }


    >>> Symlinks used in a boot entry
    Symlinks are like shortcuts, and they direct control from the link to the file they point at. Symlinks for the kernel and initrd files are already set up for you. Look for yourself. List all files (-a) in long or detailed form (-l) under your root partition (/) by issuing the following command at Konsole:

    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

    menuentry “Kubuntu 9.10 on sda8, by symlinks” {
    set root=(hd0,8)
    linux /vmlinuz root=/dev/sda8 ro quiet splash
    initrd /initrd.img
    }

    or even simpler, when you can't remember the kernel options "ro quiet splash":

    menuentry “Kubuntu 9.10 on sda8, by symlinks” {
    set root=(hd0,8)
    linux /vmlinuz root=/dev/sda8
    initrd /initrd.img
    }

    (ro = Read-Only and is the default. Thanks to dibl for this information.)

    NOTE about the paths
    Notice the paths to the symlinks start at root / (since the symlinks are stored under root /); whereas the paths to the actual kernel & initrd files start at /boot (since the kernel and initrd are stored under /boot)

    Another Example

    # Kubuntu 9.10 on sdb7 symlinks, normal mode
    menuentry “Kubuntu 9.10 on sdb7, by symlinks” {
    set root=(hd1,7)
    linux /vmlinuz root=/dev/sdb7 ro quiet splash
    initrd /initrd.img
    }

    This is normal mode. If you want recovery mode (single user),
    replace the kernel options “ro quiet splash” with “ro single” (without quotes)


    >>> Direct booting
    In direct booting, you use the actual kernel and initrd file names in the boot menuentry.
    NOTE
    If you use direct booting at the GRUB CLI, ie., at grub> prompt, you may use TAB completion to make your job easier.
    For example,
    grub>linux /boot/<Press TAB key now>
    and you will get some choices, such as vmlinuz-2.6.24-24-generic

    Example

    # Kubuntu 8.04 on sdb3, direct booting
    menuentry "Kubuntu 8.04 on sdb3, direct booting" {
    set root=(hd1,3)
    linux /boot/vmlinuz-2.6.24-24-generic root=UUID=db287e84-cbdd-4ca1-8745-85241a3b3fe2 ro quiet splash
    initrd /boot/initrd.img-2.6.24-24-generic
    }


    >>> Chainloader booting
    When you boot an OS by chainloading, you use the chainloader command to pass control of the booting from your native GRUB to some other bootloader located in the MBR of a disk somewhere or in the
    boot sector of a partition.

    NOTE: For this to work, a bootloader must first be installed to the target MBR or a partition boot sector.

    A Linux example

    menuentry “Kubuntu 9.10 on sdb7, by chainloader” {
    set root=(hd1,7)
    chainloader +1
    }

    "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

    This is another way to write the same boot entry:
    menuentry “Kubuntu 9.10 on sdb7, by chainloader” {
    chainloader (hd1,7)+1
    }

    Another Linux example

    menuentry “Drive sdc = hd2 by chainloader” {
    chainloader (hd2)+1
    }

    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
    }


    Dedicated GRUB 2 Partition: How To Build It
    Again, this is straightforward, much easier than in GRUB Legacy.

    1 Create the GRUB 2 partition.
    Create a partition to be used as your dedicated GRUB 2 partition and format it. I use GParted Live CD to do this. At that time, you may if you wish, again using GParted, set a Label on your partition; e.g., “GRUB2” (without the quotation marks) (in GParted, use Partition > Labels).
    (Check the size of the /boot/grub folder to determine how big to make the partition. GRUB 2 files use just 572 KB (96 files, including 12 old ones) on my installation.)

    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."

    3 Install GRUB 2 to the MBR.
    From your Kubuntu OS, install GRUB 2 to the Master Boot Record (of your first BIOS boot drive) using GRUB 2 files set up in your dedicated GRUB 2 partition.
    Example
    Suppose sdb1 is your dedicated GRUB 2 partition, and assume it is mounted as /media/sdb1 (or, if you set the label GRUB2 on sdb1, this might be /media/GRUB2). And suppose you wish to install GRUB 2 to the MBR of sda which is set in BIOS to be your first boot drive.
    Do it this way:
    sudo grub-install –root-directory=/media/sdb1 /dev/sda
    (or, if it didn't work, try: sudo grub-install –boot-directory=/media/sdb1/boot /dev/sda)
    (That will also build the directory /boot/grub for you in your GRUB 2 partition.)

    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.

    Set the boot flag on the dedicated GRUB 2 partition:
    Do that using GParted either from your OS (K > System > Partition editor) or from the GParted Live CD. If you do it using the GParted Live CD, you might go this way now:
    After completing Step 4 (copying the grub.cfg file into the partition), put the GParted Live CD in the CD tray, let it be recognized, re-boot into GParted Live, set the boot flag on your dedicated GRUB 2 partition (Partition > Manage Flags), GParted > Quit, then double click GParted (large menu at top) to quit and re-boot, when prompted remove the GParted Live CD, and let the PC re-boot (and it will now be using your dedicated GRUB 2 partition), and see if it works.

    CAUTION: Remember to keep Super Grub Disk live CD handy.

    IMPORTANT NOTE ABOUT KERNEL UPDATES:
    Using this method of building a dedicated GRUB 2 partition, YOU are in charge of the boot configuration file /boot/grub/grub.cfg that is located in the GRUB 2 partition. The stuff we talked about above--/etc/default/grub and the scripts /etc/grub.d and grub-mkconfig--does not apply. You must keep these two "shows" separate. Edit the dedicated GRUB 2 file grub.cfg manually. If there ever is a problem, you may have to manually re-install GRUB 2 to the MBR (of the first BIOS boot drive) from the dedicated GRUB 2 partition.

    Example Here's my dedicated GRUB 2 /boot/grub/grub.cfg:

    # grub.cfg
    # This is my custom boot menu, called /boot/grub/grub.cfg, located in my dedicated Grub 2 partition sda1.

    # Set the timeout
    set timeout=10

    # Set the default boot entry.
    set default=0

    # Kubuntu 9.10 on sda8 by chainload
    menuentry "Kubuntu 9.10 on sda8, by chainload" {
    chainloader (hd0,8)+1
    }

    # Kubuntu 9.10 on sda8 by configfile
    menuentry "Kubuntu 9.10 on sda8, by configfile" {
    configfile (hd0,8)/boot/grub/cfg
    }

    # Kubuntu 9.10 on sda8 by symlink
    menuentry "Kubuntu 9.10 on sda8, by symlink" {
    set root=(hd0,8)
    linux /vmlinuz root=/dev/sda8 ro quiet splash
    initrd /initrd.img
    }

    # Kubuntu 8.04.3 on sda2, by configfile
    menuentry "Kubuntu 8.04.3 on sda2, by configfile" {
    configfile (hd0,2)/boot/grub.cfg
    }

    # sidux on sda3, by direct booting
    menuentry "sidux on sda3" {
    set root=(hd0,3)
    linux /boot/vmlinuz-2.6.28-5.slh.3-sidux-686 root=UUID=306d94a5-107b-4c9e-ae03-a159e18dc1c7 ro quiet vga=791
    initrd /boot/initrd.img-2.6.28-5.slh.3-sidux-686
    }


    GRUB 2 Flashdrive (USB flash drive)

    For the principles of installing GRUB 2, see the discussion under "Installing GRUB 2" and "The grub-install Command."

    Example

    I used a 1 GB Kingston; the GRUB 2 files used just 51 MB.
    Partition and format the flash drive as ext4 (or something else, using GParted Partition Editor). (You could also use FAT32 or ext3 or some other filesystem.)
    Set the boot flag on the newly created partition (use GParted to do that: Partition > Manage Flags).
    Exit GParted. Unplug the flashdrive, then plug it in.

    In Kubuntu, to see how it is named, at Konsole run
    sudo fdisk -lu
    Output:
    Disk /dev/sdb: 1031 MB, 1031798784 bytes
    255 heads, 63 sectors/track, 125 cylinders, total 2015232 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Disk identifier: 0x000f0fe1
    Device Boot Start End Blocks Id System
    /dev/sdb1 63 2008124 1004031 83 Linux

    Konqueror (or Dolphin) indicated it is mounted as /media/disk.

    => So it is seen as sdb with the partition sdb1 mounted as /media/disk.

    Install GRUB 2 to the flash drive. At Konsole:
    sudo grub-install --root-directory=/media/disk /dev/sdb (Tested January 2014)
    (or, if it didn't work, try: sudo grub-install --boot-directory=/media/disk/boot /dev/sdb)
    Output:
    Installation finished. No error reported.
    This is the contents of the device map /media/disk/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
    (hd1) /dev/sdb

    (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

    Thus, I booted into Kubuntu using the GRUB 2 flash drive.

    Building a boot menu for the flash drive:
    You can create a text file /boot/grub/grub.cfg for the flash drive exactly as demonstrated under building a Dedicated GRUB 2 Partition. Or, try:
    sudo grub-mkconfig -o /media/disk/boot/grub/grub.cfg

    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.

    [End of the flashdrive subsection]


    Use of the Term "root"
    GRUB's Root Device, the Linux statement, root=UUID=, --root-directory=DIR INSTALL_DEVICE

    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

    Files Master image files: /usr/lib/grub/i386-pc/
    boot/grub/grub.cfg Configuration file for the boot menu. Do NOT edit.
    /etc/default/grub Default settings file (Timeout, Default OS, kernel options)
    /etc/grub.d Folder of boot menu scripts:
    00_header; 05_debian_theme: Background, text colors, themes
    10_hurd Locates Hurd kernels; 10_linux Locates Linux kernels; 20_memtest86+
    30_os-prober: Searches for Linux and other OS's on all partitions
    40_custom: Template for custom boot menu entries
    More files: /boot/grub/device.map, boot.img (MBR), core.img

    Fixing Things, Rescue
    Ctrl+Alt+Del reboot PC; Super Grub Disk
    New grub.cfg: sudo grub-mkconfig -o /boot/grub/grub.cfg (or, sudo update-grub)
    Install, re-install GRUB 2: sudo grub-install [INSTALL_DEVICE]
    to MBR: sudo grub-install /dev/sdx; to partition: sudo grub-install /dev/sdxn
    If error: grub-install --recheck /dev/sdx; sudo grub-install --recheck /dev/sdxn
    Install GRUB 2 to MBR of sda using GRUB 2 in /dev/sdb1/boot/grub:
    sudo grub-install –root-directory=/media/sdb1 /dev/sda
    (or, a new way: sudo grub-install –boot-directory=/media/sdb1/boot /dev/sda)
    Install GRUB 2 to PC (/usr/lib/grub/i386-pc/): sudo apt-get install grub-pc

    Live CD rescue: Re-install GRUB 2
    sudo mkdir /media/sda2
    sudo mount /dev/sda2 /media/sda2
    Install GRUB 2 to MBR of sdb [or to partition sda2] using GRUB 2 files in sda2:
    sudo grub-install --root-directory=/media/sda2 /dev/sdb [or /dev/sda2]
    (or, using --boot, try: sudo grub-install --boot-directory=/media/sda2/boot /dev/sdb [or /dev/sda2])
    umount /media/sda2

    Drives, partitions, information sudo fdisk -lu & grub>ls
    Naming: (hdx,y) or sdzy: drive x starts at 0; partitions y start at 1
    Konsole: sudo fdisk -lu; df -hT; mounting: cat /etc/mtab; or: mount
    UUIDs: sudo blkid; ls /dev/disk/by-uuid/ -alh
    Kernel ver: uname -r; cat /proc/version; Linux ver: lsb_release -a
    sudo grub-emu and then grub>ls (if grub-emu is installed and works)
    GRUB devices/drives: grub>ls; grub>ls -al directory
    UUID of (hdx,y): grub>ls (hdx,y)
    Finding: grub>search /boot/grub/grub.cfg; grub>search /boot/grub/boot.img

    Syntax, booting choices
    configfile: set root=(hdx,y) and configfile /boot/grub/grub.cfg; or:
    configfile (hdx,y)/boot/grub/grub.cfg
    symlinks: linux /vmlinuz root=UUID= xxx ro quiet splash; initrd /initrd.img
    symlinks: linux /vmlinuz root=/dev/sdxn ro quiet splash
    chainload: set root=(hdx,y) and chainloader +1; chainloader (hdx,y)+1
    chainload a MBR: chainloader (hdx)+1

    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

    Create a script called /etc/grub.d/NN_myscript
    Empty text doc: kdesudo kate; File > Save As /etc/grub.d/NN_myscript
    Type it (see template below).
    Make executable: sudo chmod 744 /etc/grub.d/NN_myscript
    or, sudo chmod +x /etc/grub.d/NN_myscript
    GUI: kdesudo konqueror (dolphin), rt-click, Properties, Permissions
    Make new grub.cfg: sudo grub-mkconfig -o /boot/grub/grub.cfg

    > Template, custom boot entry for file /etc/grub.d/NN_name
    #!/bin/sh
    echo "Adding name" >&2
    cat << EOF
    menuentry "name of OS boot entry" {
    set root=(hdx,y)
    linux /boot/vmlinuz-xyz root=UUID=xxx
    initrd /boot/initrd.img-xyz
    }
    EOF

    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

    Separate GRUB 2 partition: mounted at /media/sdb1; sda=MBR of 1st BIOS drive
    sudo grub-install –root-directory=/media/sdb1 /dev/sda

    Working as root (8.10+: kdesudo; 8.04: kdesu)
    kdesudo kate /path-to-file; kdesudo konqueror (or dolphin)
    Terminal as root: sudo –i; sudo su
    GUI file manager, navigate to file, right-click on file, Actions, Edit as Root.
    sudo [COMMAND]; sudo grub-install [INSTALL_DEVICE];
    sudo grub-mkconfig -o /boot/grub/grub.cfg

    To search the Kubuntu forum using google:
    site:kubuntuforums.net "additional drivers" + sound -Windows

    [End of GRUB 2 Practical Reminders]

    = = = = = = = = = = = = = = = = = = = =
    = = = = = = = = = = = = = = = = = = = =
    Appendix: Techniques

    --- Removing old kernels so they don't take up space and so your grub.cfg boot menu isn't so long

    --- Installing Kubuntu--GRUB 2 placement: Placed at the end of Post #2
    --- Working as root: Placed at the end of Post #2
    --- Permissions: read, write, execute; change the execute bit: Placed at the end of Post #2
    -->>> For command line (CLI) methods, see my how-to:
    Commands at Konsole: Beginners
    https://www.kubuntuforums.net/showth...sole-Beginners


    - - - - - - - - - -
    Removing old kernels so they don't take up space and so your grub.cfg boot menu isn't so long

    Basically:

    Pick a method (CLI or using a package manager (Muon, Synaptic)), remove unwanted kernel packages.
    Then to generate a new /boot/grub/grub.cfc, run sudo update-grub or sudo grub-mkconfig.

    Using a package manager:
    Simply search for the main version number. For example, consider kernels 3.2.0-x, where x may be various kernel versions in some range, like from x=23 to 60. In Muon, simply search for 3.2.0- , and all the "x's" will come up.
    For each kernel, there may be two, three, or four associated packages. For example (hypothetical):

    linux-headers-3.2.0-57 (header files)
    linux-headers-3.2.0-57-generic-pae (additional kernel headers depending on kernel type)
    linux-image-3.2.0-57-generic-pae (kernel image)
    linux-image-extra-3.2.0-57-generic-pae (extra image)

    In Muon, Highlight these, right-click, select purge. (Credit to: Smimapan)

    Afterwards, update grub.cfg with sudo update-grub or sudo grub-mkconfig.
    - - - - -

    Rog131, How-to: several ways, mainly using package managers:
    https://www.kubuntuforums.net/showth...ll=1#post65529

    kubicle:
    Actually, removing a kernel image package frees over 100Mb (it's not just the image, the package installs a good number of firmware and modules in /lib/firmware/{kernel} and /lib/modules/{kernel})
    If you also had the headers package installed and removed it, the total freed space is around 200Mb per kernel.
    https://www.kubuntuforums.net/showth...l=1#post235269

    Several methods suggested here:
    https://www.kubuntuforums.net/showth...l=1#post292951

    JontheEchidna:
    You can install kde-config-grub2 which provides a System Settings module that can do this for you.
    Afterwards, you will need to navigate to the Startup and Shutdown settings in System Settings, System Admin, Startup and Shutdown. If you go to the "GRUB2 Bootloader" section in the Startup section, you'll see a button that says "Remove Old Entries". After clicking this, it will find all kernel entries. You should then mark all but the one you're using, and it'll remove them for you. (Be careful, the list includes the kernel currently in use also)
    https://www.kubuntuforums.net/showth...l=1#post293021

    Kubicle:
    You can safely remove unneeded (old) kernel images with synaptic, the kernel image packages are called 'linux-image-<version>'.
    https://www.kubuntuforums.net/showthread.php?39323-How-to-delete-old-config-initrd-vmcoreinfo-and-vmlinuz-files&p=171496&viewfull=1#post171496

    oshunluvr:

    Launch your choice of package managers and remove the image and kernels that you don't want.
    I use synaptic, so I'd type in the version number in the search bar and remove the 2 or 3 files associated with that version, in your case 2.6.32-21, -22, and -23 are the likely candidates.
    When you install a new kernel, the old one is NOT removed automatically because the new just may not work, thus leaving your system unbootable. I always leave one old kernel that I am sure works just in case.
    Basically, for every kernel that you don't want anymore, remove the following three files:
    linux-headers-<version>
    linux-headers-<version>-generic
    linux-image-<version>-generic
    https://www.kubuntuforums.net/showthread.php?49916-SOLVED-Delete-old-updates-from-GRUB&p=235159&viewfull=1#post235159

    Steve Riley:
    A typical kernel image package will place:
    * firmware modules in subdirectories beneath /lib/firmware/kernel-version
    * driver modules in subdirectories beneath /lib/modules/kernel-version
    * the kernel and support files in /boot
    Manually deleting the files from /boot won't remove the associated firmware and driver modules. You might want to check in those subdirectories, too.
    https://www.kubuntuforums.net/showthread.php?58075-remove-old-linux-versions&p=293690&viewfull=1#post293690

    Shimapan:
    https://www.kubuntuforums.net/showth...l=1#post309742


    = = = = = = = = = = = = = = = = = = = =
    = = = = = = = = = = = = = = = = = = = =

    References and Tutorials

    GRUB 2 References, Tutorials, Special Topics

    Official GRUB 2 Manual
    http://www.gnu.org/software/grub/manual/grub.html
    Also, in a terminal: info -f grub -n 'Simple configuration'

    Note: Ubuntu versus Kubuntu tutorials
    A GRUB 2 tutorial written for Ubuntu applies to Kubuntu. Watch for obvious differences in a few commands and OS tools. In Ubuntu you will see
    gksudo gedit /boot/grub/grub.cfg
    used for opening grub.cfg as root using text editor gedit.
    In Kubuntu, you would use
    kdesudo kate /boot/grub/grub.cfg.
    In Kubuntu, you will probably use Konqueror or Dolphin as your file manager. Also, there are different package managers used in each OS, even within the same OS at times. I think you'll be able to sort it out, and you can always post questions under one of the regular Kubuntu forums.
    >>> The GRUB commands are the same in both Ubuntu and Kubuntu and other Linux OSs.

    Removing Old Kernels -- see Appendix above, immediately preceding References.
    - - - - -

    GUI packages to help you change/repair your GRUB 2 setup/options:

    GRUB2 Editor
    A KDE Control Module for configuring the GRUB2 bootloader
    http://sourceforge.net/projects/kcm-grub2/

    Boot-Repair
    https://help.ubuntu.com/community/Boot-Repair

    Boot-Info (gives you a diagnostic report on your system)
    https://help.ubuntu.com/community/Boot-Info

    kde-config-grub2

    Grub Customizer
    http://ubuntuforums.org/showthread.php?p=10340183#post10340183

    UNetbootin - Homepage and Downloads
    http://unetbootin.sourceforge.net/
    Makes a bootable USB thumb drive for you, using your distro or using an iso.

    -- The Appendix continues at the end of Post #2 below --

    -- More References are also placed at the end of Post #2 --
    Last edited by Qqmike; Sep 27, 2015, 03:43 PM.
    An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

    #2
    Re: GRUB 2, continued from Post #1

    GRUB 2, continued from Post #1
    This post is a continuation of the GRUB 2 Guide. SECTION numbers refer to the original (first) post above: GRUB 2 Guide.

    Current CONTENTS:

    SECTION numbers refer to the original (first) post above.

    CONTENTS, brief:
    -- Notes about some of the new GRUB 2 commands
    -- Dual booting: How to set it up
    -- PROBLEMS -- booting
    -- Windows Topics -- booting
    --> drivemap command: XP on a non-first hard drive
    -- Boot From ISO -- use of GRUB 2 loopback
    -- GPT: GUID Partition Table
    -- UEFI issues, GPT, Secure Boot, links


    Need UEFI help? Steve's introductory comments:
    https://www.kubuntuforums.net/showth...Need-UEFI-help
    and ...
    The threads under Miscellaneous Linux Info > Need UEFI help?:
    https://www.kubuntuforums.net/forumd...EFI-assistance

    PLease note --
    Placed at the end of this post are the following:

    Appendix Topics (continued from Post #1):

    Installing Kubuntu--GRUB2 Placement, Working as Root, Permissions
    -->> Or, instead, for command line (CLI) methods, see my how-to:
    Commands at Konsole: Beginners
    https://www.kubuntuforums.net/showth...sole-Beginners

    Also placed at the end of this post:
    more GRUB 2 References, Tutorials, Special Topics

    ------------------------------
    CONTENTS, expanded:

    Notes about some of the new GRUB 2 commands
    Included here: chainloader, ls, grub-emu, grub-mkconfig (many tips!), root, rootnoverify (is gone), grub-setup
    grub-install: See SECTION 4 above.
    drivemap replaces map
    See Section 4 above: Booting XP on a non-first hard drive: The drivemap command
    See Post #17 (below) in this thread.
    loopback
    See below: Boot From ISO -- use of GRUB 2 loopback

    Dual booting: How to set it up
    Installing two or more Linux operating systems
    RECOMMENDED METHOD
    Subsection:
    PROBLEMS -- booting
    Messing up the booting -- fixing GRUB without re-installing Kubuntu

    Windows Topics -- booting
    Installing XP (or 7? or Vista?) & Kubuntu:
    How to set up dual booting (recommended outline)
    Re-installed XP and now can't boot Kubuntu
    XP on a non-first hard drive: (hdx,y), x > 1
    Subsection:
    Booting XP on a non-first hard drive
    The drivemap command in GRUB 2
    --Lots of technical notes here--

    Boot From ISO -- use of GRUB 2 loopback
    Boot your Kubuntu Live CD ISO from your flashdrive

    GPT: GUID Partition Table
    ... for Kubuntu 9.10 and GRUB 2

    => Overcoming the "2 TB disk size limit" associated with the conventional MBR
    => Get rid of the Extended partition with its linked list of Logical partitions
    (Have as many partitions as you want)
    => Testing GRUB 2 on your GPT-partitioned flash drive

    UEFI issues, GPT, Secure Boot, links: see the last topic below
    Need UEFI help? Steve's introductory comments:
    https://www.kubuntuforums.net/showth...Need-UEFI-help
    and ...
    The threads under Miscellaneous Linux Info > Need UEFI help?:
    https://www.kubuntuforums.net/forumd...EFI-assistance

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Notes about some of the new GRUB 2 commands
    Included here: chainloader, ls, grub-emu, grub-mkconfig (many tips!), root, rootnoverify (is gone), grub-setup
    grub-install: See SECTION 4 above.
    drivemap replaces map
    See Section 4 above: Booting XP on a non-first hard drive: The drivemap command
    See Reply #17 (below) in this thread.
    loopback
    See below: Boot From ISO -- use of GRUB 2 loopback

    chainloader --force
    is used to skip the check for the end-of-file (EOF) boot sector signature 0xaa55.
    For valid bootsectors, it shouldn't be needed; e.g. it shouldn't be needed with a valid windows bootsector.

    The ls command
    geometry is gone and replaced by ls
    The ls command is very useful: See Section 4:
    How to get information about your drives and devices
    Key commands:
    At Konsole : sudo fdisk -lu
    At the GRUB 2 prompt: grub> ls

    grub-emu (assuming it is installed and it is working)
    sudo grub-emu will get you into a GRUB 2 emulator (within your Kubuntu).
    To get out, type
    exit
    Tip:
    It's useful to use sudo grub-emu then use ls to see how GRUB 2 is seeing your drives and partitions.

    * * * * * *
    grub-mkconfig: Tips about using it

    grub-mkconfig
    is a GRUB 2 command for generating a new boot configuration file /boot/grub/grub.cfg
    An earlier version was called update-grub. The command update-grub has been replaced by grub-mkconfig (mkconfig = "make configuration file").
    If you run
    update-grub --help
    or
    grub-mkconfig --help
    you will get the same output based on the command file
    /usr/sbin/grub-mkconfig

    Note: update-grub
    The command update-grub generatesa 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.

    Using grub-mkconfig correctly: -o option, or --output=FILE
    grub-mkconfig --help
    tells you.

    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

    grub-mkconfig Detecting other OSs
    grub-mkconfig automatically runs os-prober to detect other OSs on your PC (assuming os-prober is installed, which it will be in any normal installation).

    grub-mkconfig: Is grub.cfg in sync with core.img?
    => Run first: grub-install
    To be sure you get the best and the correct grub.cfg file, especially if there's been a change/update to core.img, it would be safe to run
    sudo grub-install
    before running
    sudo grub-mkconfig -o /boot/grub/grub.cfg

    * * * * * *

    root is still used but is now a variable
    In GRUB 2, you assign a value to a variable using the set statement; e.g.:
    set root=(hd2,3)
    and you may reference the variable root by ${root}:
    configfile ${root}/boot/grub/grub.cfg

    rootnoverify (was a GRUB Legacy command)
    isn't needed anymore in GRUB 2 because root is now a variable
    and not a command. (So, "rootnoverify" is default behavior now.)

    grub-setup
    is an advanced tool and should not be used manually.
    You should only have to use
    grub-install
    for your work. grub-install automatically calls grub-setup for you.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Dual booting: How to set it up

    Installing two or more Linux operating systems
    > Recommended method
    > Problems – messing up the booting; fixing GRUB without re-installing Kubuntu
    > This applies to using one or more hard drives
    > If your situation involves Windows, see “Windows topics” below

    An important, key fact:
    The GRUB from the last OS you install overwrites any existing GRUB you already have installed.

    => When you have an existing Linux OS already installed, call it Linux1, and then install a second Linux OS, call it Linux2, the GRUB from Linux2 will overwrite the GRUB from Linux1 that is installed in the MBR of the first BIOS boot drive (hd0). If that happens, then the booting will be controlled not by the GRUB and boot menu from Linux1, but from the GRUB and boot menu (/boot/grub/grub.cfg) of Linux2. Knowing this, you can decide how you want to control things. For example, you can ensure that the GRUB from Linux2 does NOT overwrite the GRUB from Linux1.

    Telling the installer where to install GRUB
    See Appendix topic: Installing Kubuntu--GRUB 2 placement
    >>> Other distros may have their own facilities for installing GRUB.


    RECOMMENDED METHOD
    Setting up a dual boot between two Linux OSs
    I will outline one (of many) methods for setting up a dual boot between two Linux OSs, call them Linux1 and Linux2.

    Set up BIOS boot drives
    Start you PC, enter BIOS setup, and set BIOS to boot FIRST from the CD drive; second from your first BIOS boot drive (the one you prefer to use for such).

    Step 1 Partitioning your hard drive(s) for both OSs
    Decide how to partition your hard drive(s) for the two OSs.
    Then do the partitioning using GParted Live CD (a very handy tool):
    http://gparted.sourceforge.net/livecd.php
    Or ...
    You can do it using the Live Kubuntu (or other Linux) CD: Run the CD as a Live CD (without installing anything).
    Check whether gparted is already available: K > System > Partition Editor (if so, open it).
    If not, install it in your live session using K > System > [your package manager: synaptic, KPackageKit, Muon, etc.] Then open it and use it (K > System > [Partition Editor]).

    Step 2 Explore your hard drive(s)
    Before running the installer, but while in a Live Kubuntu CD session (or Live Linux 1 session), explore your hard drives to determine how GRUB sees the partitions you set up in Step 1.
    See "How to get information about your drives and devices" in SECTION 4 using sudo fdisk -lu and the GRUB 2 ls command. (Note: To use ls, get a GRUB prompt: sudo grub-emu, then grub>ls)
    Write down the key partitions you will use for root, home, swap.
    => Identify in both Linux notation (sdXN's) and GRUB notation (hd(x,y)'s) where everything goes--the Kubuntu root filesystem (/), swap, (and /home, if you wish to have a separate partition for /home).
    Swap: You only need to reserve one partition for swap, even if you have more than one Linux OS.

    Step 3 Run the Linux 1 installer to install the first OS
    Install Linux1. Let the installer put GRUB in (hd0) – that is usually the default location.
    Thus, your PC will boot from hd0 using GRUB from Linux1 installed to the MBR and the boot menu (/boot/grub/grub.cfg) from Linux1.

    Step 4 Run the Linux 2 installer to install the second OS
    ... and Install GRUB carefully
    Install Linux2. But be careful where you install GRUB.

    > If you want the GRUB (and boot menu) from Linux1 to continue to control the booting, then * be careful * to NOT install GRUB to (hd0). Instead, install GRUB to the root partition of Linux2; or, to the MBR of some other drive, like (hd1) or (hd2)--assuming you feel it is safe to do so.
    > If you want GRUB (and the boot menu) from Linux2 to control the booting, then install GRUB to (hd0); in that case, the GRUB from Linux2 will overwrite GRUB from Linux1 in the MBR.

    Step 5 Configure GRUB
    > If the Linux1 GRUB is to control the booting (and so you did NOT have the Linux2 installer put GRUB in (hd0)), then you want the boot menu (/boot/grub/grub.cfg) in Linux1 to include a boot stanza entry for Linux2. Boot into Linux1, open Konsole, issue this command:
    sudo grub-mkconfig /boot/grub/grub.cfg
    Check /boot/grub/grub.cfg to see that it now includes a boot entry for Linux2. If it does not, then try to re-install GRUB to the MBR of hd0 using the GRUB 2 from Linux1--See SECTION 3 (also note the use of --recheck if you get an error). Check /boot/grub/grub.cfg to see that it now includes a boot entry for Linux2. If it does not, then see SECTION 4: "Boot menu: Create a custom boot entry" and "4 ways to boot an OS: configfile, symlinks, direct booting, chainloader."
    > If the Linux2 GRUB is to control the booting (and so you DID have the Linux2 installer put GRUB in (hd0)), then you should not have to do any further configuring of GRUB--the new Linux2 boot menu (/boot/grub/grub.cfg in Linux2) should already have an entry in it for booting Linux1. If not, boot into Linux2 and issue, at Konsole, command:
    sudo grub-mkconfig /boot/grub/grub.cfg
    If the /boot/grub/grub.cfg in Linux2 still does not include an entry for Linux1, then try grub-install (possibly with --recheck, see SECTION 3). If the /boot/grub/grub.cfg in Linux2 still does not include an entry for Linux1 see SECTION 4: "Boot menu: Create a custom boot entry" and "4 ways to boot an OS: configfile, symlinks, direct booting, chainloader."

    - - - - - - - - - -
    PROBLEMS
    Messing up the booting -- fixing GRUB without re-installing Kubuntu

    If you make a mistake with GRUB while installing the OSs, you can fix it without re-installing the OS.
    See SECTION 3 ("Re-installing GRUB 2").

    Example: Re-setting Linux1 to control the booting
    Suppose in setting up the dual boot with Linux1 and Linux2 that you mistakenly overwrote the MBR with the GRUB from Linux2. To restore the Linux1 GRUB to the MBR of hd0 (the first BIOS boot drive), simply re-install GRUB 2 using the GRUB files in Linux1 (see SECTION 3). Then, as above, configure /boot/grub/grub.cfg (in Linux1) so it includes a boot entry for Linux2.
    > Let's assume Linux1 is in partition sdxn. Also, suppose the BIOS boot drive hd0 is sdz. Then re-install GRUB to the MBR of hd0 using the GRUB in Linux1 as follows:
    Use "Re-installing GRUB 2 using Live CD: Key Rescue Method" of SECTION 3.
    Or
    Use Super Grub Disk to boot into Linux1 to fix the problem
    (reinstall GRUB 2: sudo grub-install)
    Or (also see SECTION 3, "sudo grub-install"):
    Boot into Linux2, see how sdxn is mounted (check your file manager; e.g., Dolphin or Konqueror); suppose it is /media/sdxn. Open Konsole, issue:
    sudo grub-install --root-directory=/media/sdxn /dev/sdz
    If that fails, try
    sudo grub-install --recheck --root-directory=/media/sdxn /dev/sdz
    You should now be able to re-boot into Linux1 to check that its /boot/grub/grub.cfg includes a boot entry for Linux2. If not, see Step 5: Configure GRUB.

    Example: Re-setting Linux2 to control the booting
    Or, if you wanted the GRUB from Linux2 (and its /boot/grub/grub.cfg) to control the booting, but you did not have its GRUB installed to the MBR of the first BIOS boot drive, (hd0), then reinstall GRUB from Linux2 (to the MBR (hd0)) and configure the Linux2 grub.cfg to include a boot entry for Linux1.
    > Let's assume Linux2 is in partition sdxn. Also, suppose the BIOS boot drive hd0 is sdz. Then re-install GRUB to the MBR of hd0 using the GRUB in Linux2 as follows:
    Use "Re-installing GRUB 2 using Live CD: Key Rescue Method" of SECTION 3.
    Or
    Use Super Grub Disk to boot into Linux2 to fix the problem
    (reinstall GRUB 2: sudo grub-install)
    Or (also see SECTION 3, "sudo grub-install"):
    Boot into Linux1, see how sdxn is mounted (check your file manager; e.g., Dolphin or Konqueror); suppose it is /media/sdxn. Open Konsole, issue:
    sudo grub-install --root-directory=/media/sdxn /dev/sdz
    If that fails, try
    sudo grub-install --recheck --root-directory=/media/sdxn /dev/sdz
    You should now be able to re-boot into Linux2 to check that its /boot/grub/grub.cfg includes a boot entry for Linux1. If not, see Step 5: Configure GRUB.


    Windows topics -- Tested with XP only

    Installing XP (or 7? or Vista?) & Kubuntu: How to set up dual booting (recommended outline)

    1 Install XP first, and install it to the first partition of your hard drive.
    2 Decide how you want to partition for Kubuntu:
    3 Prepare the partitions for Kubuntu using GParted live CD from here:
    GParted: http://gparted.sourceforge.net/
    Or, do it using gparted from the Live Kubuntu CD.
    4 Install Kubuntu
    The Kubuntu installer will install GRUB to the MBR of the HD, and thus it overwrites the XP bootloader that XP installed in the MBR of that HD. If you do not want that to happen, you will have to use XP's bootloader to load Linux.
    5 When you re-boot your PC, you will see the GRUB boot menu offering you the choice to boot into either XP or Kubuntu.

    Re-installed XP and now can't boot Kubuntu
    Suppose you had a dual boot set up with XP and Kubuntu, but then you re-installed XP, XP's bootloader overwrote GRUB in the MBR, and now you can't boot into Kubuntu. To fix this, simply re-install GRUB (using the GRUB files in Kubuntu) to the MBR of the first BIOS boot drive (hd0). See SECTION 3 (Reinstalling GRUB) above.

    XP on a non-first hard drive: (hdx,y), x > 1
    Suppose Kubuntu is on your first BIOS boot drive hd0, and GRUB (from Kubuntu) is installed to the MBR (hd0); thus, your PC boots from hd0 using GRUB. Later, you wish to install Windows on a second hard drive, (hd1), and you wish to set things up so GRUB controls the booting through its boot menu. (Or, perhaps Windows was there first, then you install Kubuntu, but you want the PC to boot first from the Kubuntu HD.) Thus Windows will be on a non-first hard drive (a hard drive other than the first BIOS boot drive). Windows does not like booting from a non-first hard drive. Worse than that, so I've read, the real problems occur when Windows is updated in certain ways; if it is on a non-first HD, the booting may get messed up. Nonetheless, you can perform a virtual switch of hard drives using the GRUB drivemap command in the boot entry for Windows. No physical change is made to the hard drives or to the operating systems.

    See the following section titled "Booting XP on a non-first hard drive: The drivemap command in GRUB 2."

    => => Fact is, you might be able to use the GRUB 2 utility grub-mkconfig or grub-install to do this work for you: they might detect Windows properly and adjust for Windows being on a non-first HD (by implementing the drivemap commands automatically). (For the commands grub-mkconfig and grub-install, see Notes about some of the new GRUB 2 commands (in Reply #1 above); also see SECTION 3: Fixing Things)


    Booting XP on a non-first hard drive
    The drivemap command in GRUB 2

    In-progress (since GRUB 2 is not yet finalized).
    I will present you with safe options that will not harm your GRUB 2 or dual-booting setup.

    For a more compact Method 2 and for technical notes and other useful details about how drivemap works, see Reply #17. (Later, Reply # 17 may be incorporated here.)

    The Quick-and-Dirty Solution

    Method 1
    To boot Windows XP installed to (hd1,1), use the following menuentry (in a script you write as a text file (and make executable) in the folder /etc/grub.d):

    # Method 1 -- a safe, sure way to do it
    # This method applies to Windows and to FreeDOS
    # Windows XP on sdb1 (= (hd1,1)
    menuentry “Windows XP on sdb1, by chainloader” {
    drivemap (hd0) (hd1)
    drivemap (hd1) (hd0)
    set root=(hd0)
    chainloader (hd1,1)+1
    }

    => The drivemap command in GRUB 2 replaces the map command in GRUB Legacy.
    => That's all you need to know to make your grub.cfg work.

    => => Fact is, you might be able to use the GRUB 2 utility grub-mkconfig or grub-install to do this work for you: they might detect Windows properly and adjust for Windows being on a non-first HD (by implementing the drivemap commands automatically). (For the commands grub-mkconfig and grub-install, see Notes about some of the new GRUB 2 commands (in Reply #1 above); also see SECTION 3: Fixing Things)

    Technical notes

    -- The drivemap command in GRUB 2 replaces the map command in GRUB Legacy.

    -- You should use an up-to-date version of GRUB 2 (1.97xx). You can get it from 9.10 Karmic.

    -- The switch -s should also work:

    # Method 1 -- a safe, sure way to do it
    # This method applies to Windows and to FreeDOS
    menuentry “Windows XP on sdb1, by chainloader” {
    drivemap -s (hd0) (hd1)
    set root=(hd0)
    chainloader (hd1,1)+1
    }

    where the line
    drivemap -s (hd0) (hd1)
    means:
    drivemap (hd0) (hd1)
    drivemap (hd1) (hd0)

    -- If doing this at the GRUB CLI (grub>), you must (always) issue the boot command as your last command, in this case after the chainloader command:
    drivemap -s (hd0) (hd1)
    set root=(hd0)
    chainloader (hd1,1)+1
    grub>boot


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Boot From ISO -- use of GRUB 2 loopback
    Boot your Kubuntu Live CD ISO from your flashdrive

    GRUB 2 includes a new command, loopback. Use loopback to make a device from a file.

    Example Flash drive boot from ISO
    We'll put the Kubuntu Live CD iso file on a USB flash drive and boot the live OS from the iso on the flash drive. So, when done, you will boot your PC from the USB flash drive, get a boot menu, select an option corresponding to your Kubuntu Live CD iso file (which will be located on your flash drive), and you will then be booted into a Live Kubuntu session (corresponding to that iso).

    Do this work in your Kubuntu 9.10 OS.

    Steps:
    -- Prepare the flash drive (partition and format)
    -- Install GRUB to the flash drive and make a grub.cfg
    -- Copy the Kubuntu iso file to the flash drive
    -- Reboot to test it

    As follows:

    -- Prepare the flash drive
    Use GParted Live CD (or use gparted from your Kubuntu OS) to partition and format the flash drive. Make two partitions:
    Partition #1: ext3, 30 MB Label = GRUB2
    Partition #2: ext3, 850 MB Label = Kubuntu910Live
    (Make the second partition big enough to hold your iso file.)

    Notes
    1 To set a Label on a partition in GParted: Partition > Label.
    2 If your flash drive doesn't have a standard partition table on it, use GParted to set one up: Device > Partition Table, and choose the default MSDOS type.
    3 If you wish to clean up a flash drive before using it, write zeros to the entire thing. Use sudo fdisk -lu to see how it is named (e.g., sda, sdb, etc.), then use dd. Example: if it is named sdc, then open Konsole,
    sudo dd if=/dev/zero of=/dev/sdc
    will write zeros to every bit on the flash drive. It may take awhile, just let it run until it prints out the result.

    -- Install GRUB 2 In partition 1, set up GRUB 2 files and install GRUB 2 to the Master Boot Record of the flash drive using the GRUB 2 files in partition 1, and then make a boot menu /boot/grub/grub.cfg.

    At Konsole, use
    sudo fdisk -lu
    to find out how the flash drive is named. In our example, we assume it is sdc, with partitions sdc1 and sdc2.

    The following command sets up the GRUB 2 files in sdc1 assuming the first partition (/dev/sdc1) is mounted as /media/GRUB2 (in your Kubuntu OS) and then installs GRUB2 bootloader code to the MBR of sdc:
    sudo grub-install --root-directory=/media/GRUB2 /dev/sdc
    Note that the command will first make the directories /boot and /boot/grub in sdc1 (assuming they are not already set up in sdc1), and then it fills /boot/grub with GRUB 2 files.

    Boot menu: /boot/grub/grub.cfg
    Make the text file grub.cfg and copy it to /boot/grub.
    Your grub.cfg will be the following:

    set timeout=5
    set default=0

    menuentry "Kubuntu 9.10 Live from ISO on flash drive" {
    loopback loop (hd0,2)/kubuntu-9.10-desktop-i386.iso
    set root=(loop)
    linux /casper/vmlinuz boot=casper iso-scan/filename=/kubuntu-9.10-desktop-i386.iso
    initrd /casper/initrd.lz
    }

    Notes
    > Flash drive partitions sdc1 and sdc2. sdc1 = GRUB2 and contains /boot/grub. sdc2 = K910Live and contains kubuntu-9.10-desktop-i386.iso. When the PC boots from the flash drive, the partition sdc2 (where the iso file is) will be seen by BIOS and by GRUB 2 as (hd0,2). Before the loopback statement is executed, the path of the iso file is (hd0,2)/kubuntu-9.10-desktop-i386.iso. After the loopback statement (and the iso file is mounted as a device), the root directory is / (=(hd0,2)/), and the iso file is directly under /; so the kernel sees the path as /kubuntu-9.10-desktop-i386.iso.
    > Using the loopback command, you do not need to unpack and extract the kernel (vmlinuz) and the initrd (initrd.lz) files. Everything is handled automatically.


    -- Copy the iso file to the second partition
    In our case, we copy the iso file kubuntu-9.10-desktop-i386.iso to sdc2 (labeled as Kubuntu910Live).

    -- Reboot to test it
    Leave the flash drive plugged in (but Safely Remove it), close out your Kubuntu programs, re-boot, enter BIOS setup, configure your BIOS to boot from USB and place the flash drive at the top of the boot list, save these changes to BIOS and exit, and let your PC re-boot from the flash drive and start your Kubuntu Live session from the iso file (kubuntu-9.10-desktop-i386.iso).

    You're done.


    Extensions, Tips

    1 Include more iso files on the flash drive
    You can add more iso files to partition 2; of course, you'll need enough room on your flash drive to do so. For each live CD you wish to boot from its iso file, make a boot menu entry and include it in the grub.cfg you already built for "Kubuntu 9.10 Live from ISO on flash drive."
    The trick is the linux line and the initrd file: sometimes you need more kernel parameters in the linux line (and you get them by googling, asking, experimenting, and copying); and you need to know the name of the initrd file (initrd.lz in our example) ...

    Peek into the iso file without burning a CD ...
    You can look at the files contained in an iso file without burning the iso to a CD. For this, see another how-to:
    Commands at Konsole: Beginners
    https://www.kubuntuforums.net/showth...sole-Beginners


    Part 3
    -- Extract files from an .iso without burning the CD
    (You will not extract anything for our purposes here--just have a look at what's inside the iso, specifically, the kernel, initrd, and perhaps the isolinux.cfg file to see if you can find any linux kernel boot parameters).

    2 Use the method to boot a Live OS from its iso located on a hard drive (e.g., the iso might be located in your regular Kubuntu /boot directory, or on another partition). Here, you would boot your PC as usual, letting your normal boot menu appear, then you'd select a menuentry corresponding to an iso file located on one of your partitions, and you'd boot the Live OS from that iso.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    GPT: GUID Partition Table

    ... for Kubuntu 9.10 and GRUB 2

    => Overcoming the "2 TB disk size limit" associated with the conventional MBR
    => Get rid of the Extended partition with its linked list of Logical partitions
    (Have as many partitions as you want)


    CONTENTS

    The PC: BIOS, booting, the MBR, the bootloader
    MBR: Limitations, problems, the "2 TB limit" issue
    GPT -- GUID Partition Table -- and EFI
    GPT layout, features, and the Protective MBR for your bootloader
    Maximum disk size in GPT systems: 9.44 billion terabytes (9.44 zettabytes (ZB))
    Requirements for using a GPT (kernel, bootloader, utilities, BIOS Boot Partition)
    => Testing GRUB 2 on your GPT-partitioned flash drive
    Troubleshooting

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    The PC: BIOS, booting, the MBR, the bootloader

    The Master Boot Record (MBR) is an area of a disk (a hard drive, a flash drive) that contains key data used by the BIOS of the PC to start--to "boot up"--the PC. It has been around a long time through the evolution of the original IBM PC and IBM compatible PCs, dating back to 1981, and starting with x86 CPU PC architecture in 1978.

    For this chronology and references, see
    x86 (CPU: central processing unit)
    http://en.wikipedia.org/wiki/X86
    IBM PC:
    http://en.wikipedia.org/wiki/IBM_PC#Longevity
    IBM Compatible PC:
    http://en.wikipedia.org/wiki/IBM_PC_...mpatible_today
    And for BIOS (Basic Input Output System, a term also going back to the beginning of PCs), see
    http://en.wikipedia.org/wiki/BIOS


    The MBR plays a key role in the booting process

    In a (detailed) nutshell: You turn on your PC. The x86 CPU executes an instruction at the address 0xFFFF0 which then transfers control to the start of a program called BIOS, a program (a set of instructions called firmware) stored in a special type of ROM (EEPROM: electronically erasable programmable read-only memory) located on a chipset that is part of the motherboard of the PC. The BIOS runs the POST (power-on self test) checking and initializing installed devices and memory. BIOS then checks the boot devices (hard drives, CDs, flash drives, floppy drives) in a certain order (that you configure in BIOS setup under the boot device sequence) until it finds a bootable device (i.e., a device it can read and that contains a two-byte boot signature (AA 55, or in hexadecimal 0xAA55) at the end of the first sector (1 sector = 512 bytes, 1 byte = 8 bits). This first sector (of a device) is called the boot sector. In the case of a hard drive (or flash drive, or external USB drive), the first sector of the device, the boot sector, is called the Master Boot Record. BIOS then transfers control to the bootloader code (e.g., GRUB) it finds in the first 446 bytes of the MBR (this bootloader code is often referred to as Stage 1 code). The bootloader looks at the partition table (located in the next 64 bytes of the MBR); it locates a bootable partition (one that has the active flag or boot flag set); it loads the boot sector of the bootable partition into RAM (random access memory--the "main" memory of the PC); it then transfers control to its Stage 2 bootloader code (located somewhere beyond the MBR; e.g., immediately following the MBR or elsewhere, e.g., in the operating system's filesystem). Now, the Stage 2 bootloader code takes over and loads the operating system (OS) into memory (into RAM: random access memory), and then the OS runs in RAM and takes over from there.

    NOTE 1 Note the size of the MBR: 446 bytes for the bootloader Stage 1 code PLUS 64 bytes for the partition table PLUS the 2-byte ending boot signature (AA 55) = 512 bytes = the first sector of the disk.)
    NOTE 2 Note that there are two types of boot sectors on a disk: (1) the boot sector of the disk (the first sector on the disk; e.g., the MBR of a hard drive); and (2) the boot sector of a partition (the first sector of the partition).
    NOTE 3 Note that two things are sequentially loaded into RAM: first the bootloader code (in the MBR) loads the boot sector of the bootable partition into RAM; second, the bootloader code (Stage 2) loads the OS into RAM.

    Summary So, if speaking to someone you run into on the street, we might put it this way:
    You turn on the PC; the CPU starts the BIOS, the BIOS finds a bootable device and checks the MBR of that bootable device for bootloader code Stage 1 and turns control over to Stage 1; Stage 1 bootloader code looks at the partition table (in the MBR), finds a bootable partition, loads the boot sector of that bootable partition into RAM, and passes control to Stage 2 bootloader code, which in turn loads the OS into RAM and passes control to the OS (which runs in RAM).


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    MBR: Limitations, problems, the "2 TB limit" issue

    The MBR is easily damaged (as many people learn and then find themselves visiting TestDisk to recover it). It is limited to four primary partitions, or more if you make one primary partition an extended partition and put logical partitions "inside" the extended partition (but then, because the logical partitions are connected as a linked data structure, if you change or damage one of them, it may mess up access to others; furthermore, this arrangement is somewhat clumsy and inconvenient).

    And then there's the so-called 2 TB limit which is a function of the MBR itself (irrespective of hardware or OS issues). To understand this, consider what the MBR looks like. In fact, have a look at yours, print it to the screen in hexadecimal characters as follows (at Konsole):

    sudo dd if=/dev/sda count=1 | hexdump -C

    where sda is the hard drive containing the MBR you wish to see (each hard drive has an MBR). If you see a bunch of ***** here and there, they indicate blocks of zeros. If you see on the right things like GRUB .Geom.Hard Disk.Read. Error., ignore it, it's OK, not a problem. You can also see the boot signature 55 AA at the end, indicating end-of-file and indicates it is a boot record. If you want to know how to read this output and everything else about the MBR and partitions, see Starman's excellent, definitive work:

    MBR/EBR Partition Tables, Copyright © by Daniel B. Sedory
    http://thestarman.pcministry.com/asm/mbr/index.html

    But for what we need here, it's easy enough to summarize the organization of the MBR, as follows:

    -- The MBR occupies the first sector of your hard drive (or flash drive); since a sector is 512 bytes, the MBR is the first 512 bytes of your hard drive.
    -- The first 446 bytes of the MBR is occupied mainly by the bootloader code (e.g. Stage 1 of GRUB Legacy or boot.img of GRUB 2).
    -- The next 64 bytes is the partition table.
    -- The final 2 bytes is the boot sector signature (or end-of-file) 55h AAh (or, in hexadecimal, 0xAA55. (The "0x" introduces it as hexadecimal; and hexadecimal reverses the order, putting AA first then 55, and that is because of how it will be read--the last comes first.)

    Now, let's look at the MBR partition table:

    -- It is 64 bytes long, each of the four partition entries is 16 bytes.
    -- The first 8 bytes contains the following: The first byte is the status (0x80 = active => bootable). The next three bytes contains the start of the partition in the antiquated C/H/S geometry. The next three bytes after that contains the end of the partition, again in C/H/S.
    -- The second 8 bytes of the 16-byte partition entry describes the partition's location (LBA) and size as follows:
    4 bytes specifies the LBA (Logical Block Address) of the first sector of the partition.
    4 bytes is used for the number of blocks in the partition (usually a block is 512 bytes but may also be 1024 bytes).

    That raises the question which is at the heart of the problem with the MBR:
    How big can a partition be? how big can a disk be?

    > 4 bytes specifies the LBA (Logical Block Address) of the first sector of the partition.
    There are 8 bits in a byte, so 4 bytes is 32 bits. A bit can be zero or one. So 32 bits can represent 2**32 binary numbers (sequences of zero's and one's). That's 2 raised to the exponent 32:
    2**32 = 4,294,967,296.
    So that's how many sectors we can address using the MBR, and since each sector is 512 bytes, we get:
    (2**32)*512 bytes = 2,199,023,255,550 (or approximately 2.2E12) bytes.
    This is approximately 2 terabytes or 2 TB.

    Thus, the limit on disk size is 2 TB (otherwise we couldn't address all of its sectors).

    > Similarly, the size of the partition in blocks is represented by the second 4 bytes, and with the usual 512-bytes/block, that again is 2 TB, and so the limit on partition size is 2 TB.

    Thus, we have the 2 TB limit. It is a limitation of the traditional MBR used in most PC's today.

    NOTES

    --- One terabyte is 1024GB; 1 petabyte (PB) is 1024TB; 1 exabyte (EB) is 1024 PB; and 1 zettabyte (ZB) is 1024PB.
    For a table of these decimal and binary numbers, see
    http://en.wikipedia.org/wiki/Terabyte

    --- See a graphical representation of the MBR here:
    http://en.wikipedia.org/wiki/Master_Boot_Record

    --- CHS and LBA
    The old C/H/S notation (cylinder-head-sector, which starts sectors at 1) for describing the location of data on a disk was based on physical disk geometries when hard drives were very small. It was later enhanced but still very limited. It was replaced by Logical Block Addressing (LBA). which basically simply converts C/H/S into a linear, numerical sequence (sectors start at zero). Nowadays, all modern BIOSs and OSs use LBA. To learn more, read these:

    CHS Cylinder-head-sector
    http://en.wikipedia.org/wiki/Cylinder-head-sector
    LBA Logical block addressing
    http://en.wikipedia.org/wiki/Logical_block_addressing


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    GPT -- GUID Partition Table -- and EFI

    Just as the PC BIOS uses the MBR, the new Extensible Firmware Interface (EFI) uses the GUID partition table (GPT). EFI, developed by Intel and now handled by the Unified EFI Forum, defines a software interface between the OS and the platform firmware and is positioned to replace BIOS as the standard.

    >>> This section of the present how-to is in progress:
    The post you are reading is not about EFI per se, it is about GPT. We make just a few comments and provide some links, and then we return to the subject of GPT.

    Apparently, we have this:
    "Linux has been able to use EFI at boot time since early 2000, using the elilo EFI boot loader or, more recently, EFI versions of GRUB."

    elilo:
    http://en.wikipedia.org/wiki/Elilo
    And, apparently there has been some controversy in the Linux community about EFI:
    Linux: Linus On The Extensible Firmware Interface
    http://kerneltrap.org/node/6884

    Read all about EFI and related subjects:
    Extensible Firmware Interface
    http://en.wikipedia.org/wiki/Extensi...ware_Interface
    Extensible Firmware Interface (EFI) specification (GPT: see Chapter 16)
    http://www.intel.com/technology/efi/

    "There are few alternatives for Legacy BIOS in the x86 world: Extensible Firmware Interface, Open Firmware (used on the OLPC XO-1) and coreboot."
    Open Firmware (or OpenBoot)
    http://en.wikipedia.org/wiki/Open_Firmware
    Coreboot
    http://en.wikipedia.org/wiki/Coreboot

    >>> Here, our focus is on a part of the EFI, the GPT, motivated by the 2 TB disk size limitation of BIOS-MBR, and for that, continue reading.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    GPT layout, features, and the Protective MBR for your bootloader

    The size of the GPT depends on the implementation of it by an OS platform. At a minimum, the EFI specification calls for at least 128 partition entries (or records), each 128 bytes long, so that implies a minimum GPT size of 16,384 bytes (i.e., for the partition table itself).

    GPT uses LBA exclusively (it does not use the antiquated C/H/S). LBA0 refers to the starting (sector) address of the Protective MBR. LBA1 refers to the starting (sector) address of the Primary Partition Table Header.

    GPT includes a Protective MBR that you may use for your bootloader
    > Thus you may install GRUB 2 to the MBR of the disk that is partitioned as GPT.

    The Protective MBR has the same form as a full conventional BIOS-MBR.
    It goes into the first sector of the disk (just as in BIOS-MBR systems),
    and it precedes the GPT partition table.

    The partition table in this MBR contains just one partition entry of type 0xEE.
    If the disk is less than 2 TB, the single partition is specified to be the entire disk.
    If the disk is greater than 2 TB, the partition's size is set = 2 TB.

    This protects the GPT against destructive actions caused by using non-GPT-aware disk partitioning utilities. If a utility reports to you only a MBR on the GPT disk, it means that you've used a GPT unaware utility. And if such a utility is used on a GPT disk, it will see a full disk, report such to you, and not attempt to partition anything (without first complaining to you that the disk is full).

    GPT stores all partitions in one table
    => there is no use of any "extended" or "logical" partitions.

    You may include a human-readable label for a partition
    Exs.: Home; GRUB2_files; Data_Photos;

    Partition table backup and integrity

    The GPT scheme includes a Secondary GPT, providing redundancy: the GPT header (containing the Protective MBR and the partition table) is written at the start and at the end of the disk.

    (On EFI implemented GPT: " ... [The GPT] also contains a CRC32 checksum for itself and for the
    partition table, which is verified by EFI processes on boot...")

    Reference
    For a graphical representation of the GPT, more details, and links, see
    GUID Partition Table
    http://en.wikipedia.org/wiki/GUID_Partition_Table

    NOTE
    GUID (Globally Unique Identifier) is Microsoft's implementation of UUID (Universally Unique Identifier) used in Linux. More about UUIDs here:
    http://en.wikipedia.org/wiki/UUID


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Maximum disk size in GPT systems: 9.44 billion terabytes (9.44 zettabytes (ZB))

    In the partition table entry (in the GPT) for a given partition, 8 bytes are used as the pointer on the disk to the starting sector of that partition (i.e., 8 bytes are used to designate the LBA address of the starting sector of that partition). That is 64 bits (8 bytes times 8 bits/byte). And so 2**64 is the number of sectors addressable in the GPT, with 512 bytes per sector, gives a total byte-count of (2**64)*512 = 9.44E21 bytes for the disk (maximum size), or 9.44 zettabytes (ZB) (a zetabyte is a billion (~ E9) terabytes (~ E12)). Well, that certainly overcomes the 2 TB limitation of the BIOS-MBR system.


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Requirements for using a GPT

    To successfully implement a GPT, you need GPT support from:

    -- Kernel support
    (Linux supports GPT)

    -- Bootloader support
    (GRUB 2 supports GPT, as do various patched versions of GRUB Legacy)

    -- Disk partitioning utilities support
    The command-line GNU Parted supports GPT,
    as does the GUI driven GParted (Gnome Partition Editor).
    (Both these are based on libparted, a good thing.)

    GNU Parted
    http://www.gnu.org/software/parted/index.shtml
    GNOME Partition Editor
    http://gparted.sourceforge.net/

    Adding a GPT disk to an existing BIOS-MBR system: No problem
    Your existing disk(s) may be BIOS-MBR configured.
    You may install a new GPT-based disk to the setup.
    > If GRUB 2 is installed to the MBR of both disks, you may boot one from the other using chainloading.

    You do not need a full EFI system to use a GPT
    BUT ... For GRUB 2 you will need a BIOS Boot Partition

    > You can implement a GPT on a conventional BIOS-based system.

    >>> Important <<<

    For GRUB 2 you will need a BIOS Boot Partition in the GPT scheme

    GRUB 2 boot.img will go into the protective MBR (using the first 446 bytes of the MBR).
    However, in the GPT setup, there is no space following the 512-byte MBR for embedding the "second stage" core.img. Thus, you must make a separate "BIOS boot partition" to hold core.img. Make it 128 kiB as recommended in the following link. Actually, using ext2 for example, and GParted Live CD, the minimum partition size is 8 MB, or 32 MB for FAT32.

    BIOS Boot Partition
    http://en.wikipedia.org/wiki/BIOS_Boot_partition

    http://www.gnu.org/software/grub/man...tallation.html


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Testing GRUB 2 on your GPT-partitioned flash drive

    I did a quick test, and you can, too. Here's my summary.

    OS: Kubuntu 9.10 alpha 6 (which uses the latest version of GRUB 2 (1.97x).
    Bootloader: GRUB 2 (beta)
    Disk device: 1 GB Kingston USB flash drive
    Motherboard: Intel DG33FBC; Intel D915GAVL
    Disk partition utility: GParted Live CD, current version

    Steps:

    1 Boot into Kubuntu

    2 Open Konsole (Terminal program)

    3 Optional: Zero-out your flash drive
    THIS WILL DESTROY ALL DATA ON THE FLASH DRIVE.
    This writes zeros to the entire flash drive and restores it to factory-new condition.
    Find out how Kubuntu sees your flash drive:
    sudo fdisk -lu
    Let's say, for this example, it is /dev/sdc.
    Use the dd command to write zeros to the entire flash drive:
    sudo dd if=/dev/zero of=/dev/sdc
    (You will not see any progress meter or output until it finishes. It took approximately 7 minutes on my system.)

    4 Partition the flash drive using GParted Live CD
    You can also do this using an installed gparted (Partition Editor).
    Tip: While in GParted Live CD, remember that you have access to a terminal if you need one (for dd, or sudo fdisk -lu): double-click Terminal icon at top. For root, simply use sudo in front of commands.

    I partitioned as follows:

    Plug in the flash drive, click Devices > Refresh (you may have do it more than once until the flash drive appears in the drop-down list of drives at the upper right or under GParted > Devices).
    You'll get a message that a Disklabel must be set on the disk and asked if you want the (default) msdos Disklabel. (You will also get this message if you highlight unallocated space and click Partition > New). You don't want msdos, so click the Advanced button and select gpt, then Create.

    Partitions:

    Partition 1: BIOS Boot partition
    8 MB (the minimum size offered), FAT32, for the BIOS Boot partition (embedding core.img).
    Set a flag: Partition > Manage flags, then check the bios_grub box (as the tag).
    Set a Label on the partition to remind you what it is:
    Partition > Label, and I typed BIOS_BOOT as the label.

    Partition 2: For setting up the GRUB 2 files in /boot/grub
    10 MB, ext2
    Also, set the boot flag on this partition to make it the active partition:
    Partition > Manage flags > check the boot box.
    Set a label on the partition to remind you what it is:
    Partition > Label, and type GRUB_FILES as the label.

    Partition 3: A for-fun extra test partition for the heck of it. (In another test, I also tested creating 10 partitions, and it went well under GPT.)
    200 GB, ext2

    5 Install GRUB 2 to the flash drive
    Exit GParted Live CD, remove the CD and the flash drive, reboot into your regular Kubuntu.
    Plug in the flash drive. See how it is mounted (or go into Dolphin and click on the second partition GRUB_FILES to mount it). Open Konsole. install GRUB 2 to the flash drive, setting up the GRUB 2 files in the second partition (GRUB_FILES) and installing the bootloader (boot.img = 512 bytes) to the MBR of the flash drive.
    Example:
    Suppose the second partition is mounted as /media/GRUB_FILES and suppose the flash drive is seen as /dev/sdc in Kubuntu (use sudo fdisk -lu to find out). Then install GRUB 2 to it as follows:
    sudo grub-install --root-directory=/media/GRUB_FILES /dev/sdc
    If it doesn't go, do it again with --recheck:
    sudo grub-install --recheck --root-directory=/media/GRUB_FILES /dev/sdc

    6 Re-booting from the flash drive:
    Make sure your BIOS is set to boot from USB and configure BIOS to boot from your flash drive.
    If you re-boot starting from your Kubuntu session, keep the flash drive plugged in (but click Safely Remove to unmount it), reboot the PC, enter BIOS setup, configure BIOS to boot from USB and put the flash drive at the top of the drive list, F10 to Save & Exit, and re-boot from the flash drive. After the POST, you should see the GRUB 2 prompt (coming from the GRUB 2 on the flash drive): grub>. (You get the GRUB prompt grub> since there is no boot menu (/boot/grub/grub.cfg) configured.) You can use this grub prompt to boot into one of your OSs; or simply shutdown the PC (grub>halt) and remove the flash drive; or re-boot (grub>reboot), enter BIOS setup, remove the flash drive, set BIOS to boot from your regular drive, F10 to save this change and exit to reboot from your regular drive.


    >>> Tips and Troubleshooting

    Reminder
    See the Section:
    Requirements for using a GPT (kernel, bootloader, utilities, BIOS Boot Partition)

    BIOS?
    Your BIOS must support this. Strange thing on my machines. On my newer Intel DG33FBC motherboard, re-booting from the flash drive didn't work exactly as expected. Instead, BIOS by-passed the flash drive and booted from my regular drive, giving me my regular GRUB 2 boot menu with various OSs to choose from. I pressed the "c" key to get a GRUB prompt, grub>, explored the drives using grub>ls, saw my flash drive, let's say it was (hd1), and then I could reboot from the GPT flash drive using chainloader:
    grub>set root=(hd1)
    grub>chainloader +1
    grub>boot
    Amazing. (I got the grub> from the GRUB 2 GPT flash drive, then used it to boot into my regular Kubuntu 9.10 OS.) Yet it wouldn't re-boot normally from the flash drive.
    However, my older machine (4 years back), a D915GAVL, would reliably boot from the GRUB 2 GPT flash drive every time!

    I conclude that maybe the DG33FBC BIOS is either buggy or doesn't like something about the flash drive setup; normally, it boots easily from USB: but as I said, when coaxed by manually entering boot commands at the GRUB 2 prompt, the DG33FBC BIOS would boot from the flash drive. Also, at the time of this test, neither 9.10 nor GRUB 2 were in final released version yet.

    Have you repartitioned anything on the GPT flash drive lately?
    If you modify one of the GPT partitions using, say, GParted, e.g. by changing the size of a partition or moving it, the partitioning utility MAY overwrite the Protective MBR; thus you may have to re-install GRUB 2.
    (=> To Do: To be tested fully)

    The BIOS Boot partition: Notes
    -- It really doesn't require a filesystem, just the flag: boot_bios .
    You can set that flag in GParted Live CD session: Partition > Manage Flags.
    Or set it at the command line in Konsole:
    sudo parted /dev/sda set <partition_number> bios_grub on

    -- "unknown" filesystem!
    You may get this warning if you look at your GPT flash drive in GParted Live CD (or using some other utility). If so, it's OK, ignore it.

    -- To see what's in the BIOS Boot partition, you can use dd to print the first 62 sectors to the screen.
    Example: Suppose the BIOS Boot partition is /dev/sdc2. Then:
    sudo dd if=/dev/sdc2 count=62 | hexdump -C
    (You probably can't read it, unless you've studied Starman!, but you can see that almost all those sectors are filled up to the end. A * or sequence ***** indicates a block of zeros--nothing there.)
    -> You can experiment with this to satisfy yourself that core.img of GRUB 2 is embedded there. Use dd to zero out that partition, use dd to look at all the zeros in the first 62 sectors, re-install GRUB 2 to the flash drive, run dd again to have a look at those first 62 sectors.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    UEFI issues, links: BIOS, UEFI, GPT, Secure Boot and more -->

    "UEFI ... defines a software interface between an operating system and platform firmware. UEFI is meant to replace the Basic Input/Output System (BIOS) firmware interface, present in all IBM PC-compatible personal computers. In practice, most UEFI images provide legacy support for BIOS services."
    http://en.wikipedia.org/wiki/UEFI

    So, we think of BIOS and the MBR, and now UEFI with GPT. However, UEFI also supports the older MBR.

    So-called Secure Boot is yet another new issue.
    http://en.wikipedia.org/wiki/Unified...#Secure_boot_2
    http://en.wikipedia.org/wiki/Secure_Boot#Secure_boot

    Here, at Kubuntu forums, Steve Riley has led the quest for understanding UEFI and related issues:
    Need UEFI help?
    Steve's introductory comments:
    https://www.kubuntuforums.net/showth...Need-UEFI-help
    and ...
    The threads under Miscellaneous Linux Info > Need UEFI help?:
    https://www.kubuntuforums.net/forumd...EFI-assistance


    "Welcome to the new UEFI subforum. With the impending release of Windows 8, nearly every new machine that hits your local BestWallBuyMart or NewAmaEggZon will ship with:

    * UEFI firmware (which replaces, and also emulates, BIOS)
    * disks formatted with GPT (which replaces, but does not emulate, MBR)
    * UEFI Secure Boot enabled
    * a mechanism (on x86 and x86_64 machines) to disable Secure Boot

    The presence of Secure Boot will change the way we're accustomed to installing *buntu. Different Linux distros are adopting different, and somewhat incompatible, ways of dealing with Secure Boot. This forum is for all those wishing to:

    * learn more about UEFI and Secure Boot
    * discuss the various Linux distributions' implementations
    * ask for help installing with Secure Boot enabled
    * ask for help disabling Secure Boot

    My personal preference would be for folks to simply disable Secure Boot: it eliminates the strong tie between software and hardware, thus allowing you to retain greater control over your installation. But not everyone will want to do this, so all questions and discussion are welcome here.

    Also, over time, I will mirror all my UEFI-related posts spread across KFN into this subforum, so that the information is easy to find in one place. [emphasis added]..."

    Scan the topics of the thread for some excellent tutorial information about UEFI, GPT, Secure Boot, other boot managers (UEFI will boot your Kubuntu OS; you don't need GRUB to do the booting; GRUB is also a boot manager, though; however, there are also other boot managers you can use instead of GRUB; etc.), legacy issues, and just about everything else you might want to know as you get started with UEFI.

    ==============================================
    ==============================================

    Appendix Topics (to Post #1):
    Installing Kubuntu--GRUB2 Placement, Working as Root, Permissions


    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.

    Installing GRUB 2 files

    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:

    Start the Live CD installer.
    Step: Disk Setup
    "Specify Partitions Manually"
    Step: Summary
    Advanced button at lower right
    Check or un-check to install GRUB 2 bootloader
    Choose from the drop-down list where to install GRUB 2
    sda = the MBR of drive sda
    sda1 = the first partition of drive sda
    sdb = the MBR of drive sdb
    etc.

    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.

    Building new boot menus

    > 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

    Opening an empty text document as root:
    kdesudo kate
    (then File > Save As)

    Opening a file manager as root:
    in 8.10 and after: kdesudo konqueror (or dolphin)
    in 8.04: kdesu konqueror (dolphin)

    Opening a terminal as root:
    sudo –i (to get a “root” terminal)
    or:
    sudo su

    Your file manager may support this feature:
    Open the file manager, navigate to the file, right-click on the file, Actions, Edit as Root.

    At Konsole (BASH) command line: Use sudo.
    Example: sudo fdisk -lu
    To open a graphical application (a text editor, a file manager), use either kdesudo or kdesu (see above).

    = = = = = = = = = = = = = = = = = = = =
    Permissions: read, write, execute; change the execute bit

    See Part 2 of
    Commands at Konsole: Beginners: 3 parts
    https://www.kubuntuforums.net/showth...sole-Beginners

    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:

    Setting ownership and permissions in GUI
    Open Konqueror or Dolphin as root (kdesudo konqueror), navigate to the file or directory, right-click, Properties, Permission, make changes, OK. In Konqueror/Dolphin, click the Advanced Permissions button to see all choices: owner, group, others and read, write, execute.

    CLI
    owner--group--others
    For each class: read, write, execute
    ls -l: list files, use a long listing format => shows ownership and permissions

    Permissions – numerical mode
    There are 8 possibilities (2*2*2) for read (on or off) - write (on or off) - execute (on or off) permissions on a file or directory (2*2*2 = 8 ). The octal equivalents for these binary numbers are:

    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

    Permissions – symbolic mode
    Suppose the file xyzfile is owned by root.
    To make it executable for ALL users
    sudo chmod +x xyzfile
    To remove the execute permission from all users
    sudo chmod -x xyzfile


    ==========================================

    GRUB 2 References, Tutorials, Special Topics

    Official GRUB 2 Manual
    http://www.gnu.org/software/grub/manual/grub.html
    Also, in a terminal: info -f grub -n 'Simple configuration'

    “grub2” package in Ubuntu
    https://launchpad.net/ubuntu/+source/grub2
    Bugs:
    https://bugs.launchpad.net/ubuntu/+s...tatus:list=NEW
    Questions, Open Questions
    https://answers.launchpad.net/ubuntu...ld.status=OPEN

    GRUB Legacy
    -- How To GRUB Methods - Toolkit --> looks like it is gone.
    http://kubuntuforums.net/forums/inde...opic=3081671.0

    The Grub 2 Guide (formerly Grub 2 Basics) by drs305
    http://ubuntuforums.org/showthread.php?t=1195275
    Excellent treatment of editing the boot menu and some basic key concepts of Grub 2.
    NOTE: This material has been incorporated into the Ubuntu documentation:

    Official Ubuntu docs for GRUB2
    https://help.ubuntu.com/community/Grub2

    GRUB 2 -- Ubuntu Wiki -- delete the reference below, I moved it to here.
    https://wiki.ubuntu.com/Grub2

    Grub 2 Title Tweaks, by drs305
    http://ubuntuforums.org/showthread.php?t=1287602
    Customizing the boot menu. Also by drs305. Editing grub.d scripts.

    GRUB 2 - 5 Common Tasks -- drs305
    http://ubuntuforums.org/showthread.php?t=1302743
    Unhide/Hide the Menu, Menu Default Entry, Menu Resolution, Timeout, Add a Splash Image

    Make maintaining GRUB easier for multi-booters, a "How To." -- by oshunluvr
    https://www.kubuntuforums.net/showth...l=1#post309577

    Easy boot to USB using GRUB instead of your BIOS -- by oshunluvr
    https://www.kubuntuforums.net/showth...d-of-your-BIOS
    (and read the posts that follow)

    An interesting discussion on multi-booting, by oshunluvr with posts by others:
    Making GRUB easier for a true multi-boot system -> CONCEPT
    https://www.kubuntuforums.net/showth...l=1#post308845

    and, the follow-up:
    Make maintaining GRUB easier for multi-booters, a "How To."
    https://www.kubuntuforums.net/showth...l=1#post309577

    GNU GRUB 1.96/2
    http://members.iinet.net/%7Eherman546/p20.html
    Herman's site (previously known as "bigpond").

    GRUB 2 bootloader - Full tutorial -- Dedoimedo
    http://www.dedoimedo.com/computers/grub-2.html

    GRUB 2 now default for new installations
    https://lists.ubuntu.com/archives/ub...ne/000573.html

    Grub 2 now default for Ubuntu 9.10
    http://www.ubuntugeek.com/grub-2-now...mic-koala.html

    GNU GRUB, main site, Legacy GRUB
    http://www.gnu.org/software/grub/

    StartUp-Manager -- Obsolete.
    https://help.ubuntu.com/community/StartUpManager

    Grub Customizer - a graphical grub2 settings manager
    https://launchpad.net/grub-customizer

    GRUB & GRUB 2 Boot Process
    http://www.pixelbeat.org/docs/disk/

    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/Documentat...parameters.txt

    GParted Live CD
    http://gparted.sourceforge.net/livecd.php
    For partitioning, formatting your hard drive.

    Super Grub Disk
    http://www.supergrubdisk.org/
    Will boot you into your OS when you can't do it alone.

    Marco's blog, GRUB 2, boot from iso, etc.
    http://www.mgerards.net/blog/?p=16

    Re: /boot partition is full -- by Herman, deleting old kernels
    http://ubuntuforums.org/showthread.p...84#post9007884

    All the Details of many versions of both MBR and OS Boot Records -- starman
    http://thestarman.pcministry.com/asm/mbr/index.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

    GUID Partition Table
    http://en.wikipedia.org/wiki/GUID_Partition_Table

    Technical Note TN2166, Secrets of the GPT
    http://developer.apple.com/mac/libra...06/tn2166.html

    HOWTO: Booting LiveCD ISOs from USB flash drive with Grub2, by JustRon.
    http://ubuntuforums.org/showthread.php?t=1288604

    Booting LiveCD from HD ISO
    http://ubuntuforums.org/showthread.php?t=1295506

    Boot an iso via Grub 2
    http://michael-prokop.at/blog/2009/0...iso-via-grub2/

    MultiBoot USB with Grub2 (boot directly from iso files)
    http://www.panticz.de/MultiBootUSB

    GRUB Graphical Menu Development Journal
    http://grub.gibibit.com/Journal

    Debian Wiki, GRUB, grub.cfg
    http://wiki.debian.org/Grub/grub.cfg.manpage
    As of 9-9-09, it doesn't exist.

    Tweaking GRUB 2
    http://www.drlock.com/blog/2008/07/11/tweaking-grub-2/
    -
    Last edited by Qqmike; Jan 22, 2014, 09:35 AM.
    An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

    Comment


      #3
      Re: GRUB 2 A Guide for Users

      Very nice work mike, thank you
      HP Pavilion dv6 core i7 (Main)
      4 GB Ram
      Kubuntu 18.10

      Comment


        #4
        Re: GRUB 2 A Guide for Users

        Yes -- what Fintan said -- excellent contribution, Mike. Thank you!

        Comment


          #5
          Re: GRUB 2 A Guide for Users

          Qmike, you're the greatest! I know I will be referring to this posting often, as I did often to the original GRUB howto.
          Never too old to learn
          Ault, CO, USA

          Comment


            #6
            Re: GRUB 2 A Guide for Users

            We all hope that Grub 2 (the sequel) turns out to be as good (let's go for better?) than the original.

            Your efforts are very much appreciated Qqmike.
            Using Kubuntu Linux since March 23, 2007
            "It is a capital mistake to theorize before one has data." - Sherlock Holmes

            Comment


              #7
              Re: GRUB 2 A Guide for Users

              Everything you wanted to Google® about Grub2, but were afraid to bookmark. Thank you for this post to help us out with the Grub 2 growing pains...especially the dual boot section.

              drobster

              Comment


                #8
                Re: GRUB 2 A Guide for Users

                Thanks, guys, appreciate the nice comments.

                After a 40-hour writing week, though, I'm not sure I feel I've made any unique or creative contributions yet. It's too soon in this game, not enough out on it, and the product isn't even finished yet to tell where this might go. Still some quirks, bugs, incomplete parts, I think. Maybe we'll all just become crafty menuentry writers, pushing the grub-update button, and that would be OK, too, as long as it works.

                This sure as heck is a work-in-progress. The GRUB 2 Manual is not even close to being finished (based on what's published). I also notice that there may be several versions of GRUB 1.xx that we are all using, as some experiments seem to go for some users, while other experiments fail. I'm using 8.04.3 with whatever 1.96x came down through apt-get install, no updates offered yet. Way too early for all this, but I wanted to block out something. I'm hoping for a good job done on the official Manual with some verbiage explaining more about the design of GRUB 2, how it works, and examples/tips and tricks and basic trouble-shooting tips.

                Much of GRUB Legacy applies to GRUB 2, and all of Linux command usage does. In fact, it's all so new, new language, new notation (scripts), new rules, and is sort of high-sounding, but not really all that earth-shattering for the average user: you edit a default file, edit/create a script file, do an update-grub, and that's it. A sudo grub-install /dev/sdx gives you a brand new ride. Of course, we'll need good specific examples for a variety of special applications.

                From the user's perspective, I have the feeling that GRUB 2 is fairly straightforward, the main difference being how the configuration menu is treated. The trick lies in having good solid script files in /etc/grub.d, especially the 10_linux and the 30_os-prober, scripts we can rely on to get everything generated just right without a hitch, and in having grub-install work right, as well as update-grub.

                I also feel, for the first time, that good a GUI makes sense (finally) for configuring the (inputs to the) boot menu. I can't imagine helping newcomers through the logistics of some of the editing required to get certain boot menu's going. That said, it's all there in the how-to, as well as that of drs305 (kinda hard to beat what he has done--really good, knockout job he's done--and I hope he continues and expands his how-to's).

                I reserved Reply #1 in case it's needed, and I would guess that would be for specific applications/examples.

                If anyone learns something new, discovers something, has a neat use of the bootloader, a better way, a better view, a trick (no ponies, please), whatever, I hope they will post it. Depending, I may reference it and/or package it (and/or copy it), with full reference and credits to the OP, maybe stick it in somewhere, e.g., in Reply #1. A quasi-wiki?

                I have a feeling that for the average PC user, or someone dual booting a dozen or so OSs on a few drives on a standard PC, nothing is very much changed.

                I like the new design. It's clean, elegant, and fairly straightforward, at least conceptually. Just use what you know from GRUB Legacy to (creatively) rig up menuentries, format them as script files, run update-grub, and go, possibly with a grub-install now and then.

                But ... I do hope that the OS prober thinger, well, does its thing very well . . . . .


                As for dual-booting, I think it's about the same as for GRUB Legacy. The trick will be relying on the OS probe-thing to gather up all the OSs. Otherwise, you'd simply have to rig up a custom boot script file (in /etc/grub.d) for the OS that was missed. My probe-thing missed sidux, which is why I had that as an example of a custom boot entry. May have to lean on symlinks a lot for awhile, or chainoader, doing an extra sudo grub-install /dev/sdxn here and there. Configfile may not always go (as I found out), probably because of a mismatch between the GRUBs.


                An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                Comment


                  #9
                  Re: GRUB 2: A Guide for Users

                  Update 9-20-09


                  My first DRAFT of this how-to was written using 8.04.3 and the GRUB 2 1.96x from the 8.04.3 repositories, and many things didn't work or worked but not very well. After trying 9.10 Alpha 6 with GRUB 2 1.97 Beta3, I find that most things work very well. This update (9/20/09) is based on further testing done in Kubuntu 9.10 Alpha with the newer GRUB 2 version.


                  Somewhat extensive today.

                  Lots of copyediting (punctuation, spelling, and some formatting).

                  And the following items were improved/modified:

                  -- The Table of Contents

                  -- Section 3, Fixing Things
                  Added: To see or to hide the boot menu

                  -- Section 3: Key Rescue Method: Re-installing GRUB 2 using Live CD
                  I included another method from Live CD based on some testing I did this morning.

                  -- Section 4, grub> GRUB's CLI From the Boot Menu; the "c" key
                  I added some comments about using the boot command at the grub> (but that it is not necessary in grub.cfg).

                  -- Section 4, dedicated GRUB partition:
                  > Modified steps to include setting the boot flag on the GRUB partition using GParted Live CD.
                  > Gave a better (and fully tested) example of making your own dedicated GRUB partition grub.cfg file.
                  > IMPORTANT NOTE ABOUT KERNEL UPDATES: how they do not apply to your dedicated GRUB 2 partition.

                  -- Section 4, booting methods
                  I added another way to do symlinks (using root=/dev/sdxN instead of root=UUID=yyy).


                  -------------

                  To Do:

                  Lots of things, over time. Review everything. Better organizing, tighten it up here and there, add new topics as appropriate, do more testing, see what the (final) official Manual has to say about all this, review the Cheat Sheet, and do more copyediting, etc.
                  An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                  Comment


                    #10
                    Re: GRUB 2: A Guide for Users

                    More great work -- thanks Mike! I think maybe when 9.10 gets released, I'll give a shot at setting up Grub 2 as my boot menu. With your toolkit, it could work!

                    Comment


                      #11
                      Re: GRUB 2: A Guide for Users

                      Update 9-22-09

                      Again, rather major.
                      More cleaning up, checking, tightening, copyediting.

                      New topics
                      (e.g., Troubleshooting Outline, GRUB 2 flash drive, working at the grub> to boot an OS).

                      Expanded treatment of some important topics (grub-install, grub>ls, etc.)


                      SECTION 1: Introduction
                      Cleaned up a lot.

                      SECTION 2: Key Facts About the Boot menu, grub.cfg
                      Much improved; material added; better formatting.

                      SECTION 3: Fixing Things
                      Cleaner, neater. Added material, including:
                      A Troubleshooting Outline
                      The GRUB prompt grub> -- What to do with it
                      => Getting information and booting an OS : Examples
                      Confirmed: Method 1 for using a Live Kubuntu CD to install or re-install GRUB 2
                      Added: Using a Live CD to edit files in your OS

                      SECTION 4
                      Special Topics
                      Expanded: Installing GRUB 2 to your PC
                      Expanded treatment of grub-install The most useful command
                      More on the powerful ls command in GRUB 2
                      More on symlinks
                      More on configfile
                      New: GRUB 2 Flashdrive: How to build it

                      =====================

                      Of course, I still have to thoroughly check the text, but that will happen at some point.
                      An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                      Comment


                        #12
                        Re: GRUB 2: A Guide for Users

                        Thanks a ton Qqmike!

                        Last time I tried grub2 I rendered my system unbootable. Perhaps I'll try again...

                        Cheers
                        Once your problem is solved please mark the topic of the first post as SOLVED so others know and can benefit from your experience! / FAQ

                        Comment


                          #13
                          Re: GRUB 2: A Guide for Users

                          Hi toad, yeah, that was also my experience the past couple years. The newer the version of GRUB, the better. So 1.97 is working better than 1.96, imo, and you get it through 9.10 alpha's. I didn't try to see what one would get through normal 9.04 repos, but the GRUB 1.96 in my 8,04.3 has several hangups.
                          An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                          Comment


                            #14
                            Re: GRUB 2: A Guide for Users

                            fyi for forum helpers ...

                            When new people install Kubuntu 9.10 using the Live CD, they can specify where to place the bootloader (it's the same as we've known it to be, behind an Advanced button). I fully tested this for 9.10.

                            Mention is made right up front in the how-to and full details are given in an Appendix topic:

                            Installing Kubuntu--GRUB 2 placement
                            Telling the Live CD installer where to put GRUB 2
                            -> See the Appendix
                            An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                            Comment


                              #15
                              Re: GRUB 2: A Guide for Users

                              continuing from yesterday ...

                              Much improved cheat sheet (actually 2 pages in 12-pt. type if printed):
                              SECTION 4
                              Cheat sheet:
                              GRUB 2 Practical Reminders: listing of key files, commands, methods

                              and much improved
                              SECTION 4
                              4 ways to boot an OS: configfile, symlinks, direct booting, chainloader


                              (just in case someone is reading this stuff and wants to track changes)


                              EXTRA--EXTRA

                              Did you know?

                              grub>ls (hdx,y)
                              tells you about partition (hdx,y) INCLUDING its UUID.
                              (that is, you did notice the GRUB 2 prompt, right?
                              => UUIDs available in the GRUB shell now)
                              An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                              Comment

                              Working...
                              X