Hold Tight...

0 %
Warith AL Maawali
Driving cybersecurity excellence
Innovator behind Linux Kodachi
  • Residence:
    ::0
  • Uptime Binary:
    101110
  • Mantra:
    Innovate, Secure, Repeat
ONS
EEDS
NSSG
Visual basic
Gambas
PHP
Delphi
Bash
  • Cybersecurity
  • Generative AI
  • Cloud & Automation
  • Cryptocurrency

Automate Systemd Setup with This Simple Bash Script

03/11/2024

Effortlessly Configure Systemd with This Bash Script

Managing init systems can be challenging, especially when transitioning to systemd on Debian-based systems. Systemd Issue Solver Bash script automates this process, ensuring a smooth and error-free configuration.

What is Systemd?

Systemd is a system and service manager for Linux operating systems, widely adopted for its efficiency and comprehensive features. It handles system initialization, service management, and more, providing a unified framework for managing system processes.

Overview of the Systemd Issue Solver Script

This Bash script automates the configuration of systemd as the init system on Debian-based systems. Here’s a quick look at its main functionalities:

Key Features

  • Root Privileges Check: Ensures the script is run with the necessary administrative permissions.
  • Automatic Installation: Installs systemd-sysv if it’s not already present, enabling systemd as the default init system.
  • GRUB Configuration: Updates GRUB settings to use systemd and disables predictable network interface names for consistency.
  • Backup and Safety: Creates a backup of the existing GRUB configuration before making changes.
  • User Prompt for Reboot: Prompts the user to reboot the system to apply changes immediately or later at their convenience.
Bash
#!/bin/bash
# =========================================
# Systemd Issue Solver
# =========================================
#
# Version: 1.0.0
# Script written by Warith AL Maawali
#
# Discord channel: https://discord.gg/KEFErEx
# Twitter: http://twitter.com/warith2020
# Linkedin: http://www.linkedin.com/in/warith1977
# Website: https://www.digi77.com
# (c) 2024
#
# Description:
# This script configures systemd as the init system on a Debian-based system.
# It ensures root privileges, updates system packages, configures GRUB to use systemd,
# and prompts the user to reboot the system to apply changes.
#
# This software is dual-licensed:
#
# Personal, non-commercial use: Apache License 2.0
# Commercial, corporate, or organizational use: Separate commercial license required.
# Contact me for licensing inquiries.
#
# Usage: ./systmd-issue-solver.sh
#
# Usage Examples:
#   Run this script as root to configure systemd as the init system:
#     ./systmd-issue-solver.sh
# =========================================

# Global variables
GRUB_FILE="/etc/default/grub"
GRUB_BACKUP_FILE="/etc/default/grub.bak"
SYSTEMD_PACKAGE="systemd-sysv"
GRUB_CMDLINE_LINUX_DEFAULT="GRUB_CMDLINE_LINUX_DEFAULT=\"quiet init=/lib/systemd/systemd\""
GRUB_CMDLINE_LINUX="GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\""

# Function to configure systemd as the init system
configure_systemd() {
  # Ensure the script is running as root
  if [ "$(id -u)" -ne 0 ]; then
    echo "Please run this script as root or with sudo privileges."
    exit 1
  fi

  # Update package lists and install systemd-sysv if it's not already installed
  echo "Installing $SYSTEMD_PACKAGE..."
  apt update && apt install -y $SYSTEMD_PACKAGE

  # Update /etc/default/grub with systemd as the init system
  echo "Configuring GRUB to use systemd as init..."

  # Backup the existing grub file
  cp $GRUB_FILE $GRUB_BACKUP_FILE

  # Use sed to update the GRUB_CMDLINE_LINUX_DEFAULT line
  sed -i "/GRUB_CMDLINE_LINUX_DEFAULT=/c\\$GRUB_CMDLINE_LINUX_DEFAULT" $GRUB_FILE

  # Ensure net.ifnames and biosdevname are disabled for consistent network names
  sed -i "/GRUB_CMDLINE_LINUX=/c\\$GRUB_CMDLINE_LINUX" $GRUB_FILE

  # Update GRUB to apply the new configuration
  echo "Updating GRUB..."
  update-grub

  # Confirm with the user before rebooting
  echo "Configuration complete. The system needs to reboot to apply changes."
  read -p "Do you want to reboot now? (y/n): " REBOOT_CONFIRM

  if [[ "$REBOOT_CONFIRM" =~ ^[Yy]$ ]]; then
    echo "Rebooting..."
    reboot
  else
    echo "Reboot canceled. Please reboot manually to apply changes."
  fi
}

# Call the function to execute the script
configure_systemd
Bash
Posted in Tech BlogTags:
© 2024 Warith AL Maawali. All Rights Reserved.
Stay Secure, Stay Assured.