Repository: archlinux/archinstall

Issue:
Presence of ROM device raises `_ped.DiskException`
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.

https://github.com/archlinux/archinstall/blob/5276d95339368210e75791e2b88c1bf5aca4517b/archinstall/lib/disk/device_handler.py#L47-L52

### 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 https://github.com/codefiles/archinstall/commit/08b963f563387d0e1c4341109a13e85449190022 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

  ```python
  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
  ```


Discussion:

Resolving patch:
diff --git a/archinstall/lib/disk/device_handler.py b/archinstall/lib/disk/device_handler.py
--- a/archinstall/lib/disk/device_handler.py
+++ b/archinstall/lib/disk/device_handler.py
@@ -45,6 +45,9 @@ def load_devices(self):
 		block_devices = {}
 
 		for device in getAllDevices():
+			if get_lsblk_info(device.path).type == 'rom':
+				continue
+
 			try:
 				disk = Disk(device)
 			except DiskLabelException as err:


Test patch: