#!/bin/bash # Exit on error set -e # Variables DISK="/dev/sda" CHROOT_DIR="/mnt/gentoo" # Partition the disk parted -s $DISK mklabel gpt parted -s $DISK mkpart primary 1MiB 3MiB parted -s $DISK mkpart primary 3MiB 131MiB parted -s $DISK mkpart primary 131MiB 100% # Format the partitions mkfs.fat -F32 ${DISK}1 mkfs.ext4 ${DISK}2 mkfs.ext4 ${DISK}3 # Mount the partitions mount ${DISK}3 $CHROOT_DIR mkdir -p $CHROOT_DIR/boot mount ${DISK}2 $CHROOT_DIR/boot # Download and extract the stage3 tarball cd $CHROOT_DIR wget http://distfiles.gentoo.org/releases/amd64/autobuilds/current-stage3-amd64/stage3-amd64-*.tar.xz tar xpvf stage3-amd64-*.tar.xz --xattrs-include='*.*' --numeric-owner # Configure make.conf cat < $CHROOT_DIR/etc/portage/make.conf COMMON_FLAGS="-march=native -O2 -pipe" CFLAGS="\${COMMON_FLAGS}" CXXFLAGS="\${COMMON_FLAGS}" FCFLAGS="\${COMMON_FLAGS}" FFLAGS="\${COMMON_FLAGS}" MAKEOPTS="-j$(nproc)" EOF # Copy DNS info cp -L /etc/resolv.conf $CHROOT_DIR/etc/ # Mount necessary filesystems mount -t proc /proc $CHROOT_DIR/proc mount --rbind /sys $CHROOT_DIR/sys mount --make-rslave $CHROOT_DIR/sys mount --rbind /dev $CHROOT_DIR/dev mount --make-rslave $CHROOT_DIR/dev # Chroot into the new environment chroot $CHROOT_DIR /bin/bash <<'EOF' source /etc/profile export PS1="(chroot) $PS1" # Install the Gentoo base system emerge-webrsync emerge --sync emerge gentoo-sources emerge genkernel genkernel all # Install necessary packages emerge syslog-ng dhcpcd # Install Wayland and KDE emerge wayland plasma-meta kde-apps/kdecore-meta # Set the root password echo "root:password" | chpasswd # Configure fstab cat < /etc/fstab /dev/sda2 /boot ext4 defaults,noatime 0 2 /dev/sda3 / ext4 defaults,noatime 0 1 /dev/sda1 /boot/efi vfat defaults,noatime 0 2 EOL # Install and configure GRUB emerge grub grub-install --target=x86_64-efi --efi-directory=/boot grub-mkconfig -o /boot/grub/grub.cfg # Exit chroot exit EOF # Unmount filesystems umount -l $CHROOT_DIR/dev{/shm,/pts,} umount -R $CHROOT_DIR echo "Gentoo installation is complete. Please reboot."