From: James Bottomley on
On Tue, 2010-03-16 at 23:50 +0900, Tejun Heo wrote:
> e.g. If the first partition begins at CHS 0/32/33 and ends at
> 12/233/19 and the corresponding LBA addresses are 2048 and 206848, you
> can solve the equation and determine that the parameters gotta be 63
> secs/trk and 255 heads/cyl to make those two pairs of addresses match
> each other and in fact some BIOSs try to do this depending on
> configuration (and sometimes falls into infinite loop or causes other
> boot related problems if the parameters are too uncommon).

for an msdos label, this is illegal, that was Arnd's point. The
partitions have to begin and end on cylinder boundaries*. Knowing that,
you can deduce the geometry from the last sector entry.

James

* at least if you want to preserve windows compatibility, which is what
most of our partitioning tools seem to do.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Tejun Heo on
Hello,

On 03/16/2010 11:38 PM, Denys Vlasenko wrote:
> The "end of partition" is expected to be at the last head and sector.
> Of course this heuristic fails if there are more than one primary
> partition and they have differing last head and sector.
>
> But on most "sanely" partitioned disks they are the same:
>
> Disk /dev/sda: 255 heads, 63 sectors, 36481 cylinders
>
> Nr AF Hd Sec Cyl Hd Sec Cyl Start Size ID
> 1 00 1 1 0 254 63 850 63 13671252 0b
> 2 80 0 1 851 254 63 1023 13671315 572395950 05
> 3 00 0 0 0 0 0 0 0 0 00
> 4 00 0 0 0 0 0 0 0 0 00
> 5 00 1 1 851 254 63 972 63 1959867 83
> 6 00 1 1 973 254 63 1023 63 31246362 83
> 7 00 254 63 1023 254 63 1023 63 195318207 83
> 8 00 254 63 1023 254 63 1023 63 343871262 83
> ^^^ ^^

C/H/S of 1023/254/63 is a special marker indicating the value there is
out-of-range. It doesn't actually carry any information regarding the
geometry parameters other than that the matching LBA can't be
expressed within its range. The end marker doesn't change according
to geometry parameters. It's fixed at 0xfeffff.

> Which suggests another idea how to align a partition: since there is
> no requirement on the partition *start*, we don't have to start at
> head1,sector1 or head0,sector1

We don't have to align to cylinders either.

> In the example above, 1st partition might be modified to start at
> head1,sector2, IOW, LBA 64, thus making it 32k aligned.
>
> As long as partition *ends* adhere to the convention of being
> exactly at last_head,last_sector, nothing should break.

That has almost nothing to do with compatibility. Just let the
cylinder alignment go. Anything remotely modern doesn't care about it
at all and anything older will puke way easier with custom geometry
massaging. For those, we'll just have to stick with cylinder aligning
according to the BIOS supplied parameters.

Thanks.

--
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Denys Vlasenko on
On Tue, Mar 16, 2010 at 4:12 PM, Tejun Heo <tj(a)kernel.org> wrote:
>> The "end of partition" is expected to be at the last head and sector.
>> Of course this heuristic fails if there are more than one primary
>> partition and they have differing last head and sector.
>>
>> But on most "sanely" partitioned disks they are the same:
>>
>> Disk /dev/sda: 255 heads, 63 sectors, 36481 cylinders
>>
>> Nr AF �Hd Sec �Cyl �Hd Sec �Cyl � � �Start � � � Size ID
>> �1 00 � 1 � 1 � �0 254 �63 �850 � � � � 63 � 13671252 0b
>> �2 80 � 0 � 1 �851 254 �63 1023 � 13671315 �572395950 05
>> �3 00 � 0 � 0 � �0 � 0 � 0 � �0 � � � � �0 � � � � �0 00
>> �4 00 � 0 � 0 � �0 � 0 � 0 � �0 � � � � �0 � � � � �0 00
>> �5 00 � 1 � 1 �851 254 �63 �972 � � � � 63 � �1959867 83
>> �6 00 � 1 � 1 �973 254 �63 1023 � � � � 63 � 31246362 83
>> �7 00 254 �63 1023 254 �63 1023 � � � � 63 �195318207 83
>> �8 00 254 �63 1023 254 �63 1023 � � � � 63 �343871262 83
>> � � � � � � � � � �^^^ �^^
>
> C/H/S of 1023/254/63 is a special marker indicating the value there is
> out-of-range.

You misunderstood my ^^^ markers. I was trying to highlight
the whole columns of "end head" and "end sector", not the
last partition's 1023/254/63 values.

In the partition table like shown above it is obvious
that geometry is 255/63.

>> Which suggests another idea how to align a partition: since there is
>> no requirement on the partition *start*, we don't have to start at
>> head1,sector1 or head0,sector1
>
> We don't have to align to cylinders either.

If neither the start nor the end is aligned to cylinder's end
and disk has just one partition and it's bigger than 8G,
there is not way to determine geometry.

If everybody adopts the convention of ending the partitions
at the cylinder end, geometry can be trivially determined by
looking at partition end values. Sans "no of cylinders" value,
which can be easily determined by other means.

>> In the example above, 1st partition might be modified to start at
>> head1,sector2, IOW, LBA 64, thus making it 32k aligned.
>>
>> As long as partition *ends* adhere to the convention of being
>> exactly at last_head,last_sector, nothing should break.
>
> That has almost nothing to do with compatibility. �Just let the
> cylinder alignment go.

Then (some) bootloaders will stop working.

--
vda
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: James Bottomley on
On Wed, 2010-03-17 at 00:20 +0900, Tejun Heo wrote:
> On 03/17/2010 12:02 AM, James Bottomley wrote:
> > On Tue, 2010-03-16 at 23:50 +0900, Tejun Heo wrote:
> >> e.g. If the first partition begins at CHS 0/32/33 and ends at
> >> 12/233/19 and the corresponding LBA addresses are 2048 and 206848, you
> >> can solve the equation and determine that the parameters gotta be 63
> >> secs/trk and 255 heads/cyl to make those two pairs of addresses match
> >> each other and in fact some BIOSs try to do this depending on
> >> configuration (and sometimes falls into infinite loop or causes other
> >> boot related problems if the parameters are too uncommon).
> >
> > for an msdos label, this is illegal, that was Arnd's point. The
> > partitions have to begin and end on cylinder boundaries*. Knowing that,
> > you can deduce the geometry from the last sector entry.
> >
> > * at least if you want to preserve windows compatibility, which is what
> > most of our partitioning tools seem to do.
>
> Well, the thing is that
>
> * Anything remotely modern (>= XP) doesn't give a hoot about cylinder
> alignment.
>
> * Anything older (<= 2000) is very likely to get confused with custom
> geometry starting from the BIOS itself. For those cases, the only
> thing we can do is aligning partitions to cylinders abiding BIOS
> supplied geometry parameters which will usually be 255/63.
>
> So, using custom geometry doesn't help compatibility at all.

Our partitioning tool still obey the integral cylinder rule ... we can
argue about whether they should, but what we need is a strategy for
fixing what is rather than what should be.

James

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Martin K. Petersen on
>>>>> "Tejun" == Tejun Heo <tj(a)kernel.org> writes:

Tejun> * Anything remotely modern (>= XP) doesn't give a hoot about
Tejun> cylinder alignment.

Tejun> * Anything older (<= 2000) is very likely to get confused with
Tejun> custom geometry starting from the BIOS itself. For those
Tejun> cases, the only thing we can do is aligning partitions to
Tejun> cylinders abiding BIOS supplied geometry parameters which will
Tejun> usually be 255/63.

Tejun> So, using custom geometry doesn't help compatibility at all.

Great reads on this topic. Might be worth linking to:

http://www.win.tue.nl/~aeb/partitions/partition_types.html

http://www.win.tue.nl/~aeb/linux/largedisk.html

--
Martin K. Petersen Oracle Linux Engineering
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/