fix system-info disk space in LXC (#18696)
Ilya Mashchenko committed
Oct 6, 2024 at 19:30 UTC
ed0bf35e382f527c37f9feaaa631f095c245ac42
1 file changed
+13
-2
src/daemon/system-info.sh
+13
-2
@@ -361,6 +361,17 @@ fi
361
# -------------------------------------------------------------------------------------------------
362
# Detect the total system disk space
363
364
+is_inside_lxc_container() {
365
+ mounts_file="/proc/self/mounts"
366
+
367
+ [ ! -r "$mounts_file" ] && return 1
368
+
369
+ # Check if lxcfs is mounted on /proc
370
+ awk '$1 == "lxcfs" && $2 ~ "^/proc" { found=1; exit } END { exit !found }' "$mounts_file"
371
+
372
+ return $?
373
+}
374
+
375
DISK_SIZE="unknown"
376
DISK_DETECTION="none"
377
@@ -393,7 +404,7 @@ elif [ "${KERNEL_NAME}" = FreeBSD ]; then
404
total="$(df -t ${types} -c -k | tail -n 1 | awk '{print $2}')"
405
DISK_SIZE="$((total * 1024))"
406
else
396
- if [ -d /sys/block ] && [ -r /proc/devices ]; then
407
+ if [ -d /sys/block ] && [ -r /proc/devices ] && ! is_inside_lxc_container; then
408
dev_major_whitelist=''
409
410
# This is a list of device names used for block storage devices.
@@ -424,7 +435,7 @@ else
435
else
436
DISK_DETECTION="df"
437
include_fs_types="ext*|btrfs|xfs|jfs|reiser*|zfs"
427
- DISK_SIZE=$(($(df -T -P | tail -n +2 | sort -u -k 1 | grep "${include_fs_types}" | awk '{print $3}' | tr '\n' '+' | head -c -1) * 1024))
438
+ DISK_SIZE=$(($(df -T -P | tail -n +2 | sort -u -k 1 | grep -E "${include_fs_types}" | awk '{print $3}' | tr '\n' '+' | head -c -1) * 1024))
439
fi
440
fi
441