Last active
November 3, 2024 19:28
-
-
Save WMAL/a30bb45c43204b2faba768d946b32a5a to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment