Skip to content

Conversation

@tlaurion
Copy link
Collaborator

@tlaurion tlaurion commented Dec 8, 2025

fdisk -l can deal with 2TB max size drives. Use linux sysfs instead.

Tested:

  • qemu oem-factory reset with a canokey and public key exported to virt thumb drive's exclusive ext4 public partition
  • qemu oem-facctory-reset with canokey and in-ram key generation and key to card, creating luks+exfat partition on virt thumb drive
  • qemu-img 8tb qcow2 root attached: system information shows 8tb
  • test on v540tu

Fixes #2034 (should have been the fix for #1884)

Copilot AI review requested due to automatic review settings December 8, 2025 18:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces fdisk -l commands with sysfs-based disk enumeration to overcome fdisk's 2TB drive size limitation and improve busybox compatibility. The changes enable proper detection and display of large storage devices (e.g., 8TB drives).

Key changes:

  • Introduces list_block_devices() function that reads from /sys/block/* instead of parsing fdisk -l output
  • Replaces fdisk-based disk information gathering with sysfs-based size calculation
  • Updates partition detection logic to use sysfs directory structure

Reviewed changes

Copilot reviewed 2 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
initrd/etc/gui_functions Adds list_block_devices() function and updates show_system_info() to read disk sizes from sysfs
initrd/etc/functions Adds list_block_devices() function, updates device_has_partitions() to check sysfs for partitions, updates is_gpt_bios_grub() to read partition types from sysfs, and updates detect_boot_device() to use new function
initrd/bin/root-hashes-gui.sh Updates detect_root_device() to use list_block_devices() instead of fdisk
initrd/bin/oem-system-info-xx30 Updates disk information gathering to read from sysfs instead of fdisk
initrd/bin/config-gui.sh Updates device listing to use list_block_devices() instead of fdisk

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tlaurion tlaurion marked this pull request as draft December 8, 2025 18:59
@tlaurion tlaurion force-pushed the replace_codebase_fdisk-l branch 2 times, most recently from b0bdb67 to 879fb3c Compare December 8, 2025 19:34
@tlaurion tlaurion changed the title Replace fdisk -l with sysfs-based disk enumeration for better busybox compatibility Replace fdisk -l with sysfs-based disk enumeration (2tb+ drive support) Dec 8, 2025
@tlaurion tlaurion marked this pull request as ready for review December 8, 2025 22:52
@tlaurion tlaurion force-pushed the replace_codebase_fdisk-l branch 2 times, most recently from 925c14e to b3c8e82 Compare December 15, 2025 21:03
… compatibility

fdisk -l is unreliable in busybox environments due to 2TB max size based on max
sector assumption.

Changes:
- Add list_block_devices() helper function to initrd/etc/functions and
  initrd/etc/gui_functions that uses sysfs to enumerate all block devices
  (SATA, NVMe, VirtIO, IDE)

- Update show_system_info() in initrd/etc/gui_functions to use sysfs for
  disk size reporting instead of parsing fdisk output

- Update show_system_info() in initrd/bin/oem-system-info-xx30 to use sysfs
  for disk size reporting

- Replace device_has_partitions() in initrd/etc/functions to check for
  partition entries in sysfs instead of parsing fdisk output

- Replace is_gpt_bios_grub() in initrd/etc/functions to use sysfs partition
  attributes (PARTTYPENAME) instead of fdisk parsing. Improves reliability
  for GPT disk detection while maintaining backward compatibility.

- Update detect_boot_device() in initrd/etc/functions to use list_block_devices()

- Update boot device selection in initrd/bin/config-gui.sh to use
  list_block_devices()

- Update root device selection in initrd/bin/config-gui.sh to use
  list_block_devices()

- Update root device detection in initrd/bin/root-hashes-gui.sh to use
  list_block_devices()

Benefits:
- Fixes disk detection failures with virtio block devices (qcow2 disks)
- Works reliably in busybox environments
- More robust than fdisk output parsing
- Supports all block device types (sd*, nvme*, vd*, hd*)
- Improves debuggability with explicit logging

Note: Interactive partitioning in initrd/etc/luks-functions still uses fdisk
for actually writing partition tables, which is its legitimate use case.

Signed-off-by: Thierry Laurion <insurgo@riseup.net>
@tlaurion tlaurion force-pushed the replace_codebase_fdisk-l branch from b3c8e82 to d296082 Compare December 15, 2025 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8tb drives are reported as 4tb drives under System Information menu

1 participant