Skip to content

Instantly share code, notes, and snippets.

@Jobians
Created October 31, 2025 01:16
Show Gist options
  • Select an option

  • Save Jobians/1556f4765852aab7a5cf97b507650db9 to your computer and use it in GitHub Desktop.

Select an option

Save Jobians/1556f4765852aab7a5cf97b507650db9 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Configure GRUB for serial console in Debian (Termux-friendly)
GRUB_FILE="/etc/default/grub"
BACKUP_FILE="/etc/default/grub.bak.$(date +%F-%T)"
echo "🔹 Backing up current GRUB config to $BACKUP_FILE"
sudo cp "$GRUB_FILE" "$BACKUP_FILE"
echo "🔹 Configuring GRUB for serial console..."
# Remove existing lines if present
sudo sed -i '/^GRUB_TERMINAL=/d' "$GRUB_FILE"
sudo sed -i '/^GRUB_SERIAL_COMMAND=/d' "$GRUB_FILE"
sudo sed -i '/^GRUB_CMDLINE_LINUX=/d' "$GRUB_FILE"
# Append new settings
sudo bash -c "echo 'GRUB_TERMINAL=serial' >> $GRUB_FILE"
sudo bash -c "echo 'GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\"' >> $GRUB_FILE"
sudo bash -c "echo 'GRUB_CMDLINE_LINUX=\"console=ttyS0 loglevel=3\"' >> $GRUB_FILE"
echo "🔹 Updating GRUB..."
sudo update-grub
echo "✅ GRUB configured for serial console. Reboot your VM to apply changes."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment