Created
July 18, 2025 12:39
-
-
Save Its4Nik/6e62d5a7b8e1e2649fe35a7d96996457 to your computer and use it in GitHub Desktop.
This is a simple bash script that will gather system boot info and general hardware info. (Only tested on Arch!)
This file contains hidden or 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 | |
set -euo pipefail | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[1;33m' | |
BLUE='\033[0;34m' | |
BOLD='\033[1m' | |
NC='\033[0m' | |
print_section() { | |
echo -e "\n${BOLD}${BLUE}=== $1 ===${NC}" | |
} | |
print_info() { | |
echo -e "${GREEN}$1:${NC} $2" | |
} | |
print_warning() { | |
echo -e "${YELLOW}WARNING:${NC} $1" | |
} | |
print_error() { | |
echo -e "${RED}ERROR:${NC} $1" | |
} | |
safe_command() { | |
if command -v "$1" >/dev/null 2>&1; then | |
eval "$2" 2>/dev/null || echo "N/A" | |
else | |
echo "N/A (command not found)" | |
fi | |
} | |
### System Information | |
print_section "System Information" | |
HOSTNAME=$(hostname) | |
DISTRO=$(lsb_release -d 2>/dev/null | cut -f2 | head -1 || grep PRETTY_NAME /etc/os-release 2>/dev/null | cut -d'"' -f2 || echo "Unknown") | |
KERNEL=$(uname -r) | |
ARCH=$(uname -m) | |
print_info "Hostname" "$HOSTNAME" | |
print_info "Distribution" "$DISTRO" | |
print_info "Kernel Version" "$KERNEL" | |
print_info "Architecture" "$ARCH" | |
### Boot Mode Detection | |
print_section "Boot Mode & Firmware" | |
if [ -d /sys/firmware/efi ]; then | |
BOOT_MODE="UEFI" | |
SECURE_BOOT=$(bootctl status 2>/dev/null | grep "Secure Boot" | awk '{print $3}' || echo "Unknown") | |
print_info "Boot Mode" "$BOOT_MODE" | |
print_info "Secure Boot" "$SECURE_BOOT" | |
else | |
BOOT_MODE="Legacy BIOS" | |
print_info "Boot Mode" "$BOOT_MODE" | |
fi | |
### EFI Boot Manager Information | |
if [ "$BOOT_MODE" = "UEFI" ]; then | |
print_section "EFI Boot Information" | |
if command -v efibootmgr >/dev/null 2>&1; then | |
EFI_BOOT_MGR_OUT=$(sudo efibootmgr 2>/dev/null) | |
if [ -n "$EFI_BOOT_MGR_OUT" ]; then | |
CURRENT_BOOT=$(echo "$EFI_BOOT_MGR_OUT" | grep "BootCurrent" | awk '{print $2}') | |
BOOT_ORDER=$(echo "$EFI_BOOT_MGR_OUT" | grep "BootOrder" | awk '{print $2}') | |
BOOT_LOADER=$(echo "$EFI_BOOT_MGR_OUT" | grep -i "^Boot$CURRENT_BOOT" | sed -E 's/^Boot[0-9A-Fa-f]+\** //' | awk '{print $1}') | |
print_info "Current Boot Entry" "$CURRENT_BOOT" | |
print_info "Boot Order" "$BOOT_ORDER" | |
print_info "Boot loader" "$BOOT_LOADER" | |
else | |
print_error "Unable to read EFI boot manager information" | |
fi | |
else | |
print_warning "efibootmgr not available" | |
fi | |
fi | |
### Kernel Information | |
print_section "Kernel Information" | |
KERNEL_CMDLINE=$(cat /proc/cmdline 2>/dev/null || echo "N/A") | |
KERNEL_MODULES=$(lsmod | wc -l) | |
KERNEL_VERSION_FULL=$(uname -a) | |
print_info "Kernel Command Line" "$KERNEL_CMDLINE" | |
print_info "Loaded Modules Count" "$((KERNEL_MODULES - 1))" | |
print_info "Full Kernel Info" "$KERNEL_VERSION_FULL" | |
### Init System Detection | |
print_section "Init System Information" | |
INIT_SYSTEM="Unknown" | |
if [ -f /run/systemd/system ] || pgrep -f systemd >/dev/null 2>&1; then | |
INIT_SYSTEM="systemd" | |
if command -v systemctl >/dev/null 2>&1; then | |
SYSTEMD_VERSION=$(systemctl --version 2>/dev/null | head -1 | awk '{print $2}' || echo "Unknown") | |
print_info "Init System" "$INIT_SYSTEM (version $SYSTEMD_VERSION)" | |
# Default target | |
DEFAULT_TARGET=$(systemctl get-default 2>/dev/null || echo "Unknown") | |
print_info "Default Target" "$DEFAULT_TARGET" | |
else | |
print_info "Init System" "$INIT_SYSTEM" | |
fi | |
elif [ -f /etc/inittab ] && pgrep -f init >/dev/null 2>&1; then | |
INIT_SYSTEM="SysVinit" | |
print_info "Init System" "$INIT_SYSTEM" | |
elif pgrep -f upstart >/dev/null 2>&1; then | |
INIT_SYSTEM="Upstart" | |
print_info "Init System" "$INIT_SYSTEM" | |
elif [ -f /etc/runit/1 ] || pgrep -f runit >/dev/null 2>&1; then | |
INIT_SYSTEM="runit" | |
print_info "Init System" "$INIT_SYSTEM" | |
elif [ -f /etc/s6/current ] || pgrep -f s6 >/dev/null 2>&1; then | |
INIT_SYSTEM="s6" | |
print_info "Init System" "$INIT_SYSTEM" | |
else | |
print_info "Init System" "$INIT_SYSTEM" | |
fi | |
### Initramfs/Initrd Information | |
print_section "Initramfs/Initrd Information" | |
INITRAMFS_TOOL="Unknown" | |
# Check for dracut | |
if command -v dracut >/dev/null 2>&1; then | |
INITRAMFS_TOOL="dracut" | |
DRACUT_VERSION=$(dracut --version 2>/dev/null | head -1 || echo "Unknown version") | |
print_info "Initramfs Tool" "$INITRAMFS_TOOL ($DRACUT_VERSION)" | |
# Check for mkinitcpio (Arch) | |
elif [ -f /etc/mkinitcpio.conf ]; then | |
INITRAMFS_TOOL="mkinitcpio" | |
print_info "Initramfs Tool" "$INITRAMFS_TOOL" | |
# Parse mkinitcpio configuration | |
if [ -f /etc/mkinitcpio.conf ]; then | |
HOOKS=$(grep "^HOOKS=" /etc/mkinitcpio.conf 2>/dev/null | cut -d'=' -f2 | tr -d '()' || echo "N/A") | |
MODULES=$(grep "^MODULES=" /etc/mkinitcpio.conf 2>/dev/null | cut -d'=' -f2 | tr -d '()' || echo "N/A") | |
print_info "Hooks" "$HOOKS" | |
print_info "Modules" "$MODULES" | |
fi | |
# Check for initramfs-tools (Debian/Ubuntu) | |
elif [ -d /etc/initramfs-tools ] || command -v update-initramfs >/dev/null 2>&1; then | |
INITRAMFS_TOOL="initramfs-tools" | |
print_info "Initramfs Tool" "$INITRAMFS_TOOL" | |
else | |
print_info "Initramfs Tool" "$INITRAMFS_TOOL" | |
fi | |
# List current initramfs files | |
if [ -d /boot ]; then | |
echo -e "\n${BOLD}Initramfs Files:${NC}" | |
sudo find /boot -name "initramfs*" -o -name "initrd*" 2>/dev/null | sort | while read -r file; do | |
print_info "$file" "$(sudo du -h "$file" | awk '{print $1}')" | |
done | |
fi | |
### Boot Process Timing | |
print_section "Boot Performance" | |
if command -v systemd-analyze >/dev/null 2>&1; then | |
BOOT_TIME=$(systemd-analyze 2>/dev/null | head -1 || echo "N/A") | |
print_info "Boot Time" "$BOOT_TIME" | |
echo -e "\n${BOLD}Top 5 Slowest Services:${NC}" | |
systemd-analyze blame 2>/dev/null | head -5 | while read -r line; do | |
echo " $line" | |
done | |
else | |
print_info "Boot Time" "N/A (systemd-analyze not available)" | |
fi | |
### Memory Information | |
print_section "Memory Information" | |
if [ -f /proc/meminfo ]; then | |
TOTAL_MEM=$(grep "MemTotal" /proc/meminfo | awk '{$2/=1048576; printf "%.2fGB\n", $2}') | |
AVAILABLE_MEM=$(grep "MemAvailable" /proc/meminfo | awk '{$2/=1048576; printf "%.2fGB\n", $2}' ) | |
print_info "Total Memory" "$TOTAL_MEM" | |
print_info "Available Memory" "$AVAILABLE_MEM" | |
fi | |
### Storage Information | |
print_section "Storage Information" | |
echo -e "\n${BOLD}Mounted Filesystems:${NC}" | |
df -h | while read -r line; do | |
echo " $line" | |
done | |
if [ -f /proc/mounts ]; then | |
ROOT_FS=$(grep " / " /proc/mounts | awk '{print $3}' | head -1) | |
BOOT_FS=$(grep "/boot" /proc/mounts | awk '{print $3}' | head -1 || echo "N/A") | |
print_info "Root Filesystem" "$ROOT_FS" | |
print_info "Boot Filesystem" "$BOOT_FS" | |
fi | |
### Network Boot Information | |
print_section "Network Boot Information" | |
if [ -f /proc/cmdline ]; then | |
if grep -q "ip=" /proc/cmdline; then | |
print_info "Network Boot" "Detected (PXE/Network boot parameters found)" | |
IP_CONFIG=$(grep -o "ip=[^ ]*" /proc/cmdline || echo "N/A") | |
print_info "IP Configuration" "$IP_CONFIG" | |
else | |
print_info "Network Boot" "Not detected" | |
fi | |
fi | |
### Hardware Information | |
print_section "Hardware Information" | |
if command -v dmidecode >/dev/null 2>&1; then | |
SYSTEM_MANUFACTURER=$(sudo dmidecode -s system-manufacturer 2>/dev/null || echo "N/A") | |
BIOS_VERSION=$(sudo dmidecode -s bios-version 2>/dev/null || echo "N/A") | |
print_info "System Manufacturer" "$SYSTEM_MANUFACTURER" | |
print_info "BIOS Version" "$BIOS_VERSION" | |
fi | |
CPU_INFO=$(lscpu | grep "Model name" | cut -d: -f2 | sed 's/^ *//' | head -1 || echo "N/A") | |
print_info "CPU" "$CPU_INFO" | |
### Summary | |
print_section "Boot Process Summary" | |
echo -e "This system boots using ${GREEN}$BOOT_MODE${NC} mode with ${GREEN}$BOOT_LOADER${NC} bootloader" | |
echo -e "Init system: ${GREEN}$INIT_SYSTEM${NC}" | |
echo -e "Initramfs tool: ${GREEN}$INITRAMFS_TOOL${NC}" | |
echo -e "Kernel: ${GREEN}$KERNEL${NC} on ${GREEN}$ARCH${NC}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment