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

Presence of ROM device raises _ped.DiskException #1833

Closed
codefiles opened this issue May 23, 2023 · 7 comments · Fixed by #1906
Closed

Presence of ROM device raises _ped.DiskException #1833

codefiles opened this issue May 23, 2023 · 7 comments · Fixed by #1906

Comments

@codefiles
Copy link
Contributor

codefiles commented May 23, 2023

The list of devices returned by parted.getAllDevices() is iterated over and each device is passed to parted.Disk(). If that raises an 'unrecognised disk label' DiskLabelException then the device is passed to parted.freshDisk(). ROM devices are inlcuded in the list of devices returned by parted.getAllDevices() and will cause both of these to raise an exception.

for device in getAllDevices():
try:
disk = Disk(device)
except DiskLabelException as err:
if 'unrecognised disk label' in getattr(error, 'message', str(err)):
disk = freshDisk(device, PartitionTable.GPT.value)

Proposed fix

Do not initialize parted.Disk or parted.freshDisk with ROM devices. Use get_lsblk_info() to get the type of a device and skip the device if the type is 'rom'. See the commit codefiles@08b963f for an implementation of this fix.

Traceback

Traceback (most recent call last):
  File "/home/scripttest/archinstall/archinstall/lib/disk/device_handler.py", line 49, in load_devices
    disk = Disk(device)
           ^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/parted/decorators.py", line 42, in new
    ret = fn(*args, **kwds)
          ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/parted/disk.py", line 52, in __init__
    self.__disk = _ped.Disk(device.getPedDevice())
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ped.DiskLabelException: /dev/sr0: unrecognised disk label

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/scripttest/archinstall/.venv/bin/archinstall", line 5, in <module>
    from archinstall import run_as_a_module
  File "/home/scripttest/archinstall/archinstall/__init__.py", line 8, in <module>
    from .lib import disk
  File "/home/scripttest/archinstall/archinstall/lib/disk/__init__.py", line 1, in <module>
    from .device_handler import device_handler, disk_layouts
  File "/home/scripttest/archinstall/archinstall/lib/disk/device_handler.py", line 603, in <module>
    device_handler = DeviceHandler()
                     ^^^^^^^^^^^^^^^
  File "/home/scripttest/archinstall/archinstall/lib/disk/device_handler.py", line 38, in __init__
    self.load_devices()
  File "/home/scripttest/archinstall/archinstall/lib/disk/device_handler.py", line 52, in load_devices
    disk = freshDisk(device, PartitionTable.GPT.value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/parted/decorators.py", line 42, in new
    ret = fn(*args, **kwds)
          ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/parted/__init__.py", line 546, in freshDisk
    peddisk = disk_new_fresh(device.getPedDevice(), ty)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ped.DiskException: device is too small for GPT

Device information

  • lsblk -o NAME,PATH,TYPE /dev/sr0

    NAME PATH     TYPE
    sr0  /dev/sr0 rom
    
  • pyparted

    import parted
    
    device = parted.getDevice('/dev/sr0')
    print(device)
    print(parted.devices[device.type])

    Output

    parted.Device instance --
      model: QEMU QEMU DVD-ROM  path: /dev/sr0  type: 1
      sectorSize: 2048  physicalSectorSize:  2048
      length: 1  openCount: 0  readOnly: False
      externalMode: False  dirty: False  bootDirty: False
      host: 1  did: 0  busy: False
      hardwareGeometry: (0, 255, 5)  biosGeometry: (0, 255, 5)
      PedDevice: <_ped.Device object at 0x7f7652da5040>
    scsi
    
@codefiles
Copy link
Contributor Author

If my proposed fix is agreed upon I will submit a pull request.

@svartkanin
Copy link
Collaborator

I'll have to have a look at this a bit more

@codefiles
Copy link
Contributor Author

@Torxed, this should be addressed before a release is made.

@Torxed
Copy link
Member

Torxed commented Jun 28, 2023

I agree. I personally think it's a small and clean implementation.
Any suggestions @svartkanin? three lines of code could be easy to change later on if we decide to go another route?

@svartkanin
Copy link
Collaborator

@Torxed @codefiles yes absolutely go ahead with the patch

@codefiles
Copy link
Contributor Author

Relevant pyparted issue: dcantrell/pyparted#102

@Torxed
Copy link
Member

Torxed commented Jun 29, 2023

Will be interesting to see pyparted's response.
But for us your method will do more than fine for this release:

if get_lsblk_info(device.path).type == 'rom':
	continue

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

Successfully merging a pull request may close this issue.

3 participants