Score:0

Why can fdisk create a 10GiB partition on a 10GiB device but not a 9.9GiB partition

in flag

I am currently learning about creating and managing devices on my Ubuntu Server 22.04 VM running on a KVM host. I added a virtual qcow2 storage disk to the VM. I used fdisk and for very specific purposes I need to create a 9.9GiB partition . I setup a DOS style partition table and then tried to create a primary partition.

Following are the steps to reproduce

root@hmxserver:/home/hmx# fdisk /dev/vdb

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): o
Created a new DOS disklabel with disk identifier 0xb4942d4d.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-20971519, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519): +9.9G
Value out of range.
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519): 

Created a new partition 1 of type 'Linux' and of size 10 GiB.

Questions That I want to ask?

  1. Why is a 10GiB partition possible but 9.9GiB is out of range ?
  2. I was able accomplish this on another VM with similar specs but on VirtualBox with a 10GiB VMDK disk attached and repeated the same steps. Why was fdisk successful there?
  3. Does it have to do with the qcow2 devices ?
  4. Or is it some sort of Floating Point Errors ?
Score:3
es flag

I did a little experimentation, and to me it looks like fdisk cannot deal with floating point numbers, so +9.9G cannot be parsed while +9G or +10G can. That means that the error message was wrong.

If all you want is to use all the rest of the disk, simply do not enter a value for the partition end, and use the proposed default instead.

Otherwise, you might have to resort to a smaller unit and enter something like +10137M (i.e. 9.9*1024; remember this is using 1024-based units!).

Alternatively, you could use parted or its GUI version gparted.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.