DiracDeBroglie

Partition Boundary Alignment in 4096-byte physical sector drives

28 posts in this topic

Hi,

Got a external USB3.0 2TB drive with 4K physical sectors. It does seem to emulate 512-byte logical sectors though, so it is 512e sector drive. However, there might be a problem with the partition boundary alignment. I would like to partition the drive using the Disk Management tool in Windows 7.

I just want to be sure: Does Windows 7 Home Premium align any partition (primary, extended, logical) with the beginning of any 4K physical sector?? Or is there a risk that Win7 misaligns the partitions, resulting in a reduced performance?

In case Disk Management in Win7 would align the newly created partitions correctly --- meaning at the beginning of any 4K physical sector --- then how can I verify that? Are there any Partition Alignment utilities or tools for that to check?

Johan

0

Share this post


Link to post
Share on other sites

Supposedly Win7 is smart enough to properly align SSDs.

0

Share this post


Link to post
Share on other sites

I just want to be sure: Does Windows 7 Home Premium align any partition (primary, extended, logical) with the beginning of any 4K physical sector?? Or is there a risk that Win7 misaligns the partitions, resulting in a reduced performance?

By default Windows 7 will align the start of the partition to a 4 K boundary.

Namely first partition will start at CHS 0/32/33 or LBA 2048.

(and all following partitions will all be aligned as well)

Having a partition aligned as above makes sense if the partition is NTFS formatted.

If you need/want to use a FAT filesystem you will need to align the fiilesystem clusters (additionally):

To check the alignment you just inspect the MBR (and the eventual EPBR(s)) and verify that the "Sectors Before" or "LBA start Address" can be divided by 8.

A suitable tool could be PTEDIT32 or any similar partition table editor/viewer.

Maybe better if you use partinfo (so that there is no risk to edit a field by mistake):

ftp://ftp.symantec.com/public/english_us_canada/tools/pq/utilities/PartInNT.zip

I don't know if it runs on 7, but it should.

If -by any chance - you are going to use Logical Volumes inside Extended (partitioned/created under 7) AND use on the disk the XP disk manager, be VERY aware :ph34r: of the possible issues:

http://reboot.pro/9897/

jaclaz

Edited by jaclaz
0

Share this post


Link to post
Share on other sites

Nice post! I've looked into this a number of times but enough good sources gave me the gist of "win7 alignment of SSDs works" that I hadn't bothered to dig in and check it myself. This post will come in handy next time I install :)

0

Share this post


Link to post
Share on other sites

Nice post! I've looked into this a number of times but enough good sources gave me the gist of "win7 alignment of SSDs works" that I hadn't bothered to dig in and check it myself. This post will come in handy next time I install :)

Yep :), additionally, the issue with SSD is not exactly the "same" one as with HD's.

The use of a TRIM enabled OS (like Windows 7 is) AND enable it may make a BIG difference (after some time):

http://reboot.pro/9615/

Direct link to the article:

http://www.anandtech.com/storage/showdoc.aspx?i=3531&p=1

More:

http://blogs.msdn.com/b/e7/archive/2009/05/05/support-and-q-a-for-solid-state-drives-and.aspx

And how to make sure TRIM is running:

http://blog.corsair.com/?p=3468

http://lifehacker.com/5640971/check-if-trim-is-enabled-for-your-solid-state-drive-in-windows-7

jaclaz

0

Share this post


Link to post
Share on other sites

>>By default Windows 7 will align the start of the partition to a 4 K boundary.

Q: Do you have any genuine Microsoft documentation of that? Some KB document, clearly and explicitly mentioning that Win7 by default aligns partitions to a 4K boundary. I need to know for sure before I continue working with the 4K HD. I cannot aford to take any risk as the 4K HD of mine will be a backup drive filling up quickly. Any problems lateron will cause me lots of extra work.

>>Namely first partition will start at CHS 0/33/32 or LBA 2048. (and all following partitions will all be aligned as well)

Q: Cilinder/Head/Sector but what sectors are those? Is the number 32 related to 4K or 512e sectors? As for the Logical Block Addressing, what is the block size? Is that the block size defined during formatting of the external HD, that is, 4kB, 8kB, ... 64kB? In case of large block size, one could lose a significant amount of disk space, in the order of many MB!?

>>Having a partition aligned as above makes sense if the partition is NTFS formatted.

Q: How come? Are you insinuating that for other formats (fat32, exfat,....) partition alignment would make less sense?

Thanks, Johan

0

Share this post


Link to post
Share on other sites

>>By default Windows 7 will align the start of the partition to a 4 K boundary.

Q: Do you have any genuine Microsoft documentation of that? Some KB document, clearly and explicitly mentioning that Win7 by default aligns partitions to a 4K boundary. I need to know for sure before I continue working with the 4K HD. I cannot aford to take any risk as the 4K HD of mine will be a backup drive filling up quickly. Any problems lateron will cause me lots of extra work.

You mean that you do not trust my word for it? :w00t:

BTW I provided a link, that - had you actually checked it - may have lead you to here (from the mouth of the wolf, but you will need to "read between the lines"):

http://support.microsoft.com/kb/931760/en-us

Vista :ph34r: and 7 have a Registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\SERVICES\VDS\ALIGNMENT

which you can use to override default partition alignment (which is respecting the 4K multiple).

Additional (JFYI):

http://www.techpowerup.com/forums/showthread.php?t=107126

>>Namely first partition will start at CHS 0/33/32 or LBA 2048. (and all following partitions will all be aligned as well)

Q: Cilinder/Head/Sector but what sectors are those? Is the number 32 related to 4K or 512e sectors? As for the Logical Block Addressing, what is the block size? Is that the block size defined during formatting of the external HD, that is, 4kB, 8kB, ... 64kB? In case of large block size, one could lose a significant amount of disk space, in the order of many MB!?

The MBR will use 512 bytes sized sectors.

Block (or sector) size has nothing to do with cluster size.

>>Having a partition aligned as above makes sense if the partition is NTFS formatted.

Q: How come? Are you insinuating that for other formats (fat32, exfat,....) partition alignment would make less sense?

I am NOT "insinuating" anything, I am stating (rather flatly ;))that the internal structrures of a FAT (12/16/32 and presumably 64) may (actually will in, say, 90% of cases) produce the effect that the filesystem clusters NOT to be aligned properly (and provided a link that explains in detail the issue).

jaclaz

0

Share this post


Link to post
Share on other sites

Jaclaz,

I just ran the PartitionInfo utility from Symantec. The 4k-byte sector 2TB drive that I have is from Seagate and came formatted as FAT32X. According to PartitionInfo the start sector is 2048, so can be divided by 8; also the number of hidden sectors is 2048. So that data looks consistent but what one would expect taking into account the format is FAT32X. However, in the header of PartitionInfo there are several error messages saying that the partition didn't begin on Head Boundary, ended after end of disk, .... Note all the testing is done on WinXP.

So, I'll reformat the 4k-byte sector drive asap with Win7.

johan

0

Share this post


Link to post
Share on other sites

Jaclaz,

I just ran the PartitionInfo utility from Symantec. The 4k-byte sector 2TB drive that I have is from Seagate and came formatted as FAT32X. According to PartitionInfo the start sector is 2048, so can be divided by 8; also the number of hidden sectors is 2048. So that data looks consistent but what one would expect taking into account the format is FAT32X. However, in the header of PartitionInfo there are several error messages saying that the partition didn't begin on Head Boundary, ended after end of disk, .... Note all the testing is done on WinXP.

Sure :), partition info was developed WHEN the "standard" was n/255/63, it is normal that it tells you that the current partitioning scheme does NOT respect cylynder (255/63) or Head (63) alignment.

So, I'll reformat the 4k-byte sector drive asap with Win7.

The partition is ALREADY aligned.

The (FAT32) filesystem clusters most probably WON'T be, and if you re-format (still FAT32) it under windows 7 NOTHING will change, as I tried to explain you.

