LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-12-2017, 10:57 AM   #1
centguy
Member
 
Registered: Feb 2008
Posts: 627
Blog Entries: 1

Rep: Reputation: 48
how to install grub2 on the first section of a partition and then how to chainload to this grub2 bootloader?


Suppose I have installed Linux Mint 18.2 on /dev/sda6. I can boot up this system since
/dev/sda has a grub2 bootloader installed during installation. This grub2 bootloader
reads the content of /dev/sda6/boot/grub/grub.cfg

during the booting process.

Now, suppose I do

grub-install /dev/sda6


Now, a separated grub2 bootloader is found in /dev/sda6. Question: How do I add a menuentry
in /dev/sda6/boot/grub/grub.cfg (after adding an entry in 40_custom and run update-grub) so that
I can chainload to the bootloader located at the first sector of /dev/sda6?

Thanks. I just want to know how to do that. I was able to do that with GRUB Legacy before and the
concept is rather interesting.
 
Old 09-13-2017, 05:50 AM   #2
voleg
Member
 
Registered: Oct 2013
Distribution: RedHat CentOS Fedora SuSE
Posts: 354

Rep: Reputation: 51
Should be as for windows: chainloader +1
Have not tested.
 
Old 09-13-2017, 07:12 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
grub2 wasn't designed to work that way - hence the warnings when you do the partition install.
Best to use configfile to handoff the loading, although chainloader as suggested will also work.

If you have UEFI and gpt the discussion effectively becomes moot.
 
Old 09-13-2017, 06:35 PM   #4
aus9
LQ 5k Club
 
Registered: Oct 2003
Location: Western Australia
Distribution: Icewm
Posts: 5,842

Rep: Reputation: Disabled
add these lines to 40_custom
then use root powers to update-grub

menuentry "sda6" {
set root=(hd0,6)
chainloader +1
}

Quote:
Now, a separated grub2 bootloader is found in /dev/sda6
then test it dear Henry dear Henry .....(hole in the bucket song) (who wants to be sane in this world)

you may need prefix sudo or change to root if below command does not work

Code:
if=dev/sda6 bs=512 count=1 | strings
if you have a MBR system and successful grub into sda6....response will be multiple lines including a line saying Grub
 
Old 09-14-2017, 01:33 AM   #5
centguy
Member
 
Registered: Feb 2008
Posts: 627

Original Poster
Blog Entries: 1

Rep: Reputation: 48
I see, I think my first post just shows me I did not completely understand the power of modern UEFI/GPT
technology compared to old BIOS/MBR technology.

Okay. Something practical.

My recent new 2017 Asus Computer has UEFI where I was able to multiboot Linux Mint 18.2, CentOS 7, and Windows 10 (a
non-trivial feat as I understand better the difference between UEFI/GPT vs BIOS/MBR).
grub2 is the bootloader for Linux Mint 18.2 and Centos 7, a decendent of Fedora (even though they claim to be of the same 2.02 version but
it seems Linux Mint 18.2 use initrd but CentOS 7 use initrdefi, so at least one grub2 cannot understand the syntax of the other grub2.
However, this is no big deal in the messy Linux world, needs some simple tweak like do the chainloading).

For transition, I am still productive under CentOS 6.x (x=6 is my latest, even though x has moved).

I want to install CentOS 6.x which only uses grub LEGACY. It means at some point during installation (even before
installation I might have to turn off EFI or the bios will be defaulted BIOS/MBR boot --- I have yet to find out!)
I will have to decide to install the bootloader to /dev/sda8 or /dev/sda (the first sector of sda, the MBR!).

It seems the UEFI boot will not boot CentOS 6.x if I do nothing.

If I enable EFI/GPT in bios, then I need to chainload to the legacy grub of CentOS 6.x. Can grub2 chain load legacy grub flawlessly?
I really hope so. If not I imagine myself always have to choose UEFI or non-UEFI during boot time to boot up Windows 10, etc or CentOS 6.x.

Since there are many possible paths to take, I write down these notes to keep me sane and
see if any expert out there has a strong advice for me before I hit something strange.
 
Old 09-14-2017, 01:51 AM   #6
centguy
Member
 
Registered: Feb 2008
Posts: 627

Original Poster
Blog Entries: 1

Rep: Reputation: 48
https://www.linuxquestions.org/quest...-grub2-917118/

seems to have all the answers I need.

Will test out.
 
Old 09-14-2017, 04:35 AM   #7
aragorn2101
Member
 
Registered: Dec 2012
Location: Mauritius
Distribution: Slackware
Posts: 567

Rep: Reputation: 301Reputation: 301Reputation: 301Reputation: 301
Quote:
Originally Posted by centguy View Post
...
grub-install /dev/sda6
...
Can you please tell us the output of the above command?
From my experience, if you have a MBR partition table on your hard disk, you do grub-install /dev/sda and grub installs the bootloader to the boot sector of the drive, i.e. the MBR. But I am not sure if there is such a thing of the boot sector of /dev/sda6 and I don't think grub works like that. So I am curious as to the output of that command of yours.

Quote:
Originally Posted by centguy View Post
...
If I enable EFI/GPT in bios, then I need to chainload to the legacy grub of CentOS 6.x. Can grub2 chain load legacy grub flawlessly?
I really hope so. If not I imagine myself always have to choose UEFI or non-UEFI during boot time to boot up Windows 10, etc or CentOS 6.x.

Since there are many possible paths to take, I write down these notes to keep me sane and
see if any expert out there has a strong advice for me before I hit something strange.
I'll tell you something frankly. If you have EFI OS's, stick to UEFI. Switching between UEFI and Legacy everytime you have to boot something is not optimal, and chainloading legacy grub from EFI grub is most probably not possible at all.

But you can try something. If CentOS 6.x is not UEFI compatible, you could try to install it using Legacy mode. Then you switch to UEFI mode, boot into Linux Mint and run grub-mkconfig in Linux Mint to have an entry for the CentOS in Mint's Grub menu. Grub just boots the kernel, so maybe there is a solution in this way. Maybe the kernel will complain about certain things though. I'm thinking about efivars or the GPT filesystem. I didn't get a chance to try this. I think this could be a good experiment to carry out.
 
Old 09-14-2017, 05:26 AM   #8
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
You can load another grubs menu (grub.cfg) with the configfile option. So whatever menu entry is equivalent to:

GRUB> insmod part_gpt
GRUB> insmod ext2
GRUB> ls
GRUB> configfile (hd1,gpt1)/boot/grub/grub.cfg

AKA how I boot my SSD on an old gateway that doesn't seem to know how to boot GPT formated disks. Via a grub on a usb stick formatted the MBR way.
 
Old 09-14-2017, 06:15 AM   #9
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,617

Rep: Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695
Quote:
Originally Posted by centguy View Post
... grub2 is the bootloader for Linux Mint 18.2 and Centos 7, a decendent of Fedora (even though they claim to be of the same 2.02 version but ...
To be clear and correct, CentOS is NOT a decendent of Fedora, it is a binary compatible clone (from the same sources) of RHEL. It will have exactly the same versions and requirements as the same release number of RHEL, not the same as Fedora. This means that all of the RHEL documentation online for the same version number will apply, but the packages come from free REPOS instead of from the RHN.
 
Old 09-14-2017, 10:03 AM   #10
centguy
Member
 
Registered: Feb 2008
Posts: 627

Original Poster
Blog Entries: 1

Rep: Reputation: 48
Answers:

LM182-Asus ~ # grub-install /dev/sda6
Installing for x86_64-efi platform.
Installation finished. No error reported.
LM182-Asus ~ #


This grub-install seems okay, even though I do not know how to chainload to it from grub2 successfully.
But it seems it is perverse
to go down this path: it is just show that one does not know under the power offered by EFI/GPT. It
is too hard to into this, but experimenting with it (see my other recent posts) and reading a lot about this
topic finally convert me from grub legacy to grub2.

Back in the good old day with BIOS/MBR and grub legacy, I do that this most of the time for
multiboot: During the installation of CentOS 6.x (or any older Linux with default grub legacy),
I always install grub legacy on /dev/sda (thereby erasing the last one with the latest one). This will boot
up newly installed CentOS 6.x without any fuss. Then if Centos 6.x is installed under /dev/sda1, then when I am on
CentOS 6.1 prompt, login as root, and issue a command

grub

>root (hd0,0)
>setup (hd0)

Then the bootloader is installed on the first sector of /dev/sda1 (NOT /dev/sda, note the difference).

I may then add then stanza so that i can boot up another old system, and reinstall its native
bootlaoder on MBR, and then
use the boot configuration file to chainload to CentOS 6.x if I want.
A bit troublesome, but it helps to demystify the deep yet simple concept of
bootloader and a boot configuration file, MBR, etc.

Trust me, this work all the time, I did not seem to fail in any case. That's why I thought this is
the cleanest way to do multiboot in the new computers.
But now UEFI can store different bootloaders in a centralized place, and
the BIOS can serve to select any bootloader during boot up time, plus the power offered by grub2 and grub.cfg, the
possibilities to do things are wide open.


Finally, after using CentOS for so long, my basic understanding is that RHEL helps a lot with the
fedora (any way, the Fedora has its origin in RH9=RedHat9), so RHEL people develop
RHEL4.0 (my first RHEL experience), RHEL5.0, RHEL6.0 and RHEL7.0
based on the most current and most well-test (meaning not the most beta) Fedora at any time
as a the starting point to package it.
Then as a good service, CentOS uses the exactly the source codes provided by RHEL to ship out the corresponding
CentOS so that
the free CentOS might report the problems and this provide feedbacks to the upstream (i.e. RHEL).
This is just my basic understand for many years. May be the whole truth is more complicated that this
but I believe what I have typed should be correct to a large degree.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grub2 can't see my win 7 partition and yast2 bootloader can't reinstall grub2 jjrojaspy SUSE / openSUSE 5 07-07-2013 10:38 PM
[SOLVED] GRUB2 - Boot to Partition with Custom Bootloader snmcdonald Linux - General 2 01-04-2012 03:21 PM
LXer: HOWTO: Chainload Grub2 into the Chameleon Boot Loader LXer Syndicated Linux News 0 04-15-2011 03:30 PM
Install grub2 in partition is possible? miros84 Linux - Software 1 11-14-2010 01:59 PM
grub1 floppy chainload grub2 pavel989 Linux - General 3 02-02-2010 10:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration