Skip to content

Instantly share code, notes, and snippets.

@DanielFeichtinger
Last active December 5, 2025 10:13
Show Gist options
  • Select an option

  • Save DanielFeichtinger/66471547842000a917541f27a9db5616 to your computer and use it in GitHub Desktop.

Select an option

Save DanielFeichtinger/66471547842000a917541f27a9db5616 to your computer and use it in GitHub Desktop.
Chimera Plasma
#!/bin/sh
#
# Chimera Linux Minimal Installation Script
# Target: ZFS root filesystem with KDE Plasma desktop
# System: UEFI x86_64
#
set -eu
# ============================================================================
# Configuration
# ============================================================================
# Target disk - ADJUST THIS!
DISK="/dev/sda" # Common for most systems, change to /dev/nvme0n1 for NVMe
# Partition configuration
EFI_PART="1"
POOL_PART="2"
# For SATA/SCSI disks (e.g., /dev/sda)
EFI_DEVICE="${DISK}${EFI_PART}"
POOL_DEVICE="${DISK}${POOL_PART}"
# For NVMe disks (e.g., /dev/nvme0n1), uncomment these instead:
# EFI_DEVICE="${DISK}p${EFI_PART}"
# POOL_DEVICE="${DISK}p${POOL_PART}"
# ZFS pool name
POOL_NAME="zroot"
# System hostname
HOSTNAME="chimera-vm"
# Admin user (will prompt if not set)
ADMIN_USER=""
ADMIN_PASSWORD=""
# Mount point
TARGET="/mnt"
# ============================================================================
# Preflight checks
# ============================================================================
echo "==> Chimera Linux ZFS Installation Script"
echo ""
if [ "$(id -u)" -ne 0 ]; then
echo "Error: This script must be run as root"
exit 1
fi
# Install required tools
echo "==> Installing required tools..."
apk add parted gptfdisk
if [ ! -b "$DISK" ]; then
echo "Error: Disk $DISK not found"
echo "Available disks:"
lsblk -d -o NAME,SIZE,TYPE | grep disk
exit 1
fi
echo "WARNING: This will DESTROY all data on $DISK"
echo "Press Ctrl+C to abort, or Enter to continue..."
read dummy
# ============================================================================
# Cleanup from any previous runs
# ============================================================================
echo "==> Cleaning up any previous installation attempts..."
# Load ZFS module if not loaded
modprobe zfs 2>/dev/null || true
# Unmount any existing mounts at target
if mountpoint -q "${TARGET}/boot" 2>/dev/null; then
umount "${TARGET}/boot" || true
fi
# Unmount and export ZFS pool if it exists
if zpool list "$POOL_NAME" >/dev/null 2>&1; then
echo "==> Found existing pool '$POOL_NAME', exporting..."
zfs umount -a 2>/dev/null || true
zpool export "$POOL_NAME" 2>/dev/null || true
fi
# Force unmount any partitions on the target disk
echo "==> Unmounting any partitions on $DISK..."
for part in ${DISK}* ${DISK}p* ; do
if [ -b "$part" ] && [ "$part" != "$DISK" ]; then
umount -f "$part" 2>/dev/null || true
fi
done
# Use dmsetup to remove any device mapper devices for this disk
echo "==> Removing device mapper devices..."
for dm in $(dmsetup ls --target crypt 2>/dev/null | awk '{print $1}'); do
dmsetup remove "$dm" 2>/dev/null || true
done
# Clear ZFS labels from disk
echo "==> Clearing ZFS labels..."
zpool labelclear -f "$DISK" 2>/dev/null || true
for part in ${DISK}* ${DISK}p* ; do
if [ -b "$part" ] && [ "$part" != "$DISK" ]; then
zpool labelclear -f "$part" 2>/dev/null || true
fi
done
# Give the system a moment to release resources
sleep 2
# Remove target directory contents if it exists
if [ -d "$TARGET" ]; then
rm -rf "${TARGET}"/* 2>/dev/null || true
rmdir "$TARGET" 2>/dev/null || true
fi
# ============================================================================
# Disk partitioning
# ============================================================================
echo "==> Wiping disk and creating partitions..."
wipefs -a "$DISK"
sgdisk --zap-all "$DISK"
# Create EFI partition (1GB) - will contain boot files
sgdisk -n "${EFI_PART}:1m:+1024m" -t "${EFI_PART}:ef00" "$DISK"
# Create ZFS partition (rest of disk)
sgdisk -n "${POOL_PART}:0:0" -t "${POOL_PART}:bf00" "$DISK"
partprobe "$DISK"
sleep 2
# ============================================================================
# Create filesystems
# ============================================================================
echo "==> Creating EFI filesystem..."
mkfs.vfat -F32 "$EFI_DEVICE"
echo "==> Loading ZFS module..."
modprobe zfs
echo "==> Creating ZFS pool..."
zpool create -f \
-o ashift=12 \
-O acltype=posixacl \
-O canmount=off \
-O compression=lz4 \
-O dnodesize=auto \
-O normalization=formD \
-O relatime=on \
-O xattr=sa \
-O mountpoint=/ \
-R "$TARGET" \
"$POOL_NAME" "$POOL_DEVICE"
echo "==> Creating ZFS datasets..."
zfs create -o canmount=off -o mountpoint=none "${POOL_NAME}/ROOT"
zfs create -o canmount=noauto -o mountpoint=/ "${POOL_NAME}/ROOT/chimera"
zfs create -o mountpoint=/home "${POOL_NAME}/home"
# Mount root (home will auto-mount)
zfs mount "${POOL_NAME}/ROOT/chimera"
# Set bootfs
zpool set bootfs="${POOL_NAME}/ROOT/chimera" "$POOL_NAME"
# ============================================================================
# Mount EFI partition
# ============================================================================
echo "==> Mounting EFI partition at /boot..."
mkdir -p "${TARGET}/boot"
mount "$EFI_DEVICE" "${TARGET}/boot"
# ============================================================================
# Install base system
# ============================================================================
echo "==> Installing base system..."
chimera-bootstrap -l "${TARGET}" base-full
# ============================================================================
# Chroot configuration
# ============================================================================
echo "==> Configuring system (chroot)..."
# Prompt for admin user if not set
if [ -z "$ADMIN_USER" ]; then
echo ""
echo "==> Administrator Account Setup"
while true; do
read -p "Enter username for administrator: " ADMIN_USER
if [ -z "$ADMIN_USER" ]; then
echo "Username cannot be empty"
continue
fi
break
done
fi
# Create setup script in target's /root
cat > "${TARGET}/root/setup.sh" << EOF
#!/bin/sh
set -e
echo "==> Updating packages..."
apk update
apk upgrade
echo "==> Installing system packages..."
apk add linux-lts linux-lts-zfs-bin grub-x86_64-efi efibootmgr plasma-desktop sddm dbus elogind bash nano network-manager-applet firefox oils-for-unix
echo "==> Generating initramfs..."
update-initramfs -c -k all
echo "==> Installing GRUB..."
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=chimera
echo "==> Generating GRUB config..."
update-grub
echo "==> Creating ZFS hostid..."
zgenhostid \$(od -An -N4 -tx4 /dev/urandom | tr -d ' ')
echo "==> Setting hostname..."
echo '$HOSTNAME' > /etc/hostname
echo "==> Generating fstab..."
genfstab -U / >> /etc/fstab
echo "==> Creating administrator account..."
useradd -m -G wheel -s /usr/bin/osh '$ADMIN_USER'
echo "==> Disabling root login..."
passwd -l root
echo "==> Enabling system services..."
dinitctl enable sddm
dinitctl enable NetworkManager
dinitctl enable dbus
dinitctl enable elogind 2>/dev/null || true
dinitctl enable syslog-ng
echo "==> Chroot configuration complete!"
EOF
chmod +x "${TARGET}/root/setup.sh"
# Execute the setup script in chroot
chimera-chroot "$TARGET" /root/setup.sh
# Clean up
rm "${TARGET}/root/setup.sh"
# ============================================================================
# Set admin user password
# ============================================================================
echo "==> Setting password for $ADMIN_USER..."
if [ -z "$ADMIN_PASSWORD" ]; then
echo "Please enter password for $ADMIN_USER:"
chimera-chroot "$TARGET" /usr/bin/passwd "$ADMIN_USER"
else
echo "$ADMIN_USER:$ADMIN_PASSWORD" | chimera-chroot "$TARGET" /usr/bin/chpasswd
fi
# ============================================================================
# Cleanup and unmount
# ============================================================================
echo "==> Syncing and unmounting..."
sync
umount "${TARGET}/boot"
zfs umount -a
zpool export "$POOL_NAME"
# ============================================================================
# Completion
# ============================================================================
echo ""
echo "=========================================="
echo "Installation complete!"
echo "=========================================="
echo ""
echo "You can now reboot into your new Chimera Linux system."
echo ""
echo "Administrator account: $ADMIN_USER"
echo " - Default shell: OSH"
echo " - Admin privileges: use 'doas' for system tasks"
echo ""
echo "Root login has been disabled for security."
echo ""
echo "After reboot, you'll see SDDM login and KDE Plasma desktop."
echo ""
echo "Reboot now? (y/n)"
read response
case "$response" in
[Yy]|[Yy][Ee][Ss])
reboot
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment