Re: [RFC] Restoring HDIO_GETGEO semantics (was: Re: workaround for BIOS / CHS stuff)

Andrew Clausen
2004-07-03T12:45:32Z

On Sat, Jul 03, 2004 at 08:53:39AM +0100, Anton Altaparmakov wrote:
> On Sat, 3 Jul 2004, Andrew Clausen wrote:
> > In any case, I don't have any evidence that anything is wrong. On my
> > computer, I can tell the BIOS to use CHS geometry, (as opposed to
> > "Auto", "LBA" or "Large") modify the partition table to set the CHS
> > start/end of the Windows partition to 0, 1024, or anything I like, and
> > Windows STILL works. I can't get anything to break!
>
> Which version of Windows?

XP home edition (the green box)

> Does it use NTFS as both the boot and system drive?

I am using a single NTFS partition.

Note: I reversed-engineered the Windows FAT bootstrap code. My analysis
is contained in the file doc/FAT in the Parted source distribution. I
concluded that Windows uses LBA if the LBA flag is set in the boot
partition table entry. (i.e. the partition type includes LBA in the
fdisk codes - this corresponds to a bit being set)

> > So, can anyone break Windows?
>
> Easily. Modify any of the relevant values in the NTFS bootsector and
> windows will no longer boot. So it clearly cares hugely about the
> geometry. And at present there is no easy way for us to tell what it is
> so mkntfs and ntfsclone cannot create bootable partitions on 2.6 kernels.
> (Works fine on 2.4 using HDIO_GETGEO.)
>
> The relevant fields are (see linux/fs/ntfs/layout.h or
> ntfsprogs/include/ntfs/layout.h) in the NTFS_BOOT_SECTOR in the
> BIOS_PARAMETER_BLOCK:
>
> u16 sectors_per_track; /* Required to boot Windows. */
> u16 heads; /* Required to boot Windows. */
> u32 hidden_sectors; /* Offset to the start of the partition relative
> to the disk in sectors. Required to boot Windows. */

I just set the first 2 of these fields to 0, and everything still works.
Am I blessed? (Or perhaps cursed!)

Isn't hidden_sectors an LBA value (and hence irrelevant to this discussion)?

Cheers,
Andrew