storaged-project / blivet

A python module for configuration of block devices
GNU Lesser General Public License v2.1
106 stars 86 forks source link

Use disk parted.maxPartitionLength, out of maximum allocate sectors #1273

Closed Yurii-huang closed 2 months ago

Yurii-huang commented 2 months ago

disk label seted msdos

image

I use the maximum size of the disk partition as the number of sectors I can allocate:

            table_max_length = device.format.parted_disk.maxPartitionLength

I'm doing the alignment and sector conversion in the same way as in the add_partition function

            table_max_length = table_max_length * int(device.format.sector_size)
            # aligin to size
            grain_size = device.format.alignment.grainSize
            if table_max_length >= grain_size:
                aligned_length = table_max_length - (table_max_length % grain_size)
                table_max_length = aligned_length

My intention is not to let him show the error "requested size exceeds maximum allowed"

Does anyone know why this is, maxPartitionLength means end - start + 1?

Yurii-huang commented 2 months ago

Does anyone know why this is, maxPartitionLength means end - start + 1?

when I tried:

table_max_length = device.format.parted_disk.maxPartitionLength - 1

The result is still "requested size exceeds maximum allowed"

Yurii-huang commented 2 months ago

@vojtechtrefny Can you answer this question? thanks.

vojtechtrefny commented 2 months ago

From your screenshot the partition you are trying to create is actually too long:

geom = parted.Geometry(device=device, start=2048, end=4294969343)

geom.length
4294967296

which does exceed the maximum length of 4294967295.

When calculating the sizes in sectors don't forget that both the end and start sectors are part of the partition so a theoretical partition that starts on sector 1 and ends on sector 2 is 2 sectors long. So the length calculation length = end - start + 1 is correct.

when I tried: table_max_length = device.format.parted_disk.maxPartitionLength - 1 The result is still "requested size exceeds maximum allowed"

Do you know how the final geometry actually looks in this case? Is it possible this size is aligned up by the following code?

        if not end_alignment.isAligned(free, end):
            end = end_alignment.alignUp(free, end)
            log.debug("adjusted length from %d to %d", length, end - start + 1)
Yurii-huang commented 2 months ago

From your screenshot the partition you are trying to create is actually too long:

geom = parted.Geometry(device=device, start=2048, end=4294969343)

geom.length
4294967296

which does exceed the maximum length of 4294967295.

When calculating the sizes in sectors don't forget that both the end and start sectors are part of the partition so a theoretical partition that starts on sector 1 and ends on sector 2 is 2 sectors long. So the length calculation length = end - start + 1 is correct.

when I tried: table_max_length = device.format.parted_disk.maxPartitionLength - 1 The result is still "requested size exceeds maximum allowed"

Do you know how the final geometry actually looks in this case? Is it possible this size is aligned up by the following code?

        if not end_alignment.isAligned(free, end):
            end = end_alignment.alignUp(free, end)
            log.debug("adjusted length from %d to %d", length, end - start + 1)

Thanks for the reading, this problem has been solved.

sector alignment should be applied sector rather than byte size, this is an obvious rule, and my code does byte conversion first and then sector alignment, which is not right.

Sector alignment should precede the code logic for byte conversion.