Friday, May 19, 2017

Dedicated grub 2 partition

Dedicated grub 2 partition


Dedicated GRUB 2 Partition:  How To Build It
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 or gksu gedit, 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
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 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.

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, theres 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 youd 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 cant 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
}

download more info

No comments:

Post a Comment