Skip to content

Commit 16a083e

Browse files
committed
Replace size reporting with sysfs helper; keep fdisk for partition tables
fdisk -l can’t be trusted inside Heads’ initrd: busybox limits it to 2 TiB and parsing its output is fragile. Changes relative to origin/master: * add new function disk_info_sysfs() in initrd/etc/functions – walks /sys/block, skips partition entries, and computes a byte count (preferring blockdev --getsize64, otherwise size*512) – converts to decimal GB, switching to TB for ≥1000 GB * update show_system_info() (gui_functions & oem‑system‑info‑xx30) to call the helper and no longer invoke `fdisk -l` for size output * add TRACE_FUNC/DEBUG logging around the helper invocation Tested in qemu/debian‑13/PureOS; only the size line differs, other behaviour is identical to master. Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent 1d224e2 commit 16a083e

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

initrd/bin/oem-system-info-xx30

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,8 @@ fi
5959
ec_ver_line=""
6060
[ -n "$EC_VER" ] && ec_ver_line="\nEC_VER: ${EC_VER}"
6161

62+
# gather disk info via helper (avoids busybox 2TB limit)
63+
disk_info="$(disk_info_sysfs)"
64+
6265
whiptail_type $BG_COLOR_MAIN_MENU $FB_OPTIONS --title 'System Info' \
63-
--msgbox "${BOARD_NAME}\nFW_VER: ${FW_VER}${ec_ver_line}\nKernel: ${kernel}\nCPU: ${cpustr} RAM: ${memtotal} GB $battery_status\n$(fdisk -l | grep -e '/dev/sd.:' -e '/dev/nvme.*:' | sed 's/B,.*/B/')\n\n$(cat /tmp/devices_usb_pci)" 0 80
66+
--msgbox "${BOARD_NAME}\nFW_VER: ${FW_VER}${ec_ver_line}\nKernel: ${kernel}\nCPU: ${cpustr} RAM: ${memtotal} GB $battery_status\n${disk_info}\n\n$(cat /tmp/devices_usb_pci)" 0 80

initrd/etc/functions

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,45 @@ device_has_partitions() {
822822
return 0
823823
}
824824

825+
# Build displayable disk information using sysfs (vs current busybox's 2tb limit per https://bugs.busybox.net/show_bug.cgi?id=16276)
826+
# Output format: "Disk /dev/<name>: <GB> GB" per line
827+
# The /sys/block/*/size entry is always counted in 512-byte sectors, so
828+
# calculate using bytes from blockdev when available or multiply by 512.
829+
disk_info_sysfs() {
830+
TRACE_FUNC
831+
local disk_info=""
832+
for dev in /sys/block/sd* /sys/block/nvme* /sys/block/vd* /sys/block/hd*; do
833+
if [ -e "$dev" ]; then
834+
# ignore partition entries (they contain a 'partition' file)
835+
if [ -e "$dev/partition" ]; then
836+
continue
837+
fi
838+
local devname=$(basename "$dev")
839+
local size_bytes=""
840+
if command -v blockdev >/dev/null 2>&1; then
841+
size_bytes=$(blockdev --getsize64 "/dev/${devname}" 2>/dev/null)
842+
fi
843+
if [ -z "$size_bytes" ] || ! [ "$size_bytes" -gt 0 ] 2>/dev/null; then
844+
local size_sectors_512=$(cat "$dev/size" 2>/dev/null)
845+
if [ -n "$size_sectors_512" ] && [ "$size_sectors_512" -gt 0 ] 2>/dev/null; then
846+
size_bytes=$((size_sectors_512 * 512))
847+
fi
848+
fi
849+
if [ -n "$size_bytes" ] && [ "$size_bytes" -gt 0 ] 2>/dev/null; then
850+
local size_gb=$(((size_bytes + 500000000) / 1000000000))
851+
# show TB when >= 1000 GB for better UX
852+
if [ "$size_gb" -ge 1000 ]; then
853+
local size_tb=$(((size_bytes + 500000000000) / 1000000000000))
854+
printf -v disk_info "%sDisk /dev/%s: %s TB\n" "$disk_info" "$devname" "$size_tb"
855+
else
856+
printf -v disk_info "%sDisk /dev/%s: %s GB\n" "$disk_info" "$devname" "$size_gb"
857+
fi
858+
fi
859+
fi
860+
done
861+
printf "%s" "$disk_info"
862+
}
863+
825864
list_usb_storage() {
826865
TRACE_FUNC
827866
# List all USB storage devices, including partitions unless we received argument stating we want drives only
@@ -1259,24 +1298,29 @@ find_lvm_vg_name() {
12591298
# GPT-partitioned disk.
12601299
is_gpt_bios_grub() {
12611300
TRACE_FUNC
1301+
DEBUG "is_gpt_bios_grub: PART_DEV=$1"
12621302

12631303
local PART_DEV="$1" DEVICE NUMBER
12641304

12651305
# Figure out the partitioned device containing this device (if there is
12661306
# one) from /sys/class/block.
12671307
local DEVICE_MATCHES=("/sys/class/block/"*"/$(basename "$PART_DEV")")
1308+
DEBUG "is_gpt_bios_grub: DEVICE_MATCHES=${DEVICE_MATCHES[*]}"
12681309

12691310
DEVICE="$(echo "${DEVICE_MATCHES[0]}" | cut -d/ -f5)"
12701311
if [ "${#DEVICE_MATCHES[@]}" -ne 1 ] || [ "$DEVICE" = "*" ]; then
1312+
DEBUG "is_gpt_bios_grub: ambiguous DEVICE, returning false"
12711313
return 0
12721314
fi
12731315

12741316
# Extract the partition number
12751317
if ! [[ $(basename "$PART_DEV") =~ ([0-9]+)$ ]]; then
1318+
DEBUG "is_gpt_bios_grub: cannot parse partition number"
12761319
return 0 # Can't figure out the partition number
12771320
fi
12781321

12791322
NUMBER="${BASH_REMATCH[1]}"
1323+
DEBUG "is_gpt_bios_grub: DEVICE=$DEVICE NUMBER=$NUMBER"
12801324

12811325
# Now we know the device and partition number, get the type. This is
12821326
# specific to GPT disks, MBR disks are shown differently by fdisk.

initrd/etc/gui_functions

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ show_system_info() {
182182
[ -n "$EC_VER" ] && ec_ver_line="
183183
EC_VER: ${EC_VER}"
184184

185+
local disk_info="$(disk_info_sysfs)"
186+
TRACE_FUNC
187+
DEBUG "show_system_info: disk_info=\n${disk_info}"
188+
185189
local msgbox="${BOARD_NAME}
186190
187191
FW_VER: ${FW_VER}${ec_ver_line}
@@ -191,7 +195,7 @@ show_system_info() {
191195
Microcode: $(cat /proc/cpuinfo | grep microcode | uniq | cut -d':' -f2 | tr -d ' ')
192196
RAM: ${memtotal} GB
193197
$battery_status
194-
$(fdisk -l 2>/dev/null | grep -e '/dev/sd.:' -e '/dev/nvme.*:' | sed 's/B,.*/B/')
198+
${disk_info}
195199
"
196200

197201
local msgbox_rm_tabs=$(echo "$msgbox" | tr -d "\t")

0 commit comments

Comments
 (0)