Hold Tight...

0 %
Driving cybersecurity excellence
Innovator behind Kodachi OS
  • Residence:
    ::0
  • Uptime Binary:
    110001
  • Mantra:
    Innovate, Secure, Repeat
ONS
EEDS
NSSG
Cybersecurity
Programming & R&D
Cryptocurrency
AI & vibe coding
  • Bash
  • Gambas
  • Delphi
  • PHP
  • Visual Basic
  • Rust

Automate Systemd Setup with This Simple Bash Script

03/11/2024
3 min readDeep Tech3 code examplesUpdated October 2026

Key points

  • A Bash script that installs systemd-sysv, points GRUB at systemd, backs up the GRUB file and offers to reboot.
  • On current Debian and Ubuntu, systemd is already the init system: check with ps -p 1 -o comm= before you run it.
  • It rewrites the kernel command-line lines and returns network interfaces to eth0-style names, so compare /etc/default/grub.bak before you reboot.

Effortlessly Configure Systemd with This Bash Script

Updated October 2026: On current Debian (12 and 13) and Ubuntu, systemd is already the default init system and systemd-sysv is installed out of the box, so you only need this script to configure systemd on a system that was switched to another init or on a minimal image without it. Check first with ps -p 1 -o comm=: if it prints systemd, you are done. Two cautions before you run it:

  • It replaces the whole GRUB_CMDLINE_LINUX_DEFAULT and GRUB_CMDLINE_LINUX lines, so any kernel options you had added there are dropped. Compare with /etc/default/grub.bak before you reboot.
  • It switches network interfaces back to the old eth0 style names. If /etc/network/interfaces, netplan or NetworkManager refers to a name such as ens3 or enp1s0, change it to eth0 before you reboot, or a remote server comes back without a network connection.

Managing init systems can be challenging, especially when transitioning to systemd on Debian-based systems. This Systemd Issue Solver Bash script automates the 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.

Key Features of the Script

  • 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.

How It Works

  1. Installs systemd-sysv: Updates package lists and installs systemd-sysv to enable systemd as the default init system.
  2. Configures GRUB:
    • Updates /etc/default/grub to set systemd as the init system.
    • Disables predictable network interface names for consistent naming.
  3. Creates Backup: Saves a backup of the original GRUB configuration to ensure safety.
  4. Prompts for Reboot: Asks the user if they want to reboot immediately to apply the changes or reboot later manually.

Quick Start

  1. Save and Make Executable: copy the full script at the end of this post into a file named systemd-issue-solver.sh, then run:
   chmod +x systemd-issue-solver.sh
  1. Run the Script:
   sudo ./systemd-issue-solver.sh
  1. Follow Prompts:
    • Let the script handle installation and configuration.
    • Choose whether to reboot immediately or later.

Benefits

  • Time-Saving: Automates the configuration of systemd as the init system.
  • Enhanced Safety: Backs up GRUB configuration to prevent accidental misconfigurations.
  • User-Friendly: Provides clear prompts and ensures a smooth transition.
  • Reliable: Applies consistent network interface names (read the caution about renamed interfaces at the top first).

Conclusion

Transitioning to systemd doesn’t have to be complicated. This Bash script simplifies the process, automating configuration and ensuring a secure setup. Say goodbye to init system issues and streamline your Linux environment today! More of my server scripts are in Deep Tech.

ShellScript
#!/bin/bash
# =========================================
# Systemd Issue Solver
# =========================================
#
# Version: 1.0.0
# Script written by Warith AL Maawali
#
# Discord channel: https://discord.gg/KEFErEx
# Twitter: https://x.com/warith2020
# Linkedin: https://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: ./systemd-issue-solver.sh
#
# Usage Examples:
#   Run this script as root to configure systemd as the init system:
#     ./systemd-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
ShellScript
Posted in Deep TechTags: