Altering MBR to point to new Partition.

Asked by Glen Ellis

History:
I trashed the MBR.
The Partitions and the OS are intact.

Fix:
I re-installed Ubuntu to a new partition, and it wrote a new MBR pointing to itself.

Problem:
The new Ubuntu does not have my old configurations and additional applications.
The old Ubuntu does have my old configurations and additional applications.

The Old Partitions and the Old OS are intact, and the new Grub points into them, and they run fine.
The new Grub points into the new partition and the new /boot/grub/grub.cfg,
. . . which then allows me to select (1) Windows XP, (2) Linux Ubuntu on sda3, (3) Linux Ubuntu on sda7.

To do:
I want to point the new MBR into the OLD partition, which is Linux Ubuntu on sda7.
Then I can delete new OS in sda3 and reuse that disk space for storage.

Overall:
As a Linux skill, I want to be able to write an MBR which points into specific partitions as its starting point.

glene77is, Memphis, TN

****************************************************************************************************************************************
Edited: Feb 06, 2011 by glene77is

Re: Altering MBR to point to new Partition.
Thanks to Ubfan and Delance for their prompt attention.
Ubfan's initial analysis was right on target. My wording was clumsy.
Delance's advice to use the past.ubuntu. site to transfer files is good method.
The actual solution came via Nathan726 on the Ubuntu forums.

SOLUTION:
On Feb 06, 2011, the problem was analyzed and a script written, in the forums.
I executed this script and it was SUCCESSFUL.

The mount and bind and grub-install , etc,
caused a re-link of MBR-to-partition,
changing the bootup linked partitiion from #3 to #7.

Thanks to NATHAN726, Ubuntu forums.
The solution is pasted at:
     http://paste.ubuntu.com/563657/

glene77is, Glen Ellis, Memphis, TN
**********************************************************

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu grub2 Edit question
Assignee:
No assignee Edit question
Solved by:
delance
Solved:
Last query:
Last reply:
Revision history for this message
mycae (mycae) said :
#1

Just boot into the ubuntu OS you wish to retain, and use gparted to trash the one you don't want to keep. gparted can also be used to re-partition the freed up space. If you wish to expand your remaining partition you may need to boot to a liveCD, so the filesystem is not in use whilst you want to expand it.

once done, you can ask grub to re-scan so it updates to match your new configuration.

sudo apt-get install os-prober
sudo os-prober
sudo grub-mkconfig

More info:
https://help.ubuntu.com/community/Grub2

Revision history for this message
Glen Ellis (glene77is) said :
#2

mycae,
Thank  you.
Good Leads.

Did not follow usage for os-prober:
? sudo apt-get install os-prober
? sudo os-prober

Looks right: will read-up on it.
sudo grub-mkconfig

When I have researched these tips,
then things will be be clearer.

Will be replying to the 'Solved' page when done.

_׺°”˜`”°º×..Glen Ellis,  Memphis, TN....·×º°”˜`”°º×_
_׺°”˜`”°º×....Electricity.is.Shocking......·×º°”˜`”°º×_

--- On Sat, 2/5/11, mycae <email address hidden> wrote:

