Venom1991 / refind-btrfs

Generate rEFInd manual boot stanzas from Btrfs snapshots
GNU General Public License v3.0
149 stars 9 forks source link

Fails on lsblk returning too many items for iterable #1

Closed virtualguy closed 3 years ago

virtualguy commented 3 years ago

Let me know how I can help with more debugging info but here is the error stack trace:

[root@me /]# refind-btrfs 
Initializing the block devices using lsblk.
Initializing the physical partition table for device '/dev/sda' using lsblk.
ERROR (refind_btrfs/__init__.py/main): An unexpected error happened, exiting...
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/refind_btrfs/__init__.py", line 77, in main
    exit_code = runner.run()
  File "/usr/lib/python3.9/site-packages/refind_btrfs/console/cli_runner.py", line 48, in run
    if not machine.run():
  File "/usr/lib/python3.9/site-packages/refind_btrfs/state_management/refind_btrfs_machine.py", line 74, in run
    while model.next_state():
  File "/usr/lib/python3.9/site-packages/transitions/core.py", line 393, in trigger
    return self.machine._process(func)
  File "/usr/lib/python3.9/site-packages/transitions/core.py", line 1148, in _process
    return trigger()
  File "/usr/lib/python3.9/site-packages/transitions/core.py", line 411, in _trigger
    return self._process(event_data)
  File "/usr/lib/python3.9/site-packages/transitions/core.py", line 420, in _process
    if trans.execute(event_data):
  File "/usr/lib/python3.9/site-packages/transitions/core.py", line 272, in execute
    self._change_state(event_data)
  File "/usr/lib/python3.9/site-packages/transitions/core.py", line 282, in _change_state
    event_data.machine.get_state(self.dest).enter(event_data)
  File "/usr/lib/python3.9/site-packages/refind_btrfs/state_management/states.py", line 53, in enter
    all_block_devices = list(self._get_all_block_devices())
  File "/usr/lib/python3.9/site-packages/refind_btrfs/state_management/states.py", line 64, in _get_all_block_devices
    physical_partition_table = physical_device_command.get_partition_table_for(
  File "/usr/lib/python3.9/functools.py", line 914, in _method
    return method.__get__(obj, cls)(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/refind_btrfs/common/abc/commands/device_command.py", line 52, in _
    return self._block_device_partition_table(argument)
  File "/usr/lib/python3.9/site-packages/refind_btrfs/system/lsblk_command.py", line 148, in _block_device_partition_table
    lsblk_blockdevice = one(lsblk_parsed_output[LsblkJsonKey.BLOCKDEVICES.value])
  File "/usr/lib/python3.9/site-packages/more_itertools/more.py", line 571, in one
    raise too_long or ValueError(msg)
ValueError: Expected exactly one item in iterable, but got {'ptuuid': '4e567c56-3704-42cc-ad32-544b465c6e4d', 'pttype': 'gpt', 'partuuid': None, 'parttype': None, 'partlabel': None, 'uuid': None, 'name': '/dev/sda', 'fstype': None, 'label': None, 'mountpoint': None, 'children': [{'ptuuid': '4e567c56-3704-42cc-ad32-544b465c6e4d', 'pttype': 'gpt', 'partuuid': '1819d7f9-6774-4216-8413-6f4eaca8ef38', 'parttype': 'de94bba4-06d1-4d40-a16a-bfd50179d6ac', 'partlabel': 'Basic data partition', 'uuid': '86068167068158D7', 'name': '/dev/sda1', 'fstype': 'ntfs', 'label': None, 'mountpoint': None}, {'ptuuid': '4e567c56-3704-42cc-ad32-544b465c6e4d', 'pttype': 'gpt', 'partuuid': '1e4c0121-7dd2-4322-ad96-33903ddce419', 'parttype': 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b', 'partlabel': 'EFI system partition', 'uuid': '7639-E5E1', 'name': '/dev/sda2', 'fstype': 'vfat', 'label': None, 'mountpoint': '/boot/efi'}, {'ptuuid': '4e567c56-3704-42cc-ad32-544b465c6e4d', 'pttype': 'gpt', 'partuuid': 'da04db12-69a3-4a10-af03-7e7190ebda00', 'parttype': 'e3c9e316-0b5c-4db8-817d-f92df00215ae', 'partlabel': 'Microsoft reserved partition', 'uuid': None, 'name': '/dev/sda3', 'fstype': None, 'label': None, 'mountpoint': None}, {'ptuuid': '4e567c56-3704-42cc-ad32-544b465c6e4d', 'pttype': 'gpt', 'partuuid': '79825130-3414-4bfe-b3e5-ab81c80babd0', 'parttype': '0fc63daf-8483-4772-8e79-3d69d8477de4', 'partlabel': 'arch', 'uuid': '974dd259-8691-4433-988e-866818e47038', 'name': '/dev/sda4', 'fstype': 'ext4', 'label': None, 'mountpoint': '/etc/resolv.conf'}, {'ptuuid': '4e567c56-3704-42cc-ad32-544b465c6e4d', 'pttype': 'gpt', 'partuuid': '8a98c5fe-dd80-4c0d-9a7e-cd5ee63d3697', 'parttype': '0657fd6d-a4ab-43c4-84e5-0933c84b4f4f', 'partlabel': None, 'uuid': '62886081-efcd-4642-ac38-c8db548fb4cc', 'name': '/dev/sda5', 'fstype': 'swap', 'label': None, 'mountpoint': '[SWAP]'}, {'ptuuid': '4e567c56-3704-42cc-ad32-544b465c6e4d', 'pttype': 'gpt', 'partuuid': 'afb1fc62-4c9a-4220-b27b-ebd83c1e70cf', 'parttype': '0fc63daf-8483-4772-8e79-3d69d8477de4', 'partlabel': 'ubuntu', 'uuid': 'b3e627cd-14fe-41f2-87f3-0f164f39341c', 'name': '/dev/sda6', 'fstype': 'ext4', 'label': None, 'mountpoint': None}, {'ptuuid': '4e567c56-3704-42cc-ad32-544b465c6e4d', 'pttype': 'gpt', 'partuuid': 'a1d53bf9-f328-4b33-b301-6eea79449618', 'parttype': '0fc63daf-8483-4772-8e79-3d69d8477de4', 'partlabel': 'home', 'uuid': '10b795d8-81c4-4c08-a71d-7d135736d474', 'name': '/dev/sda7', 'fstype': 'ext4', 'label': None, 'mountpoint': None}]}, {'ptuuid': 'e2353b37', 'pttype': 'dos', 'partuuid': None, 'parttype': None, 'partlabel': None, 'uuid': None, 'name': '/dev/sdb', 'fstype': None, 'label': None, 'mountpoint': None, 'children': [{'ptuuid': 'e2353b37', 'pttype': 'dos', 'partuuid': 'e2353b37-01', 'parttype': '0x7', 'partlabel': None, 'uuid': '4C16ACBA16ACA684', 'name': '/dev/sdb1', 'fstype': 'ntfs', 'label': 'System Reserved', 'mountpoint': None}, {'ptuuid': 'e2353b37', 'pttype': 'dos', 'partuuid': 'e2353b37-02', 'parttype': '0x7', 'partlabel': None, 'uuid': '3EC87417C873CC21', 'name': '/dev/sdb2', 'fstype': 'ntfs', 'label': None, 'mountpoint': None}, {'ptuuid': 'e2353b37', 'pttype': 'dos', 'partuuid': 'e2353b37-03', 'parttype': '0x27', 'partlabel': None, 'uuid': '82B0AF33B0AF2C9B', 'name': '/dev/sdb3', 'fstype': 'ntfs', 'label': 'Recovery', 'mountpoint': None}, {'ptuuid': '4a59c2aa', 'pttype': 'dos', 'partuuid': 'e2353b37-04', 'parttype': '0x5', 'partlabel': None, 'uuid': None, 'name': '/dev/sdb4', 'fstype': None, 'label': None, 'mountpoint': None}, {'ptuuid': 'e2353b37', 'pttype': 'dos', 'partuuid': 'e2353b37-05', 'parttype': '0xef', 'partlabel': None, 'uuid': '1E33-A934', 'name': '/dev/sdb5', 'fstype': 'vfat', 'label': None, 'mountpoint': None}, {'ptuuid': 'e2353b37', 'pttype': 'dos', 'partuuid': 'e2353b37-06', 'parttype': '0x83', 'partlabel': None, 'uuid': 'f8d6597b-b5fa-44a8-84f1-f05226935ee1', 'name': '/dev/sdb6', 'fstype': 'ext4', 'label': None, 'mountpoint': None}, {'ptuuid': 'e2353b37', 'pttype': 'dos', 'partuuid': 'e2353b37-07', 'parttype': '0x83', 'partlabel': None, 'uuid': 'e2700231-4f2a-4467-bf8e-49a88acf2ba9', 'name': '/dev/sdb7', 'fstype': 'ext4', 'label': None, 'mountpoint': None}]}, and perhaps more.

lsblk output:

[root@me /]# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 465.8G  0 disk 
├─sda1        8:1    0   450M  0 part 
├─sda2        8:2    0    99M  0 part /boot/efi
├─sda3        8:3    0    16M  0 part 
├─sda4        8:4    0    80G  0 part /etc/resolv.conf
├─sda5        8:5    0    16G  0 part [SWAP]
├─sda6        8:6    0    80G  0 part 
└─sda7        8:7    0 289.2G  0 part 
sdb           8:16   0 465.8G  0 disk 
├─sdb1        8:17   0   499M  0 part 
├─sdb2        8:18   0 263.6G  0 part 
├─sdb3        8:19   0   4.7G  0 part 
├─sdb4        8:20   0     1K  0 part 
├─sdb5        8:21   0   513M  0 part 
├─sdb6        8:22   0    93G  0 part 
└─sdb7        8:23   0  74.9G  0 part 
sr0          11:0    1  1024M  0 rom  
nvme0n1     259:0    0 931.5G  0 disk 
├─nvme0n1p1 259:1    0   300M  0 part 
└─nvme0n1p2 259:2    0 931.2G  0 part /
Venom1991 commented 3 years ago

Thank you for opening an issue! So this is, I believe, an issue with two devices (sda and sdb) having the same major number which I use to fetch the physical partition table along with its partitions, filesystems and such. This is caused by a misunderstanding on my part of what the major device number actually represents. It is unfortunately not unique and my guess is HDDs are marked with 8 and, for instance, NVMe SSDs are marked with 259 (same on my machine).

What would help me greatly is posting the output of:

lsblk --paths --tree --include 8 --output ptuuid,pttype,partuuid,parttype,partlabel,uuid,name,fstype,label,mountpoint

and (with the "--json" option):

lsblk --json --paths --tree --include 8 --output ptuuid,pttype,partuuid,parttype,partlabel,uuid,name,fstype,label,mountpoint

With this I'll try to somehow mock lsblk's output for your specific case and try to figure out a solution.

EDIT: Additionally, what would also be helpful is the output of:

lsblk --nodeps --merge --paths --output name,type,maj:min

and also with the "--json" option included (same as before).

Thank you in advance.

Venom1991 commented 3 years ago

I've pushed a potential fix which I hope will work and updated the PKGBUILD so you can try upgrading the package and running the script again.

virtualguy commented 3 years ago

Epic! i'll give it go next week :) :crossed_fingers:

Venom1991 commented 3 years ago

Did you perhaps find the time to try again so that I can close this issue? There was a similar issue opened (and closed) recently concerning mostly the same parts of the program.

virtualguy commented 3 years ago

Sorry I haven't tested it yet. Will try soon :)

On Sun, 24 Jan 2021, 10:38 am Luka, notifications@github.com wrote:

Did you perhaps find the time to try again so that I can close this issue? There was a similar issue opened (and closed) recently concerning mostly the same parts of the program.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Venom1991/refind-btrfs/issues/1#issuecomment-766183530, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKT6KI5ILTM3YAE7TZ6PYTS3M6WTANCNFSM4WBUDAVQ .

Venom1991 commented 3 years ago

I'm gonna close this issue soon because its been two weeks without any activity. :sleeping:

Venom1991 commented 3 years ago

Closing due to inactivity.