How to specify size in MiB in curtin?

Asked by Steve Rainwater

Curtin documentation for lvm_partition specifies that "The size can be entered in any format that can be processed by the lvm2 tools". However, this does not appear to be the case. The following use results in "113MiB is not valid input":

 - { type: lvm_partition, id: lvm_partition_drbdpad1, name: drbdpad1, volgroup: vg1 , size: 113MiB }

Curtin does allow me to specify the size in SI Units as 113MB, which lvm also accepts, however, I need precise values to get my drbd meta-data exactly the correct size and 113Mib is more like 118MB. Does curtin only allow SI units vs normal power-of-2 units, meaning I need to convert all my partition sizes from MiB to MB before writing the curtin lvm_partition sections or is there some other way to tell curtin I want to use MiB?

I'm using Ubuntu 20.04.2 LTS with curtin 19.3-27-g437caaa9-0ubuntu1 and LVM version 2.03.07(2) (2019-11-30)

The Ubuntu /etc/lvm/lvm.conf file defaults to si_unit_consistency = 1

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu curtin Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Bernard Stafford (bernard010) said (last edit ):
#1

MiB to MB Convertor
https://www.gbmb.org/mib-to-mb

lvm2 tools, so a number followed by a SI unit should work, i.e. B, kB, MB, GB, TB.
Mib is not listed in doc.
Curtin does not adjust size values. If you specific a size that exceeds the capacity of a device then installation will fail.

119 MB Round up to the nearest whole number.
https://curtin.readthedocs.io/en/latest/topics/storage.html?highlight=lvm%20partition#lvm-partition-command

Revision history for this message
Steve Rainwater (steevithak) said :
#2

I'm aware of how to convert between MiB and MB, my question is whether the Curtin documentation is correct or not. It says I should be able to provide lvm_parition sizes in MiB since the MiB or m size units are "accepted by lvm2" but I get an error when using them.

It appears that Curtin will only accept SI units for lvm_partition sizes (e.g. MB/M and not MiB/m) rather than "any format accepted by lvm2". If this is the intended behavior then the documentation should be corrected to say that ONLY SI units are accepted and NOT ANY units supported by lvm2.

Revision history for this message
Steve Rainwater (steevithak) said :
#3

I tried a simple test to see how the SI units were handled and gave curtin this lvm_parition size:

- { type: lvm_partition, id: lvm_partition_drbdpad1, name: drbdpad1, volgroup: vg1 , size: 8MB }

8MB in SI units is 8000000 bytes (vs 8MiB which is 8388608 bytes).

The resulting partition that was created by curtin/lvm turns out to be 8388608 bytes, which is incorrect if curtin is using SI values. Based on the debug logs curtin executed this command:

lvcreate vg0 --name drbdpad0 --zero=y --wipesignatures=y --size 8388608.0B

So it "converted" 8MB to 8MiB, meaning it's not using SI units, despite the documentation. My guess is that it's just old code that uses MB when it really means MiB. After browsing the Python code I found the conversion used in util.py fuction human2bytes(). It's clear that it's using powers of 2 to convert 8 into 8388608 (so MiB) instead of into 8000000 (MB). But I also see I can avoid Curtin's confusing conversions/unit labels by specifying all my sizes in Bytes. So if I specify 8388608B, that's exactly what I get, just as if I specified it as 8MiB. For now that seems like the safest way to go.

Can you help with this problem?

Provide an answer of your own, or ask Steve Rainwater for more information if necessary.

To post a message you must log in.