If you re-format (no matter if under XP or 7) as NTFS, filesystem clusters will be (inherently) aligned.

Further explanation:

  • due to how NTFS is made, data clusters are alway aligned on 4K multiples from the beginning of the partition, hence, IF the partition is aligned, so will be the filesystem clusters (the bootsector, i.e. reserved sectors is a multiple of 4Kb, being 16 x 512 bytes long and all other structures are actually "files").
  • on FAT there are a number of data structures (bootsector/reserved sectors, FAT tables and - on FAT12/16 only - root directories) that are placed BEFORE the actual data clusters and that may not result as being a multiple of 4 Kb, hence, even if the beginning of the parition is aligned, filesystem clusters may not.

This is the essence of the referenced thread.

I hope now it is more clear. :unsure:

jaclaz

Edited by jaclaz
0

Share this post


Link to post
Share on other sites

Jaclaz,

Yes, now it has become clear to me why alignment of partitions is not enough when dealing with FAT (and maybe other file systems) . Fortunately, I'll be using NTFS on the drive. You have been a great help, without your info I would still be dangling on Google and waisting many more manhours. It's still not over for me; I still need to re-partition the drive to NTFS under Win7, and perform analysis on the drive to see if all is ok. I'll be back on this thread maybe later. I still need to install a SSD next coming few weeks or so. Also that may still raise some performance issues, I'll see.

johan

0

Share this post


Link to post
Share on other sites

Yes, now it has become clear to me why alignment of partitions is not enough when dealing with FAT (and maybe other file systems) . Fortunately, I'll be using NTFS on the drive. You have been a great help, without your info I would still be dangling on Google and waisting many more manhours.

Good. :)

jaclaz

0

Share this post


Link to post
Share on other sites

Jaclaz,

Just had a look at the key

HKEY_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\SERVICES\VDS\ALIGNMENT

that you mentioned earlier using RegEdit. Indeed there are the keys:

Between4_8GB

Between8_32GB

GreaterThan32GB

LessThan4GB

and presumably they all have an offset of 1048576 (bytes), except for LessThan4GB, which has an offset of 65536 bytes. Then 1048576 / 4096 = 256, and 65536 / 4096 = 16. So it looks that any 512 or 4096-byte sector drive has its partitions automatically aligned in Win7. Is that a correct conclusion?

I just wonder why the offset is so large? 256 times 4Kib offset is a lot. What could be the reason for that?

And, are those gaps of 1048576 (bytes) also present between the partitions?

Got also a question about the Master Boot Record. Usually the MBR is 512 bytes, but how long is the MBR in a 4KiB sector drive? Could be interesting to know because maybe I'll use my 2TB drive as an internal boot drive lateron.

johan

Edited by DiracDeBroglie
0

Share this post


Link to post
Share on other sites

Jaclaz,

Just had a look at the key

HKEY_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\SERVICES\VDS\ALIGNMENT

that you mentioned earlier using RegEdit. Indeed there are the keys:

Between4_8GB

Between8_32GB

GreaterThan32GB

LessThan4GB

and presumably they all have an offset of 1048576 (bytes), except for LessThan4GB, which has an offset of 65536 bytes. Then 1048576 / 4096 = 256, and 65536 / 4096 = 16. So it looks that any 512 or 4096-byte sector drive has its partitions automatically aligned in Win7. Is that a correct conclusion?

Yep :).

I just wonder why the offset is so large? 256 times 4Kib offset is a lot. What could be the reason for that?

That's a MS decision :ph34r: , if you check the "alignment jumper" that there is on some 4 Kb sector HD's (I seem to remember Seagate), you will see that they add a "fake" sector so that older OS (XP, that has hardcoded 63 as "boundary") will partition disk starting from sector 64.

Since this has been made by the actual HD manufacturer, it means that 64 is "good enough".

And, are those gaps of 1048576 (bytes) also present between the partitions?

Yes/No.

There is NOT any gap between two primaries. (the previous is already aligned at start and has a size that is a 4 Kb multiple, so also it's end is aligned, hence the following is already aligned).

There is no "gap" between a primary and an Extended (for the same reason) but there is a gap inside the extended until the beginning of the first Logical Volume and between any two Logical Volumes.

These gaps were 63 sectors in the "previous standard" and are probably (but I have never had an occasion to check) 2048 in the "new standard". :unsure:

Got also a question about the Master Boot Record. Usually the MBR is 512 bytes, but how long is the MBR in a 4KiB sector drive? Could be interesting to know because maybe I'll use my 2TB drive as an internal boot drive lateron.

This is a common doubt.

Traditionally we have seen (because they were like that ;)) that the MBR is first sector of a hard disk.

It is NOT like that (it is :), but we have to slightly change the definition)

The MBR is the first 512 bytes of the first sector of a hard disk.

When we say that the "magic Bytes" 55AA are the last two bytes of first sector, we commit a mistake they are the last two bytes of the MBR, or even more properly the bytes at offset 510 and 511 of the first sector of a hard disk.

The above, that now may seem obvious, comes (extrapolated by yours truly :w00t: porting it from "bootsector" to "MBR") UNexpectedly by a seemingly not connected MS doc , the FAT32 specification:

http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/fatgen103.doc

Though evidently written by a snotty MS kid that thinks to be much smarter than his intended audience :realmad: , and provides among senceful info also a few wrong or misleading info, it contains this:

There is one other important note about Sector 0 of a FAT volume. If we consider the contents of the sector as a byte array, it must be true that sector[510] equals 0x55, and sector[511] equals 0xAA.

NOTE: Many FAT documents mistakenly say that this 0xAA55 signature occupies the “last 2 bytes of the boot sector”. This statement is correct if — and only if — BPB_BytsPerSec is 512. If BPB_BytsPerSec is greater than 512, the offsets of these signature bytes do not change (although it is perfectly OK for the last two bytes at the end of the boot sector to also contain this signature).

jaclaz

0

Share this post


Link to post
Share on other sites

Hi, Jaclaz,

I just wonder why the offset is so large? 256 times 4Kib offset is a lot. What could be the reason for that?

That's a MS decision :ph34r: , if you check the "alignment jumper" that there is on some 4 Kb sector HD's (I seem to remember Seagate), you will see that they add a "fake" sector so that older OS (XP, that has hardcoded 63 as "boundary") will partition disk starting from sector 64.

Since this has been made by the actual HD manufacturer, it means that 64 is "good enough".

64 x 512 = 32768 bytes (=8 times 4K sectors) or

64 x 4096 = 2642144 bytes, which is 1/4 of the offset in the Win7 registry key being 1048576 (=256 times 4K sectors).

Problem is that it is not quite clear to me if one means a sector of 512 bytes or 4096 bytes. Fortunately, in the Win7 key they use simply bytes as offset, which is not susceptible to interpretation.

And, are those gaps of 1048576 (bytes) also present between the partitions?

Yes/No.

There is NOT any gap between two primaries. (the previous is already aligned at start and has a size that is a 4 Kb multiple, so also it's end is aligned, hence the following is already aligned).

There is no "gap" between a primary and an Extended (for the same reason) but there is a gap inside the extended until the beginning of the first Logical Volume and between any two Logical Volumes.

These gaps were 63 sectors in the "previous standard" and are probably (but I have never had an occasion to check) 2048 in the "new standard". :unsure:

Is that 2048 times 512bytes, or 2048 x 4K? The first results in 2048 x 512 = 1048576 bytes, which is the same value in the registry key mentioned earlier. So 256 times a 4K sector between the logical volumes: that is a lot!

Got also a question about the Master Boot Record. Usually the MBR is 512 bytes, but how long is the MBR in a 4KiB sector drive? Could be interesting to know because maybe I'll use my 2TB drive as an internal boot drive lateron.

This is a common doubt.

Traditionally we have seen (because they were like that ;)) that the MBR is first sector of a hard disk.

It is NOT like that (it is :), but we have to slightly change the definition)

The MBR is the first 512 bytes of the first sector of a hard disk.

So, the first 512 bytes of the first 4K sector are used as MBR. A petty that the last 7 short (512bytes) sectors in the first 4K sectors are not used. That extra space could have been used for larger bootloaders, for instance, in case one wants to boot multiple OSs. Also the remaining 255 4K sectors between the first 4K boot sector and the beginning of the first partition are just sitting there. What is that space used for? For extra and larger bootloaders, maybe?

johan

When we say that the "magic Bytes" 55AA are the last two bytes of first sector, we commit a mistake they are the last two bytes of the MBR, or even more properly the bytes at offset 510 and 511 of the first sector of a hard disk.

The above, that now may seem obvious, comes (extrapolated by yours truly :w00t: porting it from "bootsector" to "MBR") UNexpectedly by a seemingly not connected MS doc , the FAT32 specification:

http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/fatgen103.doc

Though evidently written by a snotty MS kid that thinks to be much smarter than his intended audience :realmad: , and provides among senceful info also a few wrong or misleading info, it contains this:

There is one other important note about Sector 0 of a FAT volume. If we consider the contents of the sector as a byte array, it must be true that sector[510] equals 0x55, and sector[511] equals 0xAA.

NOTE: Many FAT documents mistakenly say that this 0xAA55 signature occupies the “last 2 bytes of the boot sector”. This statement is correct if — and only if — BPB_BytsPerSec is 512. If BPB_BytsPerSec is greater than 512, the offsets of these signature bytes do not change (although it is perfectly OK for the last two bytes at the end of the boot sector to also contain this signature).

jaclaz

Edited by DiracDeBroglie
0

Share this post


Link to post
Share on other sites

64 x 512 = 32768 bytes (=8 times 4K sectors) or

64 x 4096 = 2642144 bytes, which is 1/4 of the offset in the Win7 registry key being 1048576 (=256 times 4K sectors).

64 x 512 = 32768 bytes (=8 times 4K sectors)

Problem is that it is not quite clear to me if one means a sector of 512 bytes or 4096 bytes.

Unless otherwise specified, 512 bytes/sector.

Is that 2048 times 512bytes, or 2048 x 4K? The first results in 2048 x 512 = 1048576 bytes, which is the same value in the registry key mentioned earlier. So 256 times a 4K sector between the logical volumes: that is a lot!

Well, with disks of hundreds of Gigabytes, 1 Mb is not that much.

If you think about it, older (much smaller) disks always had a bunch of unused sectors at the end, as the "steps" or "size increment/decrement" for any partition was 1 cylinder, i.e. 1x255x63x512=8,225,280 bytes, depending on a few factors there has always been this unused space in the theoretical range 0÷8,224,768, but often nearer to the upper limit.

So, the first 512 bytes of the first 4K sector are used as MBR. A petty that the last 7 short (512bytes) sectors in the first 4K sectors are not used. That extra space could have been used for larger bootloaders, for instance, in case one wants to boot multiple OSs. Also the remaining 255 4K sectors between the first 4K boot sector and the beginning of the first partition are just sitting there. What is that space used for? For extra and larger bootloaders, maybe?

No, you got this part wrong. :ph34r:

We thought for years that the BIOS accessed first (512 byte) sector and that that (first seector) was the MBR.

It is simply not like this.

The MBR is the first 512 bytes of the first sector, NO MATTER sector size.

There are already more than a few (grub4dos as an example) bootmanagers/bootloaders that use several (512 bytes) sectors after the first one (grub4dos' grldr.mbr uses, if I recall correctly, first 18 sectors of a hard disk (512 bytes each) or if you prefer, it is 9,216 bytes in size.

The grub4dos' grldr.mbr contains in the first 512 bytes, i.e. what is actually READ during booting some code that makes the BIOS read from 513th byte onwards (actually normally from 1025th, as second block of 512 bytes is a backup of the previous MBR if any) up to 9,216th.

jaclaz

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.