LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 06-14-2005, 04:05 PM   #1
LinuxGeek
Member
 
Registered: Jun 2002
Posts: 302

Rep: Reputation: 31
How to Backup MBR?


Hi,
I was wondering how you could back up your MBR in case it is overwritten, for example. I know the command:

dd if=/dev/hda of=/root/mbr bs=512 count=1

but the shortcoming with this approach is that the partition table for only the primary partitions is saved. What would I do if I wanted the partition tables of the logical partitions to be saved. Would I do something like:

dd if=/dev/hda4 of=/root/mbrlogical bs=512 count=1

I'm asking because I'm not sure how big it should be or is. Is there any way to know? Thanks for your time.
 
Old 06-14-2005, 04:16 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
If you are wanting to back up the partition table then I would use sfdisk:
sfdisk -d /dev/hda > part_layout.txt

Then you can restore with:
sfdisk /dev/hda < part_layout.txt

This is also a good way to set up partitions for a raid 1 system.
 
Old 06-14-2005, 06:59 PM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,838

Rep: Reputation: 340Reputation: 340Reputation: 340Reputation: 340
http://www.cpqlinux.com/ddbackup.html has an interesting discussion on this very topic.
 
Old 06-14-2005, 08:03 PM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 58
Quote:
dd if=/dev/hda of=/root/mbr bs=512 count=1

but the shortcoming with this approach is that the partition table for only the primary partitions is saved.
Actually, that command works very nicely with extended / logical parttions also.
 
Old 06-14-2005, 09:29 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 13,368

Rep: Reputation: 1312Reputation: 1312Reputation: 1312Reputation: 1312Reputation: 1312Reputation: 1312Reputation: 1312Reputation: 1312Reputation: 1312Reputation: 1312
Re: How to Backup MBR?

Quote:
Originally posted by LinuxGeek
I was wondering how you could back up your MBR in case it is overwritten, for example. I know the command:
dd if=/dev/hda of=/root/mbr bs=512 count=1

but the shortcoming with this approach is that the partition table for only the primary partitions is saved. What would I do if I wanted the partition tables of the logical partitions to be saved. Would I do something like:
dd if=/dev/hda4 of=/root/mbrlogical bs=512 count=1
This will (probably) achieve what you are looking for.
IMHO a bit pointless, but that's o.k.
The "logical" part table(s) within each logical partition are chained (forward chain only). A single sector per logical partition should be sufficient.

Let's hope your root isn't mounted on the disk you are trying to salvage ...

Note that the MBR backup will also have the data for the extended partition in addition the the primary/primaries.

Edit: Go with sfdisk as suggested by david_ross.
*MUCH* better option - hadn't seen that use of it.

Last edited by syg00; 06-15-2005 at 12:56 AM.
 
Old 06-15-2005, 09:18 PM   #6
LinuxGeek
Member
 
Registered: Jun 2002
Posts: 302

Original Poster
Rep: Reputation: 31
Thanks... So using sfdisk -d would dump both the MBR contents and the logical partition information in hdx4, right?

syg000, "Note that the MBR backup will also have the data for the extended partition in addition the the primary/primaries."

It should just have the data for the start and end of the extended partition but no information about the logical partitions.
 
Old 06-15-2005, 10:01 PM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 13,368

Rep: Reputation: 1312Reputation: 1312Reputation: 1312Reputation: 1312Reputation: 1312Reputation: 1312Reputation: 1312Reputation: 1312Reputation: 1312Reputation: 1312
Quote:
So using sfdisk -d would dump both the MBR contents and the logical partition information in hdx4, right?
Yep - all the partitions. Try it and have a look at the text file outputted.
Quote:
syg000, "Note that the MBR backup will also have the data for the extended partition in addition the the primary/primaries."

It should just have the data for the start and end of the extended partition but no information about the logical partitions.
This is true - I made no mention of logicals. That note was to alert you to the error of your first post;"but the shortcoming with this approach is that the partition table for only the primary partitions is saved".
 
Old 06-16-2005, 03:54 PM   #8
LinuxGeek
Member
 
Registered: Jun 2002
Posts: 302

Original Poster
Rep: Reputation: 31
Thanks for your help...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
MBR zeroed. Can I verify backup MBR? TomF Linux - General 7 06-20-2005 05:28 PM
by tring to fix the MBR i damage the MBR that was help... AKAKAK Fedora 4 03-21-2005 08:18 AM
How to backup & restore the MBR in linux? sgzlit Linux - Newbie 7 03-02-2005 09:07 PM
MBR software or tools for backup/restore Rubedogg Linux - Newbie 1 12-08-2004 02:58 PM
backup MBR and FIXMBR leessusan Linux - Laptop and Netbook 2 09-23-2004 01:31 AM


All times are GMT -5. The time now is 03:14 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration