LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > Lumak's Guide to Random Things
User Name
Password

Notices


OK I don't really have a good title yet but I figure I can post works in progress and other tips I've come across or other interesting things.
Rate this Entry

Fixing the MBR without loosing data.

Posted 12-14-2008 at 02:21 PM by lumak
Updated 12-16-2008 at 01:50 PM by lumak

First let me explain my situation. I was playing with Slackware 12.1 and making partitions on a new system, I got lost somewhere withmy partitions and had the crazy idea of dualbooting slackware to have a safe build environment from my system. (I ended up just using the build environment which lead me to wanting a chroot jail instead... ANYWAY)

I screwed things up and had lilo installed on boot records in several different places. How do you fix this then?!

You restore your boot record and make sure to install lilo ON YOUR PARTITION BOOT RECORD.

First thing is you got to remove only the executable code from the MBR.

Code:
# /dev/hda is your harddrive device and NOT a partition
# a partition boot record is 512
# executable code is in the first 446
dd if=/dev/zero of=/dev/hda bs=446 count=1
BUT there is a catch!
This blanks the executable code!
Your bios now doesn't know how to send control from the MBR to the actual partition you want to boot!

a few man minutes later
Code:
# use mbr if the boot partition is on a primary partition
# use ext if the boot partition is on a logical partition
lilo -M /dev/hda mbr
# This is the same as using (c)fdisk to activate a partition
# for booting.  Also note the space.
lilo -A /dev/hda 1
Without this step, even though I had lilo installed onto a partition boot record, nothing was booting. I'm guessing that at the very least there needs to be generic code in the MBR for anything to happen at all. The real question would be, what about windows? I have no clue. I don't dual boot windows anymore. IF I do install windows, it's going to be with a virtual machine. I would rather control windows rather than windows control my machine.

Now you can go about installing lilo properly. Me personally, I have a boot partition /boot just in case I want to boot other linux OSes for testing, I can build a kernel and place it on the boot partition and run lilo again... or chroot my main os and run lilo again.

I also install lilo into the partition boot record of the /boot partition... believe this is done by having
Code:
boot = /dev/hda1
in the lilo.conf

I'm sure I'm misunderstanding something here... BUT this is how I fixed things before installing slackware 12.2 Everything seems to be working now.

Incase you were wondering how badly my system was partitioned before... I had space for 2 or 3 oses on /dev/hda as well as wasted space for an os on /dev/sda. I fixed everything now by blanking /dev/hda, tossing all my saved files there, blanking /dev/sda, fixing partitions for only 1 os (any 'dual' booting will be going on the slower older /dev/hda) then I ran into my booting problem with old lilo reminance, figured out all this crap to fix it, and restored my system with a fresh 12.2! No more random lilo code laying around. (at least I hope it was cleaned off all the other partition boot records. I destroyed all the partition tables and it was 'different' enough that it's probably all gone.) Never figured out how to clean partition boot records. Don't even know if such a thing is possible. Read a better manual. I fixed my problem, that's all that was needed.
Views 1530 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



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

Main Menu
Advertisement
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