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

bugfix: make sure busybox's fdisk output parsing is not positional, support qemu and fix debug output #1884

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions initrd/etc/functions
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,24 @@ device_has_partitions() {
# to satisfy fdisk. In that case, fdisk prints a partition table header
# but no partitions.
#
# This check covers that: [ $(fdisk -l "$b" | wc -l) -eq 5 ]
# In both cases the output is 5 lines: 3 about device info, 1 empty line
# and the 5th will be the table header or the invalid message.
# busybox's fdisk doesn't support >2TB devices since >2^32 sectors
# TODO: this is https://bugs.busybox.net/show_bug.cgi?id=16276
# revise logic when this is fixed, otherwise we can't rely on
# positional output, we need to force strings match only.
local DISK_DATA=$(fdisk -l "$DEVICE")
if echo "$DISK_DATA" | grep -q "doesn't contain a valid partition table" || \
[ "$(echo "$DISK_DATA" | wc -l)" -eq 5 ]; then
if echo "$DISK_DATA" | grep -q "doesn't contain a valid partition table"; then
# No partition table
return 1
fi
# There is a partition table
return 0

# Check for partition entries in the fdisk output
if echo "$DISK_DATA" | grep -q "^/dev"; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

IIRC, this will break on a device directly formatted FAT32 without being partitioned. (That's what I wrote above - in that case, fdisk prints out a partition table but with no partitions. The FAT32 "volume boot record" is essentially the same as a master boot record.)

Instead I'd suggest looking for the heading, then checking if there are any partition lines following it. awk would be a good fit for this.

If you don't beat me to it, I can suggest a solution here after I get through my post-holidays inbox 😁

# There are partitions
return 0
fi

# No partitions found
return 1
}

list_usb_storage() {
Expand Down Expand Up @@ -661,7 +668,7 @@ is_gpt_bios_grub() {

# Now we know the device and partition number, get the type. This is
# specific to GPT disks, MBR disks are shown differently by fdisk.
TRACE "$PART_DEV is partition $NUMBER of $DEVICE"
DEBUG "$PART_DEV is partition $NUMBER of $DEVICE"
if [ "$(fdisk -l "/dev/$DEVICE" | awk '$1 == '"$NUMBER"' {print $5}')" == grub ]; then
return 0
fi
Expand Down
2 changes: 1 addition & 1 deletion initrd/etc/gui_functions
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ show_system_info()
kernel=$(uname -s -r)

whiptail_type $BG_COLOR_MAIN_MENU --title 'System Info' \
--msgbox "${BOARD_NAME}\n\nFW_VER: ${FW_VER}\nKernel: ${kernel}\n\nCPU: ${cpustr}\nRAM: ${memtotal} GB\n$battery_status\n$(fdisk -l | grep -e '/dev/sd.:' -e '/dev/nvme.*:' | sed 's/B,.*/B/')" 0 80
--msgbox "${BOARD_NAME}\n\nFW_VER: ${FW_VER}\nKernel: ${kernel}\n\nCPU: ${cpustr}\nRAM: ${memtotal} GB\n$battery_status\n$(fdisk -l | grep -e '/dev/sd.:' -e '/dev/nvme.*:' -e '/dev/vd.:' | sed 's/B,.*/B/')" 0 80
}

# Get "Enable" or "Disable" to display in the configuration menu, based on a
Expand Down