Δημοσιεύτηκε: 12 Σεπ 2009, 13:40
από vista killer
έγραψε: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 below "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
See: http://grub.enbug.org/FranklinPiat/grub-install.manpage
(That will also build the directory /boot/grub for you in your GRUB 2 partition.)

4 As root, copy your grub.cfg frm 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 Re-boot your PC to test it.
CAUTION: Remember to keep Super Grub Disk live CD handy.

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

# Set the timeout
set timeout=10

# Set the default boot entry.
set default=0

# Kubuntu 8.04.3 on sda2, by configfile
menuentry “Kubuntu 8.04.3 on sda2, by configfile” {
set root=(hd0,2)
configfile /boot/grub/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
}


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

First, we'll describe each method; then show examples.
(See below: Sample boot menu. Examples of the 4 types of booting.)

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

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.

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:
At Konsole, run
ls -a -l /
to see them:
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.im g-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. (Notice the root directory called for in the list statement, indicated by /: ls -a -l / says to list all files, in long form, under the root directory.)
NOTE: Thus, 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

NOTE: 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)

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

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

A Linux example

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

"chainlaoder +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
}

NOTE/Caveat? -- TODO -- Qqmike to check this.
Herman says: If you're trying to chainload a partition boot sector, you might need to use the -f option, which tells GRUB to ignore the fact that there might not be a bootable disc signature there, (!= 0xaa55). I'm not sure about exactly when that's needed or isn't needed yet. It seems to be only needed in CLI Mode GRUB.

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

Now, to demonstrate the 4 ways to boot an OS.

# Sample boot menu
# Examples of the 4 types of booting
# Sample boot menu /boot/grub/grub.cfg for a dedicated GRUB 2 partition
#
# The sign # indicates a comment and is ignored by GRUB.
# You may write anything you wish after the # sign.

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

# Set the timeout
set timeout=10

# Set the default boot entry
set default=0

# 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
}

# Kubuntu 9.10 on sdb7 symlinks, normal mode
# This is normal mode! If you want recovery mode (single user),
# replace the kernel options “ro quiet splash” with “ro single” (without quotes),
menuentry “Kubuntu 9.10 on sdb7, by symlinks” {
set root=(hd1,7)
linux /vmlinuz root=UUID= vb687f89-ggjd-6ach-7755-77241i4b4fk3 ro quiet splash
initrd /initrd.img
}

# 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
}

# Windows XP on sda1
menuentry “Windows XP on sda1, by chainloader” {
set root=(hd0,1)
chainloader +1
}

# End of /boot/grub/grub.cfg


grub> GRUB's CLI From the Boot Menu; the "c" key

When you re-boot or boot your PC, and see the boot menu, press any arrow key to stop the timer and freeze the menu. Read the tips at the bottom of the menu. To get a grub> prompt, press the "c" key. 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 this 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"). To reboot at the GRUB prompt: grub>reboot; or shutdown your PC: grub>halt.

Use of the Term "root"
GRUB's Root Device, the Linux statement, root=UUID=, --root-directory=DIR INSTALL_DEVICE
(To Do -- expand/clarify further)

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 0df17bc5-0056-4ef7-bfca-251194b6eb44 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=/sdb1 sda
where DIR is sdb1 and INSTALL_DEVICE is 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/) under the directory DIR instead of the root directory (/) of the OS.


- - - - - - - - - -
Cheat Sheet

GRUB 2 Practical Reminders -- for those who know what they are doing Smiley

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: /usr/lib/grub/i386-pc/, /boot/grub/device.map, boot.img (MBR), core.img

Fixing Things, Rescue
Ctrl+Alt+Del reboot PC; Super Grub Disk
New grub.cfg: sudo update-grub
Install, re-install entire GRUB 2: sudo grub-install [INSTALL_DEVICE]
sudo grub-install /dev/sdxn or to MBR: sudo grub-install /dev/sdx
If error: grub-install --recheck /dev/sdx
Install GRUB 2 to MBR of sda using GRUB in /sdb1/boot/grub:
sudo grub-install –root-directory=/media/sdb1 /dev/sda
Live CD rescue: Re-install GRUB 2 (mount, chroot into broken partition)
Install GRUB 2 to PC: sudo apt-get install grub-pc

Drives, partitions, information Keys: sudo fdisk -lu & grub>ls
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
GRUB devices/drives: grub>ls; grub>ls -al directory
Finding: grub>search /boot/grub/grub.cfg; grub>search /boot/grub/boot.img

Syntax, booting
set root=(hdw,z) and configfile /boot/grub/grub.cfg
configfile (hdx,y)/boot/grub/grub.cfg
Symlinks: linux /vmlinuz root=UUID= xxx ro quiet splash; initrd /initrd.img
set root=(hdx,y) and chainloader +1; chainloader (hdx,y)+1; chainloader (hdx)+1
> Booting choices: direct booting, configfile, symlinks, chainlaoder

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, 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 update-grub

> 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

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 update-grub

[End of GRUB 2 Practical Reminders]

- - - - - - - - - - - - - - - - - - - -
SECTION 5
Tutorials: Where to go to study Grub 2

Grub 2 Basics, by drs305
http://ubuntuforums.org/showthread.php?t=1195275
Absolutely excellent treatment of editing the boot menu and some basic key concepts of Grub 2.

Grub 2 Manual
http://grub.enbug.org/Manual
We hope this will be all you need, along with the man pages.

GNU GRUB 1.96/2
http://members.iinet.net/%7Eherman546/p20.html
Looks like an encyclopedic, comprehensive coverage.

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

See also the References which include both basic topics and advanced/special topics.


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

--- Working as root -- see below
--- Permissions: read, write, execute; change the execute bit -- see below
--- Chroot -- how to -- see below
--- Konsole, see:
Commands at Konsole: Beginners: 3 parts
http://kubuntuforums.net/forums/index.p ... =3091607.0
--- GRUB Legacy, see:
How To GRUB Methods - Toolkit
http://kubuntuforums.net/forums/index.p ... =3081671.0

--------------------------
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
http://kubuntuforums.net/forums/index.p ... =3091607.0
Ownership and Permissions Use ls -l to see them; chown & chmod to change them.
See tuxfiles
http://www.tuxfiles.org/linuxhelp/filepermissions.html
(symbolic mode)
Here's a brief reminder sheet for those who know this stuff:

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

--> See Tuxfiles

--------------------------
Chroot -- how to
From, Part 3 of
Commands at Konsole: Beginners: 3 parts
http://kubuntuforums.net/forums/index.p ... =3091607.0

To “chroot into a partition” is to enter the partition with root privileges (“as root”). (The root directory is set equal to the partition.)
Here's how:
Let's say Kubuntu is in partition sda2, something is broken there, and you need to use your Kubuntu
Live CD to chroot into sda2 and fix the problem. From the Live Kubuntu CD at Konsole:
sudo mkdir /media/fixthings
sudo mount /dev/sda2 /media/fixthings
sudo chroot /media/fixthings
=> Now you are “in” sda2 “as root” and can work from there as if you were actually booted into it. The command prompt is a root prompt “... :/#” You can enter the commands you will use to fix the problem in sda2. When done, type exit to leave the root prompt:
exit
Now the prompt is a regular, non-root prompt “... :~$”
To be safe, unmount the partition:
sudo umount /dev/sda2 /media/fixthings
=> CAUTION Do not use chroot unless you know what you are doing; you can damage your Kubuntu filesystem if you make a mistake while using chroot.