1
0
Fork
You've already forked pyparted
1

Unable to size partitions correctly in Debian Bullseye #90

Open
opened 2022年05月05日 23:02:06 +02:00 by marria05 · 3 comments
marria05 commented 2022年05月05日 23:02:06 +02:00 (Migrated from github.com)
Copy link

I've been asked to update an install script that I had written a couple of years to check that it still works correctly under the new(ish) version of Debian. On running it on a test machine, it appears the partition sizing no longer seems to work for me.

Using the demo file make_one_primary_partition.py (found in the examples directory), I can create a single partition that uses the entire disk.

INFO - wiping partitions and other meta-data
DEBUG - has partitions ['/dev/sda1']
DEBUG - wiping /dev/sda1
DEBUG - wiping /dev/sda
INFO - creating primary partition
DEBUG - created parted.Device instance --
 model: ATA SanDisk SDSSDX12 path: /dev/sda type: 1
 sectorSize: 512 physicalSectorSize: 512
 length: 234441648 openCount: 0 readOnly: False
 externalMode: False dirty: False bootDirty: False
 host: 2 did: 0 busy: False
 hardwareGeometry: (459689, 255, 2) biosGeometry: (459689, 255, 2)
 PedDevice: <_ped.Device object at 0xb759d868>
DEBUG - created parted.Disk instance --
 type: msdos primaryPartitionCount: 0
 lastPartitionNumber: -1 maxPrimaryPartitionCount: 4
 partitions: []
 device: <parted.device.Device object at 0xb7596ad8>
 PedDisk: <_ped.Disk object at 0xb759e308>
DEBUG - created parted.Geometry instance --
 start: 1 end: 234441647 length: 234441647
 device: <parted.device.Device object at 0xb75969d0> PedGeometry: <_ped.Geometry object at 0xb7596b38>
DEBUG - created parted.FileSystem instance --
 type: ext3 geometry: <parted.geometry.Geometry object at 0xb7596aa8> checked: False
 PedFileSystem: <_ped.FileSystem object at 0xb759e428>
DEBUG - created parted.Partition instance --
 disk: <parted.disk.Disk object at 0xb7596a60> fileSystem: <parted.filesystem.FileSystem object at 0xb7596a30>
 number: -1 path: /dev/sda-1 type: 0
 name: None active: True busy: False
 geometry: <parted.geometry.Geometry object at 0xb7596aa8> PedPartition: <_ped.Partition object at 0xb75a7910>
bncs@gpi-box:/opt$ sudo fdisk /dev/sda
sudo: unable to resolve host gpi-box.national.bbc.co.uk: Name or service not known
Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 111.79 GiB, 120034123776 bytes, 234441648 sectors
Disk model: SanDisk SDSSDX12
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: dos
Disk identifier: 0xb06a60c1
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 522240 233963519 233441280 111.3G 83 Linux

However, note the start and end positions for the partition don't seem to tally from the pyparted debug code and what fdisk is showing.

If I modify the example to specify a specific size for the partition:

--- make_one_primary_partition.py 2022年05月05日 21:41:12.629505506 +0100
+++ make_one_primary_partition_modified.py 2022年05月05日 21:30:31.637821303 +0100
@@ -76,7 +76,7 @@
 disk = parted.freshDisk(device, 'msdos')
 self.logger.debug('created %s', disk)
 geometry = parted.Geometry(device=device, start=1,
- length=device.getLength() - 1)
+ length=parted.sizeToSectors(32, 'MB', device.sectorSize))
 self.logger.debug('created %s', geometry)
 filesystem = parted.FileSystem(type='ext3', geometry=geometry)
 self.logger.debug('created %s', filesystem)

I get the following:

INFO - wiping partitions and other meta-data
DEBUG - has partitions ['/dev/sda1']
DEBUG - wiping /dev/sda1
DEBUG - wiping /dev/sda
INFO - creating primary partition
DEBUG - created parted.Device instance --
 model: ATA SanDisk SDSSDX12 path: /dev/sda type: 1
 sectorSize: 512 physicalSectorSize: 512
 length: 234441648 openCount: 0 readOnly: False
 externalMode: False dirty: False bootDirty: False
 host: 2 did: 0 busy: False
 hardwareGeometry: (459689, 255, 2) biosGeometry: (459689, 255, 2)
 PedDevice: <_ped.Device object at 0xb7619810>
DEBUG - created parted.Disk instance --
 type: msdos primaryPartitionCount: 0
 lastPartitionNumber: -1 maxPrimaryPartitionCount: 4
 partitions: []
 device: <parted.device.Device object at 0xb7614b20>
 PedDisk: <_ped.Disk object at 0xb761a348>
DEBUG - created parted.Geometry instance --
 start: 1 end: 62500 length: 62500
 device: <parted.device.Device object at 0xb7614a18> PedGeometry: <_ped.Geometry object at 0xb7614b80>
DEBUG - created parted.FileSystem instance --
 type: ext3 geometry: <parted.geometry.Geometry object at 0xb7614af0> checked: False
 PedFileSystem: <_ped.FileSystem object at 0xb761a408>
DEBUG - created parted.Partition instance --
 disk: <parted.disk.Disk object at 0xb7614aa8> fileSystem: <parted.filesystem.FileSystem object at 0xb7614a78>
 number: -1 path: /dev/sda-1 type: 0
 name: None active: True busy: False
 geometry: <parted.geometry.Geometry object at 0xb7614af0> PedPartition: <_ped.Partition object at 0xb7624780>
bncs@gpi-box:/opt$ sudo fdisk /dev/sda
sudo: unable to resolve host gpi-box.national.bbc.co.uk: Name or service not known
Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 111.79 GiB, 120034123776 bytes, 234441648 sectors
Disk model: SanDisk SDSSDX12
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: dos
Disk identifier: 0x24fd1996
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 522240 1044479 522240 255M 83 Linux

Am I doing something wrong? I had initially thought it might be the drive. But a test VM behaves in exactly the same manner. I don't have a Debian Buster machine to hand right now to confirm, otherwise I would try running it on that as well.

I was using the version of pyparted that came with install of Debian which appears to be 3.11.7. I have, however tried upgrading to what appears to be the latest (3.20.0), but that doesn't seem to have made any difference.

