From 9fa1e37d938118ed0fdd5858d42cafeb1f6ed03b Mon Sep 17 00:00:00 2001 From: cyteen Date: Mon, 16 Mar 2026 00:40:12 +0000 Subject: [PATCH] Renamed to bring functionality into the same namespace. --- 010_grub-commandline_console-blanking.sh | 6 ++ 010_grub-commandline_docker.sh | 31 +++++++ 010_grub-commandline_gfxmode.sh | 19 +++++ 010_grub-commandline_ignore_ppc.sh | 6 ++ ...rub-commandline_prevent_udev_net-rename.sh | 8 ++ grub-commandline_mod.sh | 83 +++++++++++++++++++ 6 files changed, 153 insertions(+) create mode 100644 010_grub-commandline_console-blanking.sh create mode 100755 010_grub-commandline_docker.sh create mode 100755 010_grub-commandline_gfxmode.sh create mode 100644 010_grub-commandline_ignore_ppc.sh create mode 100755 010_grub-commandline_prevent_udev_net-rename.sh create mode 100644 grub-commandline_mod.sh diff --git a/010_grub-commandline_console-blanking.sh b/010_grub-commandline_console-blanking.sh new file mode 100644 index 0000000..85f722d --- /dev/null +++ b/010_grub-commandline_console-blanking.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# the screen will blank after 3 minutes of inactivity on the TTY console. +NEWARG="consoleblank=3" +sudo sed -i -E "s|^(GRUB_CMDLINE_LINUX_DEFAULT=\"[^\"]*)\"|\1 ${NEWARG}\"|" /etc/default/grub +sudo update_grub diff --git a/010_grub-commandline_docker.sh b/010_grub-commandline_docker.sh new file mode 100755 index 0000000..be70c7b --- /dev/null +++ b/010_grub-commandline_docker.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# https://fabianlee.org/2020/01/18/docker-placing-limits-on-container-memory-using-cgroups/ + +# Internally Docker uses cgroups to limit memory resources, and in its simplest form is exposed as the flags “-m” and “–memory-swap” when bringing up a docker container. + +# sudo docker run -it -m 8m --memory-swap 8m alpine:latest /bin/sh + +# If you see the message above, or “WARNING: Your kernel does not support cgroup swap limit.”, +# then modify “/etc/default/grub” as below: + +## Docker likes kernel swappiness support (on reboot) +sudo bash -c "perl -i -pe 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"/g' /etc/default/grub" + +sudo update-grub +# Now that your server supports swap limit capabilities in your docker run command you can use --memory-swappiness=0 and set --memory-swap equal to --memory. You also need to set -Des.bootstrap.mlockall=true on the docker run commandline. + +# eg. +# https://stefanprodan.com/2016/elasticsearch-cluster-with-docker/ + +# docker run -d -p 9200:9200 \ +# --name es-t0 \ +# --network es-net \ +# -v "$PWD/storage":/usr/share/elasticsearch/data \ +# --cap-add=IPC_LOCK --ulimit nofile=65536:65536 --ulimit memlock=-1:-1 \ +# --memory="2g" --memory-swap="2g" --memory-swappiness=0 \ +# -e ES_HEAP_SIZE="1g" \ +# es-t \ +# -Des.bootstrap.mlockall=true \ +# -Des.network.host=_eth0_ \ +# -Des.discovery.zen.ping.multicast.enabled=false diff --git a/010_grub-commandline_gfxmode.sh b/010_grub-commandline_gfxmode.sh new file mode 100755 index 0000000..2fa5d39 --- /dev/null +++ b/010_grub-commandline_gfxmode.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# test script for 256 color on the fb console. https://www.robmeerman.co.uk/unix/256colours +#wget -c -O /var/tmp/256color.pl https://gist.githubusercontent.com/hSATAC/1095100/raw/ee5b4d79aee151248bdafa8b8412497a5a688d42/256color.pl + +# supported modes can be found at the grub console with 'vbeinfo' or 'videoinfo +# 0x17d 1920x1200x32 vga=381 +# 0x17c 1920x1200x8 vga=380 + +## Add this to the /etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT +gfxmode="1920x1200x32,1920x1200x8" +sed -i "s|^\(GRUB_GFXMODE=\).*|\1\"$gfxmode\"|" /etc/default/grub +sed -i '/^GRUB_GFXMODE=.*/ s/.*/&\nGRUB_GFXPAYLOAD_LINUX=\"keep\"/' /etc/default/grub + + +# DEPRICATED: vesafb requires a vga= on the kernel commandline. +#sed -i 's,^\(GRUB_CMDLINE_LINUX=\).*,\1'\"vga=381\"',' /etc/default/grub + +mount /boot/grub +update-grub diff --git a/010_grub-commandline_ignore_ppc.sh b/010_grub-commandline_ignore_ppc.sh new file mode 100644 index 0000000..9e6d939 --- /dev/null +++ b/010_grub-commandline_ignore_ppc.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# Set ignore bios throttling on the kernel commandline +NEWARG="processor.ignore_ppc=1" +sudo sed -i -E "s|^(GRUB_CMDLINE_LINUX_DEFAULT=\"[^\"]*)\"|\1 ${NEWARG}\"|" /etc/default/grub +sudo update_grub diff --git a/010_grub-commandline_prevent_udev_net-rename.sh b/010_grub-commandline_prevent_udev_net-rename.sh new file mode 100755 index 0000000..161072b --- /dev/null +++ b/010_grub-commandline_prevent_udev_net-rename.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# prevent renaming of network interfaces by udev +#ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules + +## Add this to the /etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT +#sed -i 's,^\(GRUB_CMDLINE_LINUX=\).*,\1'\"net.ifnames=0\"',' /etc/default/grub + + diff --git a/grub-commandline_mod.sh b/grub-commandline_mod.sh new file mode 100644 index 0000000..35c8505 --- /dev/null +++ b/grub-commandline_mod.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +# --- DEFAULTS --- +FILE="/etc/default/grub" +DRY_RUN=false +NEW_SETTING="" + +# --- HELP FUNCTION --- +usage() { + echo "Usage: sudo $0 [OPTION] \"setting=value\"" + echo "Example: sudo $0 \"consoleblank=3\"" + echo "" + echo "Options:" + echo " -d, --dry-run Show changes without applying them" + echo " -h, --help Display this help message" + exit 1 +} + +# --- ARGUMENT PARSING --- +while [[ $# -gt 0 ]]; do + case $1 in + -d | --dry-run) + DRY_RUN=true + shift + ;; + -h | --help) + usage + ;; + *) + NEW_SETTING="$1" + shift + ;; + esac +done + +# Check if a setting was actually provided +if [[ -z "$NEW_SETTING" ]]; then + echo "❌ Error: No GRUB setting provided." + usage +fi + +# --- LOGIC --- +apply_grub_change() { + local TARGET="$1" + # Regex: Appends TARGET inside the quotes of GRUB_CMDLINE_LINUX_DEFAULT + local SED_LOGIC="/^GRUB_CMDLINE_LINUX_DEFAULT=/ s/\"\([^\"]*\)\"/\"\1 $TARGET\"/; s/ */ /g; s/ $TARGET\"/$TARGET\"/" + + # 1. PRE-CHECK + if grep -q "$TARGET" "$FILE"; then + echo "ℹ️ SKIP: '$TARGET' already exists in $FILE." + return 0 + fi + + # 2. EXECUTION + if [ "$DRY_RUN" = true ]; then + echo "🔍 DRY RUN: Simulating '$TARGET' addition..." + grep "^GRUB_CMDLINE_LINUX_DEFAULT=" "$FILE" | sed "$SED_LOGIC" + else + # Ensure script is run as root for actual changes + if [[ $EUID -ne 0 ]]; then + echo "❌ Error: This script must be run with sudo to apply changes." + exit 1 + fi + + echo "💾 Backing up to $FILE.bak..." + cp "$FILE" "$FILE.bak" + + echo "🔧 Applying '$TARGET' to $FILE..." + sed -i "$SED_LOGIC" "$FILE" + + # 3. VERIFICATION & UPDATE + if grep -q "$TARGET" "$FILE"; then + echo "✅ SUCCESS: Updating bootloader..." + update-grub + else + echo "❌ ERROR: Failed to apply changes." + exit 1 + fi + fi +} + +# --- EXECUTE --- +apply_grub_change "$NEW_SETTING"