I'm playing around with fdisk and I tried to create a partition on an empty USB drive. Here's how that went:

Command (m for help): n
Partition number (1-128, default 1): 1
First sector (34-61187102, default 2048): 2048
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-61187102, default 61187102): +30000000         

Created a new partition 1 of type 'Linux filesystem' and of size 14,3 GiB.

so just one partition with 30 million sectors.

However, when I check how many sectors it contains I get:

enter image description here

I'm checking with a different program and I see again that additional sector:

enter image description here

Sorry for the pettiness :) I'm learning.

  • 1
    To expand on what @IporSircer said, if a partition started at 2048 and ended at 2048, would it be 0 or 1 sector long? If it started at 2048 and ended at 2049 (one more) would it be 1 or 2 sectors long? – icarus Oct 6 at 3:04
  • I know that sectors start at 0 but keep in mind I'm not specifying the last sector, just how big the partition needs to be (30million sectors), and my understanding was that the end sector would have been 30.002.047. – mmttato Oct 6 at 3:38
  • @icarus Besides being patronizing, you make no sense whatsoever. Go read (just in the fdisk quoted in the OP's question) what the +size means. I guess that the partition appears as one extra sector larger in that GUI because it also counts the extra bootrecord/header which all the logical partitions have in the PC disk format. – Cocaine Mitch Oct 6 at 4:00
  • @icarus And a simple test will show you that you're trying to create a partition of +1K (1024 bytes), fdisk will create and report having created a partition of size 1.5 KiB (3 instead of 2 sectors). – Cocaine Mitch Oct 6 at 4:11
  • @localuser the prompt is asking for the last sector, not the address of the following sector. The + input format adds that number of sectors to the start sector to give the end sector. So if you specify a start and end of 2048 you get something that is 1 sector long. If you specify a start of 2048 and an end of +0 you get an end of 2048+0 or 2048, and you get something that that is 1 sector long. You can reasonably assert that it would be more convenient if the + format subtracted one sector, but consistency has a lot of merit as well. – icarus Oct 6 at 5:04

man fdisk says

The "last sector" dialog accepts partition size specified by number of sectors or by +/-{K,B,M,G,...} notation.

If the size is prefixed by '+' then it is interpreted as relative to the partition first sector. If the size is prefixed by '-' then it is interpreted as relative to the high limit (last available sector for the partition).

Relative values are applied as in the mathematical operation, to determine the last sector, not the partition size (the documentation is somewhat confusing on this point). On top of that, partitions start at the beginning of their first sector, and end at the end of their last sector. Thus “+0” is a valid entry and results in a partition which starts and ends at the same sector, and contains one sector. In your case, the partition starts at (the start of) sector 2048 and ends at (the end of) sector 2048 + 30000000, i.e. 30,002,048, and contains 30,000,001 sectors.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.