I've been asked to update an install script that I had written a couple of years to check that it still works correctly under the new(ish) version of Debian. On running it on a test machine, it appears the partition sizing no longer seems to work for me. Using the demo file `make_one_primary_partition.py` (found in the examples directory), I can create a single partition that uses the entire disk. ``` INFO - wiping partitions and other meta-data DEBUG - has partitions ['/dev/sda1'] DEBUG - wiping /dev/sda1 DEBUG - wiping /dev/sda INFO - creating primary partition DEBUG - created parted.Device instance -- model: ATA SanDisk SDSSDX12 path: /dev/sda type: 1 sectorSize: 512 physicalSectorSize: 512 length: 234441648 openCount: 0 readOnly: False externalMode: False dirty: False bootDirty: False host: 2 did: 0 busy: False hardwareGeometry: (459689, 255, 2) biosGeometry: (459689, 255, 2) PedDevice: <_ped.Device object at 0xb759d868> DEBUG - created parted.Disk instance -- type: msdos primaryPartitionCount: 0 lastPartitionNumber: -1 maxPrimaryPartitionCount: 4 partitions: [] device: <parted.device.Device object at 0xb7596ad8> PedDisk: <_ped.Disk object at 0xb759e308> DEBUG - created parted.Geometry instance -- start: 1 end: 234441647 length: 234441647 device: <parted.device.Device object at 0xb75969d0> PedGeometry: <_ped.Geometry object at 0xb7596b38> DEBUG - created parted.FileSystem instance -- type: ext3 geometry: <parted.geometry.Geometry object at 0xb7596aa8> checked: False PedFileSystem: <_ped.FileSystem object at 0xb759e428> DEBUG - created parted.Partition instance -- disk: <parted.disk.Disk object at 0xb7596a60> fileSystem: <parted.filesystem.FileSystem object at 0xb7596a30> number: -1 path: /dev/sda-1 type: 0 name: None active: True busy: False geometry: <parted.geometry.Geometry object at 0xb7596aa8> PedPartition: <_ped.Partition object at 0xb75a7910> bncs@gpi-box:/opt$ sudo fdisk /dev/sda sudo: unable to resolve host gpi-box.national.bbc.co.uk: Name or service not known Welcome to fdisk (util-linux 2.36.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sda: 111.79 GiB, 120034123776 bytes, 234441648 sectors Disk model: SanDisk SDSSDX12 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: dos Disk identifier: 0xb06a60c1 Device Boot Start End Sectors Size Id Type /dev/sda1 * 522240 233963519 233441280 111.3G 83 Linux ``` However, note the start and end positions for the partition don't seem to tally from the pyparted debug code and what `fdisk` is showing. If I modify the example to specify a specific size for the partition: ``` --- make_one_primary_partition.py 2022年05月05日 21:41:12.629505506 +0100 +++ make_one_primary_partition_modified.py 2022年05月05日 21:30:31.637821303 +0100 @@ -76,7 +76,7 @@ disk = parted.freshDisk(device, 'msdos') self.logger.debug('created %s', disk) geometry = parted.Geometry(device=device, start=1, - length=device.getLength() - 1) + length=parted.sizeToSectors(32, 'MB', device.sectorSize)) self.logger.debug('created %s', geometry) filesystem = parted.FileSystem(type='ext3', geometry=geometry) self.logger.debug('created %s', filesystem) ``` I get the following: ``` INFO - wiping partitions and other meta-data DEBUG - has partitions ['/dev/sda1'] DEBUG - wiping /dev/sda1 DEBUG - wiping /dev/sda INFO - creating primary partition DEBUG - created parted.Device instance -- model: ATA SanDisk SDSSDX12 path: /dev/sda type: 1 sectorSize: 512 physicalSectorSize: 512 length: 234441648 openCount: 0 readOnly: False externalMode: False dirty: False bootDirty: False host: 2 did: 0 busy: False hardwareGeometry: (459689, 255, 2) biosGeometry: (459689, 255, 2) PedDevice: <_ped.Device object at 0xb7619810> DEBUG - created parted.Disk instance -- type: msdos primaryPartitionCount: 0 lastPartitionNumber: -1 maxPrimaryPartitionCount: 4 partitions: [] device: <parted.device.Device object at 0xb7614b20> PedDisk: <_ped.Disk object at 0xb761a348> DEBUG - created parted.Geometry instance -- start: 1 end: 62500 length: 62500 device: <parted.device.Device object at 0xb7614a18> PedGeometry: <_ped.Geometry object at 0xb7614b80> DEBUG - created parted.FileSystem instance -- type: ext3 geometry: <parted.geometry.Geometry object at 0xb7614af0> checked: False PedFileSystem: <_ped.FileSystem object at 0xb761a408> DEBUG - created parted.Partition instance -- disk: <parted.disk.Disk object at 0xb7614aa8> fileSystem: <parted.filesystem.FileSystem object at 0xb7614a78> number: -1 path: /dev/sda-1 type: 0 name: None active: True busy: False geometry: <parted.geometry.Geometry object at 0xb7614af0> PedPartition: <_ped.Partition object at 0xb7624780> bncs@gpi-box:/opt$ sudo fdisk /dev/sda sudo: unable to resolve host gpi-box.national.bbc.co.uk: Name or service not known Welcome to fdisk (util-linux 2.36.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sda: 111.79 GiB, 120034123776 bytes, 234441648 sectors Disk model: SanDisk SDSSDX12 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: dos Disk identifier: 0x24fd1996 Device Boot Start End Sectors Size Id Type /dev/sda1 * 522240 1044479 522240 255M 83 Linux ``` Am I doing something wrong? I had initially thought it might be the drive. But a test VM behaves in exactly the same manner. I don't have a Debian Buster machine to hand right now to confirm, otherwise I would try running it on that as well. I was using the version of pyparted that came with install of Debian which appears to be `3.11.7`. I have, however tried upgrading to what appears to be the latest (`3.20.0`), but that doesn't seem to have made any difference.
marria05 commented 2022年05月06日 23:38:16 +02:00 (Migrated from github.com)
Copy link

