Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to size partitions correctly in Debian Bullseye #90

Open
marria05 opened this issue May 5, 2022 · 3 comments
Open

Unable to size partitions correctly in Debian Bullseye #90

marria05 opened this issue May 5, 2022 · 3 comments
Assignees

Comments

@marria05
Copy link

marria05 commented May 5, 2022

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
Copy link
Author

marria05 commented May 6, 2022

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
Copy link
Author

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

@dcantrell dcantrell self-assigned this May 13, 2022
@dcantrell
Copy link
Owner

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants