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.bakbefore 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_DEFAULTandGRUB_CMDLINE_LINUXlines, so any kernel options you had added there are dropped. Compare with/etc/default/grub.bakbefore you reboot. - It switches network interfaces back to the old
eth0style names. If/etc/network/interfaces, netplan or NetworkManager refers to a name such asens3orenp1s0, change it toeth0before 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-sysvif 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
- Installs systemd-sysv: Updates package lists and installs
systemd-sysvto enable systemd as the default init system. - Configures GRUB:
- Updates
/etc/default/grubto set systemd as the init system. - Disables predictable network interface names for consistent naming.
- Updates
- Creates Backup: Saves a backup of the original GRUB configuration to ensure safety.
- Prompts for Reboot: Asks the user if they want to reboot immediately to apply the changes or reboot later manually.
Quick Start
- 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
- Run the Script:
sudo ./systemd-issue-solver.sh
- 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.
#!/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