Βοηθήστε στην μετάφραση εδώ viewtopic.php?f=9&t=7278&p=73237#p73237
Βρήκα αυτό εδώ το φοβερό post στο kubuntu forum που εξηγεί τις διαφορές του grub 2 από τον grub legacy που χρησιμοποιούσαμε μέχρι τώρα καθώς και πως μπορούμε να κάνουμε το upgrade σε grub 2. Δείτε εδώ
http://kubuntuforums.net/forums/index.p ... #msg195838
έγραψε:GRUB 2 A Guide for Users -Qqmike Updated: 9/10/09
In Progress -- DRAFT -- this still needs testing, expansion, and awaits the completion of the GRUB 2 Manual: http://grub.enbug.org/Manual . I've left various To Do's for myself throughout the text.
> Keep an eye on SECTION 5: Tutorials: Where to go to study Grub 2.
First thing to do: Get Super Grub Disk bootable rescue CD.
From a user's view, in many ways, GRUB 2 is simpler than GRUB Legacy; certainly cleaner, more elegant, more logical (hierarchical, modular).
Tech stuff: see references.
GRUB 2 Practical Reminders (a cheat sheet for those who know what they are doing) -- you'll find this at the end of SECTION 4 Special Topics. You may wish to modify this, customizing it for what you need.
TABLE of CONTENTS
SECTION 1
Introduction
History: Grub Legacy, Grub 2
Differences between Grub Legacy and Grub 2
Grub 2 commands
SECTION 2
Key Facts About the Boot menu, grub.cfg
Quick version -- Overview -- Details
/etc/grub/default --> /etc/grub.d --> /boot/grub/menu.lst
Rules for editing grub.cfg, /etc/default/grub, and the script files in /etc/grub.d
SECTION 3 Fixing Things
A checklist of things to try to fix a broken system
Ctrl+Alt+Del will reboot your PC (at any time)
Super Grub Disk: Very Important
Key commands: sudo update-grub and sudo grub-install
-- Install/re-install GRUB 2 to a MBR or to a partition boot sector:
sudo grub-install [INSTALL_DEVICE]
Exs.: INSTALL_DEVICE may be /de/sda, /dev/sda1, hd0, hd1, etc.
-- Generate a new boot menu configuration file /boot/grub/grub.cfg:
sudo update-grub
Timeout & Default OS, changing
Kernel options, changing
Missing OS entry in the boot menu
Editing the boot menu during booting: "e" key
You get a grub> prompt instead of a boot menu
Using the GRUB prompt grub> to fix your system: "c" key
Key: Re-installing GRUB 2 using Live CD
SECTION 4
Special Topics
Installing Grub 2 to your PC
The various types of command lines!
emu, "c," grub>, Konsole BASH, edit "e"
How to get information about your drives and devices
Boot menu: Adding or removing an OS entry
Boot menu: Create a custom boot entry
Boot menu: Making your own custom grub.cfg
Dual booting: How to set it up
Dedicated Grub 2 partition: How to build it
4 ways to boot an OS
direct booting configfile, symlinks, chainloader
grub> Grub's CLI from the boot menu, "c" key
Use of the term "root"
GRUB's Root Device, the Linux statement, root=UUID=,
--root-directory=DIR INSTALL_DEVICE
Cheat sheet:
GRUB 2 Practical Reminders: listing of key files, commands, methods
SECTION 5
Tutorials: Where to go to study Grub 2
Rely on these few references for comprehensive, detailed treatment.
Appendix: Techniques
--- Working as root, editing a file -- see below
--- Permissions: read, write, execute; change the execute bit -- see below
--- Chroot -- how to -- see below
--- Konsole
Commands at Konsole: Beginners: 3 parts
http://kubuntuforums.net/forums/index.p ... =3091607.0
--- GRUB Legacy
How To GRUB Methods - Toolkit
http://kubuntuforums.net/forums/index.p ... =3081671.0
References
= = = = = = = = = = = = = = = = = = = =
SECTION 1
Introduction
History: GRUB Legacy, GRUB 2
Differences between GRUB Legacy and GRUB 2
GRUB 2 commands
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: http://www.gnu.org/software/grub/grub-2.en.html
Its mailing list for development,
GRUB-devel: http://lists.gnu.org/mailman/listinfo/grub-devel
And the Wiki: http://grub.enbug.org/
GRUB 2 is the default bootloader in 9.10
https://lists.ubuntu.com/archives/ubunt ... 00573.html
Differences between GRUB Legacy and GRUB 2
From the user's view, the biggest difference between the two versions of GRUB concerns the configuration file. The configuration file in GRUB Legacy is /boot/grub/menu.lst (it is used to generate the boot menu you see at boot time). In GRUB 2, it is /boot/grub/grub.cfg (again, grub/cfg generates 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 update-grub.
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 not a constant value, it is a variable).
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, it is the search 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) is used.
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). 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 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.)
GRUB 2 Commands -- compared to GRUB Legacy
Comparison chart:
http://grub.enbug.org/CommandList
Key useful items to note:
device is replaced by loopback (makes a drive out of a file)
find is replaced with search
geometry is gone and replaced by ls
kernel is replaced by linux (and other terms for different OSs)
map is replaced by drivemap
quit is gone (halt is sometimes used)
root is still used but is now a variable
set is a GRUB 2 term used to set a variable
setup is gone; the work is done by grub-install
title (in menu.lst) is replaced by menuentry (in grub.cfg)
- - - - - - - - - - - - - - - - - - - -
SECTION 2 Key Facts About the Boot menu, grub.cfg
Quick version:
/etc/grub/default --> /etc/grub.d --> /boot/grub/menu.lst
Rules:
-- Do not 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 update-grub
TODO, check this: grub-mkconfig ... used instead of update-grub in Karmic Koala?
sudo grub-mkconfig ?
Details
The configuration file is called /boot/grub/grub.cfg, and it generates the boot menu you see on your screen when you boot your PC (and so, /boot/grub/grub.cfg can be called the boot menu configuration file). You are NOT supposed to edit it (it is read-only). It is generated from a folder of scripts called /etc/grub.d. Another key file is /etc/grub/default and it feeds default data to the scripts in /etc/grub.d. You may edit /etc/grub/default (as root). You may also edit the scripts in /etc/grub.d (as root). If you create a new file in /etc/grub.d, you must make it executable if you want the entry included in the configuration file grub.cfg. If you do not want a script to execute (and so remove that entry from grub.cfg), you must remove the execute bit (i.e., remove the execute permission).
>>> Key reminder:
Generate a new grub.cfg after changing anything in /etc/default/grub or /etc/grub.d, by:
sudo 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 update-grub is run, the file returns to read-only, 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/grub/default
This file feeds data to the scripts in /etc/grub.d. It contains the 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 update-grub 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 update-grub
to generate a new boot menu configuration file /boot/grub/grub.cfg.
GUI, setting 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.
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, Konsole, and other topics.
- - - - - - - - - - - - - - - - - - - -
SECTION 3 Fixing Things
A checklist of things to try to fix a broken system:
Ctrl+Alt+Del will reboot your PC (at any time)
Super Grub Disk: Very Important
Key commands: sudo update-grub and sudo grub-install
-- Install/re-install GRUB 2 to a MBR or to a partition boot sector:
sudo grub-install [INSTALL_DEVICE]
Exs.: INSTALL_DEVICE may be /dev/sda, /dev/sda1, hd0, hd1, etc.
-- Generate a new boot menu configuration file /boot/grub/grub.cfg:
sudo update-grub
Timeout & Default OS, changing
Kernel options, changing
Missing OS entry in the boot menu
Editing the boot menu during booting: "e" key
You get a grub> prompt instead of a boot menu
Using the GRUB prompt grub> to fix your system: "c" key
Re-installing GRUB 2 using Live CD
Ctrl+Alt+Del will reboot your PC (at any time)
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). Keep your SGD CD handy.
Tip (using SGD to boot into your broken OS)
Choose GBU/Linux > Fix Boot, then select the broken partition.
Should you decide to simply Quit the SGD (without doing anything), do so, select reboot, enter your BIOS setup, remove the SGD CD, exit BIOS, and continue rebooting.
Key commands: sudo update-grub and sudo grub-install
Use these two commands to "freshen up" your GRUB 2 installation.
update-grub: 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.
The command
sudo update-grub
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 update-grub after editing the default file or the scripts.
> Man page: (8)UPDATE-GRUB - Generate grub.cfg.
http://grub.enbug.org/FranklinPiat/update-grub.manpage
The command
sudo grub-install [INSTALL_ DEVICE]
installs or re-installs GRUB 2 to INSTALL_DEVICE. For example,
sudo grub-install /dev/sda
installs GRUB 2 to the Master Boot Record of drive sda. And
sudo grub-install /dev/sda
installs GRUB 2 to the boot sector of the partition sda1.
In doing so, grub-install does a complete job of setting uo 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.
> Man page: (8)GRUB-INSTALL - Install GRUB on your drive.
http://grub.enbug.org/FranklinPiat/grub-install.manpage
Troubleshooting
-- After running sudo update-grub, make sure that the line set default=(hdx,y) is correct (i.e., that the order of the menuentries did not change the default OS position).
-- sudo grub-install --recheck [INSTALL_DEVICE]
=> If you get an error running sudo grub-install, try it again with sudo grub-install --recheck [INSTALL_DEVICE].
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 update-grub.
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
Sample (see your file /etc/default/grub):
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.
Troubleshooting Tip: Check default OS setting after update-grub
If you recently added/removed a boot entry (by editing a /etc/grub.d script) and ran sudo update-grub to generate a new boot menu, you might have to check and edit the line "GRUB_DEFAULT= " if the default sequence number changed.
TO DO: Check also: sudo grub-set-default N.
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 update-grub, 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.
If you need a grub> prompt, hit "c" key at the original boot menu or Control+c at the Edit mode menu. From the grub> prompt, you may be able to issue commands to help you gather information about your drives or to boot your computer (using SECTION 4 Special Topics, the subsection "4 ways to boot an OS" -- direct booting configfile, symlinks, chainloader; and the subsection "How to get information about your drives and devices"). From the Edit mode menu, when you think you are ready, you may boot your PC (using your edited statements) by pressing Control+x. If you need to re-boot otherwise, get the GRUB 2 prompt, and use grub>reboot.
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 by issuing sudo update-grub.
Key:
Re-installing GRUB 2 using Live CD
(In progress. See reference:
GRUB 2 Live CD Install Guide
http://grub.enbug.org/Grub2LiveCdInstallGuide
Comment: TODO -- re-test this; it didn't work yet for me, but it might work for you if you have a more current version of GRUB 2 or in 9.10.)
> See Appendix: Chroot, how-to.
Steps:
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. Our example to demonstrate this method is sda2.
(If you have a separate /boot partition, see the reference cited.)
Make a mount point (directory) for partition sda2:
sudo mkdir /media/sda2
Mount sda2 on the mount point:
sudo mount /dev/sda2 /media/sda2
Mount the devices in your Live CD session:
sudo mount --bind /dev /media/dev
Chroot into sda2:
sudo chroot /media/sda2
Install (or re-install) GRUB 2 (into the MBR of drive sda):
sudo grub-install /dev/sda
Troubleshooting: If you get Auto-detection of filesystem failed, try:
sudo grub-install --recheck /dev/sda
Exit out of the Chroot by typing exit; or by Control+d.
Unmount both filesystems
sudo umount /dev/sda2 /media/sda2
sudo umount /media/dev
(Reminder: If you have a separate /boot and mounted it above, unmount it now.)
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).
Comment The error messages for me were:
# grub-install /dev/sda
grub-probe: error: cannot find a device for /boot/grub
Auto-detection of a filesystem module failed.
Please specify the module with the option `--modules' explicitly
So, I tried
# grub-install --recheck /dev/sda
grub-probe: error: cannot find a device for /boot/grub
Auto-detection of a filesystem module failed
Please specify the module with the option `--modules' explicitly.
grub-probe: error: Cannot get the real path of `/dev/sda'
Auto-detection of a filesystem module failed.
Please specify the module with the option `--modules' explicitly.
You get a grub> prompt instead of a boot menu
If you boot or re-boot and instead of seeing your boot menu, you get the grub> prompt, then your boot menu /boot/grub/cfg is either not present or is broken somehow. Examples of what to try:
-- Try to boot into an OS using commands at the GRUB 2 prompt, grub>. Use the booting methods explained in SECTION 4 Special Topics: "4 ways to boot an OS" -- direct booting configfile, symlinks, chainloader. Or use the subsection "How to get information about your drives and devices" from a grub> prompt).
-- Use Super Grub Disk to boot into your OS and then try to fix things from there.
> run sudo update-grub
> or reinstall GRUB 2 using sudo grub-install
-- Live CD: try to re-boot into a Live Kubuntu CD session and reinstall GRUB 2 from there by chrooting into your broken partition. See the subsection above: Re-installing GRUB 2 using Live CD.
Using the GRUB prompt grub> to fix your system: "c" key
When you see the boot menu, you can get a grub> prompt by pressing the "c" key. The discussion above applies: Try to boot into an OS using commands at the GRUB 2 prompt, grub>. Use the booting methods explained in SECTION 4 Special Topics: 4 ways to boot an OS -- direct booting configfile, symlinks, chainloader. Or use the subsection "How to get information about your drives and devices" from a grub> prompt).
- - - - - - - - - - - - - - - - - - - -
SECTION 4 Special Topics
Installing GRUB 2 to your PC
The various types of command lines!
emu, "c," grub>, Konsole BASH, edit "e"
How to get information about your drives and devices
Boot menu: Adding or removing an OS entry
Boot menu: Custom boot entry
Boot menu: Making your own custom grub.cfg
Dual booting: How to set it up
Dedicated GRUB 2 partition: How to build it
4 ways to boot an OS
direct booting configfile, symlinks, chainloader
grub> GRUB's CLI from the boot menu, "c" key
Use of the term "root"
GRUB's Root Device, the Linux statement, root=UUID=,
--root-directory=DIR INSTALL_DEVICE
Installing GRUB 2 to your PC
CAUTION, fair warning, you have been warned:
Have a bootable Super Grub 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 update-grub
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/sda2.
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
The various types of command lines!
emu, "c," grub>, Konsole BASH, edit "e"
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 lines you may use in GRUB 2 are the following.
-- Konsole (BASH), in Kubuntu, at your regular prompt (as root), ~#:
-- GRUB 2 emu (from Konsole, issue sudo grub-emu [OPTION]; this gives you a grub> prompt)
=>TODO: More on this later.
-- GRUB 2 command line interface (CLI), grub>. When you re-boot your PC, get the boot menu, and press the "c" key, you get a GRUB 2 prompt, grub>. That is the GRUB 2 CLI. You will also get grub> upon re-booting if you don't have a boot menu, grub.cfg, or if your boot menu is broken. (See the
subsection below titled "grub> Grub's CLI from the boot menu, 'c' key.")
-- 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 make them so later). (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 sudo update-grub --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.
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>
Exploring your hard drive(s): grub> ls
=> Very useful, very important.
(in GRUB Legacy, the geometry command is used instead of ls.)
-- TAB completion
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.
-- 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 halt.
>>> 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 made (sudo grub-emu)) and issue the list (ls) command at the GRUB prompt (grub>ls) to see your drives and GRUB devices.
-- 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
Boot menu, to see it: grub>cat (hdx,y)/boot/grub/grub.cfg
Kernel, where it is: grub>search /vmlinuz
fstab, to see it: grub>cat (hdx,y)/etc/fstab
Device.map, to see it: grub>cat (hdx,y)/boot/grub/device.map
(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)
-- Using ls to list 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)
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.
-- 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 update-grub
-- Add a boot menu entry by making your own custom boot entry, then run:
sudo update-grub
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 update-grub
(2) Or, remove the script file (for the boot entry) from the folder /etc/grub.d. Then run
sudo update-grub 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 run sudo update-grub 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.
-- After you write the script file for your custom boot entry, make it executable.
-- Then generate a new grub.cfg by running sudo update-grub.
See the subsection below: "4 Ways To Boot an OS."
(direct booting, configfile, symlinks, chainload)
Troubleshooting: Sometimes when you run grub-install or update-grub, 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:
title 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 sudo update-grub 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 update-grub
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 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"
-- 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" to refresh the available kernels, and repeat these instructions.
Dual booting: How To Set It Up
This should follow the same guidelines as for GRUB Legacy, so see my GRUB Legacy how-to:
How To GRUB Methods - Toolkit
http://kubuntuforums.net/forums/index.p ... =3081671.0
(See Sections 5 and 6)
The differences will only involve how to edit things, especially the boot menu grub.cfg. As you know, in GRUB 2, you do NOT edit grub.cfg directly. Instead you edit the defaults file /etc/default/grub and the script files in /etc/grub.d following the present how-to you are reading now.
Dedicated GRUB 2 Partition: How To Build It
Again, this is straightforward, much easier than in GRUB Legacy.





