Created
November 22, 2024 01:12
-
-
Save j796160836/8015a73ea8278a95e2337a57e5c3c02f to your computer and use it in GitHub Desktop.
Redhat/RockeyLinux 移除 swap https://aiarchives.org/id/S344wkzhHUg3ME2QhKoH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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