Skip to content

Instantly share code, notes, and snippets.

@MCMXCIII
Created January 22, 2024 12:06
Show Gist options
  • Save MCMXCIII/d53ed7844d5b0bbdbf18e2eafe6cf9c9 to your computer and use it in GitHub Desktop.
Save MCMXCIII/d53ed7844d5b0bbdbf18e2eafe6cf9c9 to your computer and use it in GitHub Desktop.
Exherbo Script.
#!/bin/bash
# Prompt for BIOS or UEFI booting
echo "Select the boot mode:"
echo "1. BIOS/Legacy booting"
echo "2. UEFI booting"
read -p "Enter the number (1 or 2): " boot_mode
# Validate user input
if [[ $boot_mode != "1" && $boot_mode != "2" ]]; then
echo "Invalid choice. Exiting."
exit 1
fi
# Prompt for disk selection
lsblk
read -p "Enter the disk to use (e.g., /dev/sda): " selected_disk
# Validate user input
if [[ ! -e $selected_disk ]]; then
echo "Invalid disk. Exiting."
exit 1
fi
# Prepare the hard disk
cfdisk $selected_disk
if [[ $boot_mode == "1" ]]; then
mkfs.ext2 "${selected_disk}1"
else
mkfs.vfat -F32 "${selected_disk}1"
fi
mkfs.ext4 "${selected_disk}2"
mkfs.ext4 "${selected_disk}3"
mkdir /mnt/exherbo && mount "${selected_disk}2" /mnt/exherbo && cd /mnt/exherbo
curl -O https://stages.exherbolinux.org/x86_64-pc-linux-gnu/exherbo-x86_64-pc-linux-gnu-gcc-current.tar.xz
curl -O https://stages.exherbolinux.org/x86_64-pc-linux-gnu/exherbo-x86_64-pc-linux-gnu-gcc-current.tar.xz.sha256sum
sha256sum -c exherbo-x86_64-pc-linux-gnu-current.tar.xz.sha256sum
tar xJpf exherbo*xz
cat <<EOF > /mnt/exherbo/etc/fstab
${selected_disk}2 / ext4 defaults 0 0
${selected_disk}3 /home ext4 defaults 0 2
EOF
if [[ $boot_mode == "1" ]]; then
echo "${selected_disk}1 /boot ext2 defaults 0 0" >> /mnt/exherbo/etc/fstab
else
echo "${selected_disk}1 /boot vfat defaults 0 0" >> /mnt/exherbo/etc/fstab
fi
# Chroot into the system
mount -o rbind /dev /mnt/exherbo/dev/
mount -o rbind /sys /mnt/exherbo/sys/
mount -t proc none /mnt/exherbo/proc/
mount "$selected_disk"1 /mnt/exherbo/boot/
mount "$selected_disk"3 /mnt/exherbo/home/
cp /etc/resolv.conf /mnt/exherbo/etc/resolv.conf
env -i TERM=$TERM SHELL=/bin/bash HOME=$HOME $(which chroot) /mnt/exherbo /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"
# Update the install
cd /etc/paludis && vim bashrc && vim *conf
cave sync
# Make it bootable
# Download and extract the latest stable kernel from The Linux Kernel Archives.
# Install the kernel
# Clone the stable kernel on Linux and navigate to it
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux /kernel
cd /kernel
# Switch to the desired kernel version (6.6.8 in this case)
git checkout tags/v6.6.8
# Configure the kernel
make nconfig
# Compile kernel to arch/x86/boot/bzImage
make
# Install kernel modules
make modules_install
# For BIOS/Legacy booting using GRUB 2
grub-install $selected_disk
cat <<EOF > /boot/grub/grub.cfg
set timeout=10
set default=0
menuentry "Exherbo" {
set root=(${selected_disk}1)
linux /kernel root=${selected_disk}2
}
EOF
# OR
if [[ $boot_mode == "2" ]]; then
grub-mkconfig -o /boot/grub/grub.cfg
fi
# For UEFI booting using systemd-boot
if [[ $boot_mode == "2" ]]; then
bootctl install
# Assuming kernel copy and systemd-boot configuration steps here
fi
# Configure hostname and hosts file
read -p "Enter the hostname: " user_hostname
cat <<EOF > /etc/hostname
$user_hostname
EOF
read -p "Enter the domain (e.g., domain.foo): " user_domain
cat <<EOF > /etc/hosts
127.0.0.1 ${user_hostname}.${user_domain} ${user_hostname} localhost
::1 localhost
EOF
# Install Linux firmware files if needed
cave resolve linux-firmware
# Set root password
passwd
# Install additional locales if needed
# Example locales: en_US.UTF-8 and ru_RU.UTF-8
localedef -i en_US -f ISO-8859-1 en_US
localedef -i ru_RU -f UTF-8 ru_RU.UTF-8
# Change system timezone to Berlin
ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime
# Reboot
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment