linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rene Herman <rene.herman@gmail.com>
To: Theodore Tso <tytso@mit.edu>, Al Boldi <a1426z@gawab.com>,
	linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFH] Partition table recovery
Date: Sat, 21 Jul 2007 19:54:14 +0200	[thread overview]
Message-ID: <46A24846.7050803@gmail.com> (raw)
In-Reply-To: <20070720160614.GG26752@thunk.org>

On 07/20/2007 06:06 PM, Theodore Tso wrote:

> It wouldn't be that hard to put a backup partition table at the beginning
> of an ext2/3 filesystem.  No one is currently using the space between
> offset 512 and 1023 bytes, and it would be an easy place to stash a
> backup copy of the partition table.  We wouldn't be able to use the MBR
> format, since information about extended partitions are stored scattered
> across the disk.

I was looking into this, but I'm afraid I believe it's not a very good idea.

> So for the sake of argument, I'll propose the following partition
> backup, starting at offset 512 and going for 512 bytes to byte #1023:
> 
> offset 
> from 512  Description
> -------   -----------
> 0..7      Signature ASCII: "PARTBAK1"
> 8..9      Part-type: 1=MBR

Not sure what you mean with this type field. You were suggesting to only 
backup "Plain Ol' Partition" tables anyway weren't you?

> 10	  # of heads
> 11	  # sectors

This is a problem. Today the CHS fields in the partition entries don't mean 
much of anything anymore and Linux happily ignores them but DOS and (hence) 
Windows 9x do not. From time to time I still have the Windows 98 install 
that's sitting in a corner of my disk throw a fit just by having set the 
BIOS from LBA to Large (meaning the geometry the BIOS pretends the disk has 
changes) for example. Old DOS installs that I keep around for the purpose of 
hardware testing with the originally supplied drivers make for even more of 
a "don't touch, don't touch!" thing -- various version of DOS throw fits for 
various reasons.

As such, really the only functional thing to do is backup _whatever_ is 
there in the CHS fields in the entries currently and unfortunately this can 
vary between entries, and certainly between runs of whatever program creates 
them. For example, the user may have adjusted the layout in the BIOS or some 
or all partitions may have been created while the disk was in a different 
machine all together. That is to say, really no attempt should be made at 
being smart about the CHS values -- a backup should just store the actual 
(16-byte) partition table entry.

> 12	  # of partitions in the backup
> 13..15    Reserved (must be zero)
> 16..31	  first part entry
> ...
> 496..511 31st partition entry

And this is the biggest problem. IDE for example allows 63 partitions and 
while in practice not many people will actually also have used that many, 31 
isn't hugely roomy either especially due to the way extended partitions are 
kept.

An extended partition is a partition with type (0x05 || 0x0F || 0x85) the 
first sector of which contains another partition table. That second-level 
partition table generally consists of two entries; the first for the logical 
(actual) partition and the second being yet another extended partition, 
where walking the list gets you all.

However, there can be more than just 1 extended partition on a disk and this 
isn't (or wasn't...) in fact uncommon. Windows 9x at least used to create 
multiple partitions as 1 primary and the rest (even if just 1 as well) as 
logicals inside one 0x05/0x0F extended. When you then installed Linux onto 
the same disk, needed more than the 3 MBR entries left, and wanted to make 
sure that Windows wouldn't trip over any non-fat entries in the list of 
extended partitions (which it did) you'd create 1 0x85 "Linux only" extended 
  in the MBR that Windows just ignores -- not a problem since it couldn't 
read any of the filesystems on them anyway.

This already means you need to keep more information that just the logicals 
(the actual partitions) since you can't reliably restore the tables from a 
list of them alone.

Moveover, the "generally consists of two entries" above isn't guaranteed 
either. The second-level table _can_ contain more than 1 logical. Linux 
never minded much of anything and back when I was experimenting with more 
operating systems (on one disk) they did -- I used to mostly create my 
partition tables with Norton Diskedit at the time...

A bullet-proof backup then has to really store these actual second-level 
tables verbatim again as you can't assume too much about them meaning you're 
going to be storing a complete 4-entry table for every logical which 
ofcourse eats space in the available 512 bytes / 31 entries _way_ too fast.

Moreover once more -- why stop at "normal" logicals? I for example have a 
MINIX 2 partition sitting on this disk and it uses a subpartitioning scheme 
through the same DOS-style second-level partition-table setup. First entry 
in the second-level table is generally used for / and third for /usr meaning 
two additional partitions. And if two aren't bad enough, from time to time 
(when after buying a new disk my ogg vorbis collection hasn't yet grown to 
fill it again yet) I keep a FreeBSD install around which means 6 or so 
additional "slices".

Ignoring those alien partitions is sort of okay, but as said, with only 512 
bytes to spare, this is all inevitable going to be a "sorta works most of 
the time perhaps" sort of solution. The best solution is a little program 
that backs things up verbatim to wherever you want (such as a floppy or USB 
stick for example).

sfdisk -d already works most of the time. Not as a verbatim tool (I actually 
semi-frequently use a "sfdisk -d /dev/hda | sfdisk" invocation as a way to 
_rewrite_ the CHS fields to other values after changing machines around on a 
disk) but something you'd backup on the FS level should, in my opinion, need 
to be less fragile than would be possible with just 512 bytes available.

Rene.

  reply	other threads:[~2007-07-21 17:54 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-20  5:13 [RFH] Partion table recovery Al Boldi
2007-07-20  5:20 ` Dave Young
2007-07-20  5:57   ` Dave Young
2007-07-20 11:29   ` [RFH] Partition " Al Boldi
2007-07-20  5:25 ` [RFH] Partion " James Lamanna
2007-07-20  7:00   ` Jan-Benedict Glaw
2007-07-20 11:29   ` [RFH] Partition " Al Boldi
2007-07-20 11:53     ` Anton Altaparmakov
2007-07-20  5:35 ` [RFH] Partion " Willy Tarreau
2007-07-20  5:44   ` Dave Young
2007-07-20  7:03   ` Jan Engelhardt
2007-07-20 11:29     ` [RFH] Partition " Al Boldi
2007-07-20 11:39       ` Jan-Benedict Glaw
2007-07-20 12:22         ` Al Boldi
2007-07-20 12:29           ` Rene Herman
2007-07-20 16:06           ` Theodore Tso
2007-07-21 17:54             ` Rene Herman [this message]
     [not found]               ` <20070722011141.GJ26752@thunk.org>
2007-07-22  4:10                 ` Al Boldi
2007-07-22 16:28                   ` Theodore Tso
2007-07-22 19:05                     ` Al Boldi
2007-07-22 21:23                     ` Indan Zupancic
2007-07-23  8:15                     ` Rene Herman
2007-07-23  8:41                       ` Jan-Benedict Glaw
2007-07-23 10:54                         ` Rene Herman
2007-07-23 12:39                           ` Rene Herman
2007-07-23 13:15                             ` Jan-Benedict Glaw
2007-07-23 13:32                               ` Rene Herman
2007-07-23 20:22                           ` Bill Davidsen
2007-07-23 13:58                       ` Theodore Tso
2007-07-24  4:08                         ` Rene Herman
2007-07-22  9:11                 ` Rene Herman
     [not found]                   ` <20070722163934.GB20174@thunk.org>
     [not found]                     ` <46A45A01.5050709@gmail.com>
2007-07-23 13:48                       ` Theodore Tso
2007-07-24  3:41                         ` Rene Herman
2007-07-20  6:47 ` [RFH] Partion " Jeffrey V. Merkey
2007-07-20 11:29   ` [RFH] Partition " Al Boldi
2007-07-20  7:35 ` [RFH] Partion " Anton Altaparmakov
2007-07-21 19:40   ` Willy Tarreau
2007-07-23 20:08 ` Bill Davidsen
2007-07-24  3:45   ` Rene Herman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46A24846.7050803@gmail.com \
    --to=rene.herman@gmail.com \
    --cc=a1426z@gawab.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).