Skip to content

Instantly share code, notes, and snippets.

@DanielFeichtinger
Last active October 15, 2025 19:47
Show Gist options
  • Save DanielFeichtinger/66471547842000a917541f27a9db5616 to your computer and use it in GitHub Desktop.
Save DanielFeichtinger/66471547842000a917541f27a9db5616 to your computer and use it in GitHub Desktop.
Xfce on Chimera
#!/bin/sh
#
# Chimera Linux Minimal Installation Script
# Target: ZFS root filesystem with Xfce 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"
BOOT_PART="2"
POOL_PART="3"
# For SATA/SCSI disks (e.g., /dev/sda)
EFI_DEVICE="${DISK}${EFI_PART}"
BOOT_DEVICE="${DISK}${BOOT_PART}"
POOL_DEVICE="${DISK}${POOL_PART}"
# For NVMe disks (e.g., /dev/nvme0n1), uncomment these instead:
# EFI_DEVICE="${DISK}p${EFI_PART}"
# BOOT_DEVICE="${DISK}p${BOOT_PART}"
# POOL_DEVICE="${DISK}p${POOL_PART}"
# ZFS pool name
POOL_NAME="zroot"
# System hostname
HOSTNAME="chimera-vm"
# Root password (will prompt if not set)
ROOT_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/efi" 2>/dev/null; then
umount "${TARGET}/boot/efi" || true
fi
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 "$part" 2>/dev/null || true
fi
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 (512MB)
sgdisk -n "${EFI_PART}:1m:+512m" -t "${EFI_PART}:ef00" "$DISK"
# Create /boot partition (1GB, ext4)
sgdisk -n "${BOOT_PART}:0:+1024m" -t "${BOOT_PART}:8300" "$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 "==> Creating /boot filesystem..."
mkfs.ext4 -F "$BOOT_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 and boot partitions
# ============================================================================
echo "==> Mounting /boot and EFI partitions..."
mkdir -p "${TARGET}/boot"
mount "$BOOT_DEVICE" "${TARGET}/boot"
mkdir -p "${TARGET}/boot/efi"
mount "$EFI_DEVICE" "${TARGET}/boot/efi"
# ============================================================================
# Install base system
# ============================================================================
echo "==> Installing base system..."
chimera-bootstrap -l "${TARGET}" base-full
# ============================================================================
# Chroot configuration
# ============================================================================
echo "==> Configuring system (chroot)..."
# Get UUIDs before chroot
EFI_UUID=$(blkid -s UUID -o value "$EFI_DEVICE")
BOOT_UUID=$(blkid -s UUID -o value "$BOOT_DEVICE")
# 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 kernel and ZFS..."
apk add linux-lts linux-lts-zfs-bin
echo "==> Installing bootloader..."
apk add grub-x86_64-efi efibootmgr
echo "==> Installing Xfce and desktop components..."
apk add xfce4 xserver-xorg gdm dbus elogind
echo "==> Installing basic utilities..."
apk add nano network-manager-applet firefox
echo "==> Generating initramfs..."
update-initramfs -c -k all
echo "==> Installing GRUB..."
grub-install --target=x86_64-efi --efi-directory=/boot/efi --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 "==> Configuring fstab..."
echo 'UUID=$BOOT_UUID /boot ext4 defaults 0 1' >> /etc/fstab
echo 'UUID=$EFI_UUID /boot/efi vfat defaults 0 2' >> /etc/fstab
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 root password
# ============================================================================
echo "==> Setting root password..."
if [ -z "$ROOT_PASSWORD" ]; then
echo "Please enter root password:"
chimera-chroot "$TARGET" /usr/bin/passwd root
else
echo "root:$ROOT_PASSWORD" | chimera-chroot "$TARGET" /usr/bin/chpasswd
fi
# ============================================================================
# Cleanup and unmount
# ============================================================================
echo "==> Syncing and unmounting..."
sync
umount "${TARGET}/boot/efi"
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 "Default login: root / (password you set)"
echo ""
echo "After first boot:"
echo " - GDM will start automatically"
echo " - Select Xfce session from session menu"
echo " - Create a regular user:"
echo " useradd -m -G wheel -s /bin/bash username"
echo " passwd username"
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