0

note: I am a Linux beginner, and trying to learn from the following book: How Linux Works

Running parted -l I get:

Model: KBG30ZMV256G TOSHIBA (nvme)
Disk /dev/nvme0n1: 256GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name                  Flags
 1      1049kB  538MB  537MB  fat32        EFI System Partition  boot, esp
 2      538MB   256GB  256GB  ext4       

While running fdisk-l I get:

Disk /dev/loop0: 137,9 MiB, 144527360 bytes, 282280 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop1: 612,3 MiB, 642023424 bytes, 1253952 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop2: 120,4 MiB, 126201856 bytes, 246488 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop4: 89,1 MiB, 93417472 bytes, 182456 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop5: 91,3 MiB, 95748096 bytes, 187008 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop6: 612,1 MiB, 641851392 bytes, 1253616 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop7: 171,6 MiB, 179875840 bytes, 351320 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/nvme0n1: 238,5 GiB, 256060514304 bytes, 500118192 sectors
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: BCB099F2-0FCD-4A90-83C2-A76C3E49682D

Device           Start       End   Sectors  Size Type
/dev/nvme0n1p1    2048   1050623   1048576  512M EFI System
/dev/nvme0n1p2 1050624 500117503 499066880  238G Linux filesystem


Disk /dev/loop8: 134,1 MiB, 140652544 bytes, 274712 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Another thing I noticed when running lsblk -a:

NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0         7:0    0 137,9M  1 loop /snap/code/24
loop1         7:1    0 612,3M  1 loop /snap/intellij-idea-community/202
loop2         7:2    0 120,4M  1 loop /snap/docker/423
loop3         7:3    0         1 loop 
loop4         7:4    0  89,1M  1 loop /snap/core/8268
loop5         7:5    0  91,3M  1 loop /snap/core/8592
loop6         7:6    0 612,1M  1 loop /snap/intellij-idea-community/208
loop7         7:7    0 171,6M  1 loop /snap/microk8s/1173
loop8         7:8    0 134,1M  1 loop /snap/code/25
nvme0n1     259:0    0 238,5G  0 disk 
├─nvme0n1p1 259:1    0   512M  0 part /boot/efi
└─nvme0n1p2 259:2    0   238G  0 part /

I have a basic understanding of the difference between creating partitions with fdisk vs. parted; however, I am curious about: Why do I get a different output (and partition sizes) between fdisk and parted?

my system information running uname -a:

Linux  5.3.0-28-generic #30~18.04.1-Ubuntu SMP Fri Jan 17 06:14:09 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
0

Outputs from parted and fdisk are somewhat different but not contradictory.

  • parted shows values expressed in units you see in its output (kB, MB, GB).

  • fdisk shows values expressed in physical sectors which in your case are of the size 512 bytes.

The latter values are strict. Their granularity is one sector. You do not need better granularity (e.g. in bytes) because partitions cannot start in the middle of the sector or contain fractional number of sectors. You can recalculate the values to bytes is you want.

Values expressed in units like kB or MB not only are rounded, but there is an ambiguity: see Is it true that 1 MB can mean either 1000000 bytes, 1024000 bytes, or 1048576 bytes? Because of this ambiguity the size of 256GB (from parted) and 238G (from fdisk) are both "right", only they use different units.

Take the strict size of /dev/nvme0n1p2, it's 499066880 sectors. Multiply by the sector size (512 bytes). The result is 255522242560. Divide by 109 and round the result. You get 256.

Now take 255522242560, divide by 10243 and round the result. You get 238.

| 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.