Just as an update. The same script, when run on a Debian Buster machine works as expected. The version of pyparted on this system is 3.11.2.

Just as an update. The same script, when run on a Debian Buster machine works as expected. The version of pyparted on this system is `3.11.2`.
marria05 commented 2022年05月10日 19:26:13 +02:00 (Migrated from github.com)
Copy link

Another update. I'm able recreate this in a vanilla Debian Bullseye VM using the Debian supplied python3-parted package.

Another update. I'm able recreate this in a vanilla Debian Bullseye VM using the Debian supplied `python3-parted` package.
dcantrell commented 2022年05月13日 17:11:25 +02:00 (Migrated from github.com)
Copy link

Just wanted to comment here and note that I will not be able to look in to this issue for a week or so. But thank you for the detailed report here. Please continue to post here if you have more details. If you are working on a fix, PRs are welcome too.

Just wanted to comment here and note that I will not be able to look in to this issue for a week or so. But thank you for the detailed report here. Please continue to post here if you have more details. If you are working on a fix, PRs are welcome too.
Sign in to join this conversation.
No Branch/Tag specified
main
stable-3.9.x
master-distutils
master-staging
test-cases
v3.13.0
v3.12.0
v3.11.7
v3.11.6
v3.11.5
v3.11.4
v3.11.3
v3.11.2
v3.11.1
v3.11.0
v3.10.7
v3.10.6
v3.10.5
pyparted-3.10.4
pyparted-3.10.3
pyparted-3.10.2
pyparted-3.10.1
pyparted-3.10.0
pyparted-3.9.5
pyparted-3.9.4
pyparted-3.9.3
pyparted-3.9.2
pyparted-3.10
pyparted-3.10a1
v3.10a1
v3.10a0
hayseed
pyparted-3.9
pyparted-3.8
pyparted-3.7
pyparted-3.6
pyparted-3.5
pyparted-3.4
pyparted-3.3
pyparted-3.2
pyparted-3.1
pyparted-3.0
pyparted-2.5
pyparted-2.4
pyparted-2.3
pyparted-2.2
pyparted-2.1.2
pyparted-2.1.1
pyparted-2.1.0
pyparted-2.0.12
pyparted-2.0.11
pyparted-2.0.10
pyparted-2.0.9
pyparted-2.0.8
pyparted-2.0.7
pyparted-2.0.6
pyparted-2.0.5
pyparted-2.0.4
pyparted-2.0.3
pyparted-2.0.2
pyparted-2.0.1
pyparted-2.0.0
pyparted-1_8_9-1
start
pyparted-1.8.8-1
pyparted-1.8.7-1
pyparted-1.8.6-2
pyparted-1.8.6-1
pyparted-1.8.5-1
pyparted-1.8.4-1
pyparted-1.8.3-1
pyparted-1.8.2-1
pyparted-1.8.1-1
pyparted-1.8.0-1
pyparted-1.7.3-1
pyparted-1.6.9-1
pyparted-1.6.7-1
pyparted-1.6.6-2
pyparted-1.6.6-1
pyparted-1.6.10-1
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dcantrell/pyparted#90
Reference in a new issue
dcantrell/pyparted
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?