On my machine, fdisk -lu /dev/sda displays following output:
Device Boot Start End Blocks Id System /dev/sda1 * 2048 73947135 36972544 83 Linux /dev/sda2 73949182 78139391 2095105 5 Extended /dev/sda5 73949184 78139391 2095104 82 Linux swap / Solaris
What is this “blocks” unit? Is one “fdisk block” a 1KiB? Where does this unit come from?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
In the first versions of Unix, a block was 512 bytes all the way from the hardware through the filesystem through C code to user tools.
Nowadays there are many different types of hardware and many different filesystems (some of which don’t have any notion of block size), so “block size” is an arbitrary definition chosen by each tool. Most traditional Unix systems have retained the 512-byte block size by default for backward compatibility, and this is what POSIX mandates for several commands (dd, du, df, ls, find -size, …). Several GNU/Linux utilities display 1kB units by default (du, df, ls, …) unless invoked in POSIXLY_CORRECT mode. I think the move to 1kB is solely motivated because it’s a lot friendlier to humans.
The Linux fdisk utility used 1kB blocks for two decares — the header might as well have read kB. In the context of Linux’s fdisk, “block” always means 1kB. The default unit changed in version 2.25, now the unit is sectors of 512 bytes. In expert mode, the unit has always been sectors of 512 bytes. 512 byte is a more natural low-level unit for traditional PC disks because they write in 512-byte sectors, and partition boundaries are aligned to 512 bytes, so using 1kB as the unit leads to ½ fractions. Modern large disks have larger sectors (but “sectors” is widely used to mean 512 bytes regardless of any physical or logical characteristics of the disk), and GPT partitions are normally aligned on 1MB.
Method 2
You should know some concepts like sector, track, cylinder to understand block. Here is a simple definition:
Blocks and clusters The Unix communities employ the term block to refer to a sector or group of sectors. For example, the Linux fdisk utility normally displays partition table information using 1024-byte blocks, but also uses the word sector to help describe a disk's size in the phrase, 63 sectors per track.
You can read more in this link.
Method 3
I don’t believe fdisk does do 1k block reports – or that it reports on blocks at all. From the man page:
-u,--units[=unit]
- When listing partition tables, show sizes in sectors or in cylinders. The default is to show sizes in sectors. For backward compatibility, it is possible to use the option without the unit argument – then the default is used. Note that the optional unit argument cannot be separated from the
-uoption by a space, the correct form is for example-u=cylinders.
Ok, so fdisk doesn’t list output as blocks, then. It uses cylinders or sectors by default. Well, here’s what wikipedia has to say about a sector:
In computer disk storage, a sector is a subdivision of a track on a magnetic disk or optical disc. Each sector stores a fixed amount of user-accessible data, traditionally 512 bytes for hard disk drives (HDDs) and 2048 bytes for CD-ROMs and DVD-ROMs. Newer HDDs use 4096-byte (4 KiB) sectors, which are known as the Advanced Format (AF).
Now that makes more sense to me. I had never heard of a 1K sector before, and so stumbling upon this confused me. Some googling though did reveal that there was a small run of Seagate branded drives which shipped for a portion of the year 2005 that did report a sector size of 1K.
And anyway, it’s right there in the header output:
Disk /dev/sda: 111.8 GiB, 120034123776 bytes, 234441648 sector
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: E12A6152-B1E6-4D4A-9799-491B339BA633
Device Start End Sectors Size Type
/dev/sda1 4096 6197247 6193152 3G EFI System
/dev/sda2 6293504 31459327 25165824 12G Linux filesystem
/dev/sda3 31459328 234441614 202982287 96.8G Linux filesystem
See? Units: sectors of 1 * 512 = 512 bytes…
Method 4
In my version of Ubuntu 14.04, fdisk lists the partition in blocks but it doesn’t tell me how many sectors are in each block. However, it does give the starting and ending sector number for each partition and when I subtract the starting point from the end point, I get exactly twice the number of sectors as there are blocks in the partition. I.e., there are two sectors in each block in Ubuntu 12.04.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0