Skip to content

Instantly share code, notes, and snippets.

@j796160836
Created November 22, 2024 01:12
Show Gist options
  • Save j796160836/8015a73ea8278a95e2337a57e5c3c02f to your computer and use it in GitHub Desktop.
Save j796160836/8015a73ea8278a95e2337a57e5c3c02f to your computer and use it in GitHub Desktop.
Redhat/RockeyLinux 移除 swap https://aiarchives.org/id/S344wkzhHUg3ME2QhKoH
#!/bin/bash
# 取得 grubby --info DEFAULT 的輸出
grubby_info=$(grubby --info DEFAULT)
# 使用 grep 和 awk 抓取 args 中的 swap 相關參數
swap_args=$(echo "$grubby_info" | grep 'args=' | awk -F'"' '{print $2}' | grep -oE 'resume=[^ ]+|rd.lvm.lv=[^ ]+/swap')
# 檢查是否找到 swap 參數
if [[ -z "$swap_args" ]]; then
echo "未找到與 swap 相關的參數,無需移除"
exit 0
fi
# 將參數組合為 --remove-args 的格式
remove_args=$(echo "$swap_args" | tr '\n' ' ')
remove_args=$(echo "$remove_args" | sed 's/ $//') # 移除最後的空格
# 執行 grubby 指令
echo "正在執行: grubby --update-kernel=ALL --remove-args=\"$remove_args\""
grubby --update-kernel=ALL --remove-args="$remove_args"
# 檢查執行結果
if [[ $? -eq 0 ]]; then
echo "參數移除成功"
else
echo "參數移除失敗,請檢查輸出"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment