From 7e84740222366261d66ffe45df2efe22b043ded3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Mon, 23 Mar 2026 10:47:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(zram):=20=E4=BC=98=E5=8C=96=20zram=20?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=A3=80=E6=B5=8B=E4=B8=8E=E5=86=85=E5=AD=98?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/1.sh b/1.sh index 95ca3ee..5f5d27c 100644 --- a/1.sh +++ b/1.sh @@ -291,8 +291,23 @@ install_zram() { print_yellow "未找到 modprobe,继续尝试配置 zram-tools" fi + if command -v udevadm >/dev/null 2>&1; then + udevadm settle || true + fi + + if [ ! -d /sys/block/zram0 ] || [ ! -b /dev/zram0 ]; then + print_yellow "未检测到可用的 zram0 设备,跳过 zram 配置" + return 0 + fi + local total_mem algo percent - total_mem=$(free -m | awk '/^Mem:/{print $2}') + total_mem=$(awk '/MemTotal/{print int($2 / 1024)}' /proc/meminfo) + + if ! [[ "$total_mem" =~ ^[0-9]+$ ]] || [ "$total_mem" -le 0 ]; then + print_yellow "无法准确检测总内存,跳过 zram 配置" + return 0 + fi + echo "检测到总内存: ${total_mem}MB" if [ "$total_mem" -le 2500 ]; then