From: mycae <email address hidden>
Subject: Re: [Question #144248]: Altering MBR to point to new Partition.
To: <email address hidden>
Date: Saturday, February 5, 2011, 5:17 PM

Your question #144248 on Ubuntu changed:
https://answers.launchpad.net/ubuntu/+question/144248

    Status: Open => Answered

mycae proposed the following answer:
Just boot into the ubuntu OS you wish to retain,
and use gparted to trash the one you don't want to keep.
gparted can also be used to re-partition the freed up space.
If you wish to expand your remaining partition
you may need to boot to a liveCD,
so the filesystem is not in use whilst you want to expand it.

once done,
you can ask grub to re-scan
so it updates to match your new
configuration.

sudo apt-get install os-prober
sudo os-prober
sudo grub-mkconfig

More info:
https://help.ubuntu.com/community/Grub2

--
If this answers your question, please go to the following page to let us
know that it is solved:
https://answers.launchpad.net/ubuntu/+question/144248/+confirm?answer_id=0

If you still need help, you can reply to this email or go to the
following page to enter your feedback:
https://answers.launchpad.net/ubuntu/+question/144248

You received this question notification because you are a direct
subscriber of the question.

Revision history for this message
Ubfan (ubfan1) said :
#3

The grub files are probably on the new partition, so you probably should do a grub-install again from the old partition before you wipe the new partition and try to reboot.

Revision history for this message
Glen Ellis (glene77is) said :
#4

Ubfan,
You are right on target.
That is what I have observed.
The MBR is pointing into the sda3,
. . . because that is the freshest Ubuntu install.
I want the MBR to point into sda7,
. . . because that is where my real Ubuntu install is located.

(start)
I modified the sda3 grub.cfg to green background, directly.
I modified the sda7 grub.cfg to yellow background, directly.

I booted, it ran through the sda3 green.
I booted, selected sda7 yellow Ubuntu, ran a rebuild on grub.cfg.
I rebooted, into sda3 green, selected sda7 yellow.
Then I checked the sda7 yellow grub.cfg, and it had changes as expected.
The MBR is pointing into the sda3, because that is the freshest Ubuntu install.
(stop)

***********************************************************

To do:
I need a <grub-install -bios>  type routine.
The code in the MBR is pointing to the wrong sda partition.
From the proper partition (sda7) ,
Something like this in order to point right back at this partition (sda7):

# sudo grub_bios-install  --boot-directory=/boot  --no-floppy  --recheck /dev/sda

***********************************************************
This is very helpful

from http://ubuntuforums.org/showthread.php?t-224351 (mistake copying link)

[quote]
How to restore Grub from a live Ubuntu cd.
EDIT: I have not been around in a long time, but it appears grub can still give people headaches I notice people are still referring to this guide now and then, so I wanted to post a link to a grub2 guide. There are differences so you may want to check there as well http://ubuntuforums.org/showthread.php?t=1195275. Glad to see Ubuntu is still going strong Take care.

This will restore grub if you already had grub installed but lost it to a windows install or some other occurence that erased/changed your MBR so that grub no longer appears at start up or it returns an error.

(This how to is written for Ubuntu but should work on other systems. The only thing to take note of, when you see "sudo" that will mean to you that the following command should be entered at a root terminal.)

Boot into the live Ubuntu cd. This can be the live installer cd or the older live session Ubuntu cds.

When you get to the desktop open a terminal and enter. (I am going to give you the commands and then I will explain them later)

Code:

sudo grub

This will get you a "grub>" prompt (i.e. the grub shell). At grub>. enter these commands
/[quote]

In the morning, I'll pick up on this.

_׺°”˜`”°º×..Glen Ellis,  Memphis, TN....·×º°”˜`”°º×_
_׺°”˜`”°º×....Electricity.is.Shocking......·×º°”˜`”°º×_

--- On Sat, 2/5/11, Ubfan <email address hidden> wrote:

From: Ubfan <email address hidden>
Subject: Re: [Question #144248]: Altering MBR to point to new Partition.
To: <email address hidden>
Date: Saturday, February 5, 2011, 9:45 PM

Your question #144248 on grub2 in ubuntu changed:
https://answers.launchpad.net/ubuntu/+source/grub2/+question/144248

Ubfan posted a new comment:
The grub files are probably on the new partition, so you probably should
do a grub-install again from the old partition before you wipe the new
partition and try to reboot.

--
You received this question notification because you are a direct
subscriber of the question.

Revision history for this message
Best delance (olivier-delance) said :
#5

Glen, stop posting with previous message included.
To get a clear image of situation, could you run following procedure
---
provide data about boot configuration

There is a standard script provided to analyze boot configuration.

Could you download script at:

   http://sourceforge.net/projects/bootinfoscript/

Then in a terminal (Ctrl+Alt+T) run command:

    sudo bash boot_info_script055.sh

This will produce a file named: RESULTS.txt

Paste content of this file in http://paste.ubuntu.com/ and provide in this thread the link to Web page.

Please don't post file directly in thread, else it will make thread difficult to read.

Revision history for this message
Glen Ellis (glene77is) said :
#6

Delance,
Thanks for the advice.
Have downloaded, run the script, and RESULTS.txt has been pasted
http://paste.ubuntu.com/563596/

The initial lines says enough about the problem.
 => Grub 2 is installed in the MBR of /dev/sda and looks on the same drive in  partition #8 for /boot/grub.

Goal:
My good install of Ubuntu is in partition #7.
I want the MBR to point to partition #7 for /boot/grub.

http://ubuntuforums.org/showthread.php?t=1682328
Nathan726 posted a scripting solution which looks good.
http://paste.ubuntu.com/563598/

I hope this email is in your usual format and language.

_׺°”˜`”°º×..Glen Ellis,  Memphis,
 TN....·×º°”˜`”°º×_

--- On Sun, 2/6/11, delance <email address hidden>

Revision history for this message
Glen Ellis (glene77is) said :
#7

Delance,

The analysis and suggested scripting from Nathan726 worked well.
Minor hitch on simple mkdir, work around is to use PCMan file mgr.

The MBR-to-partition/boot/grub/grub.cfg link was changed successfully.
Further, his extra notes were very educational.

His SOLUTION is pasted at:
     http://paste.ubuntu.com/563657/

glene77is, Glen Ellis, Memphis, TN
*********************************************

Revision history for this message
Glen Ellis (glene77is) said :
#8

to:
MyCae, UbFan, DeLance, Nathan726.
Thank you again for your expertise.

It is very encouraging to know this is Not Magic,
. . . just a Mystery to be Solved.

This has turned into an interesting journey into MBR-BootLoaders-Grub.
Back when I was programming in assembler (8080, 6502, 6809, Z80)
in the early 80's, we worked with CP/M and then DOS.
Being able to try things with Linux, experiment,
and if it gets mucked up to simply re-install the desk-top OS
is a real treat.
Thank you again for your expertise.