Created
September 23, 2023 21:39
-
-
Save MCMXCIII/428da21580e1c8fa982806126fce7266 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Function to mount necessary filesystems | |
mount_filesystems() { | |
mount -o rbind /dev /mnt/exherbo/dev/ | |
mount -o rbind /sys /mnt/exherbo/sys/ | |
mount -t proc none /mnt/exherbo/proc/ | |
mount /dev/sda1 /mnt/exherbo/boot/ | |
mount /dev/sda3 /mnt/exherbo/home/ | |
cp /etc/resolv.conf /mnt/exherbo/etc/resolv.conf | |
} | |
# Function to chroot into the system | |
chroot_system() { | |
env -i TERM=$TERM SHELL=/bin/bash HOME=$HOME $(which chroot) /mnt/exherbo /bin/bash | |
source /etc/profile | |
export PS1="(chroot) $PS1" | |
} | |
# Prepare the hard disk | |
if [[ -d /sys/firmware/efi ]]; then | |
# Using UEFI booting | |
cfdisk /dev/sda | |
mkfs.vfat -F32 /dev/sda1 | |
else | |
# Using BIOS/Legacy booting | |
cfdisk /dev/sda | |
mkfs.ext2 /dev/sda1 | |
fi | |
mkfs.ext4 /dev/sda2 | |
mkfs.ext4 /dev/sda3 | |
mkdir /mnt/exherbo && mount /dev/sda2 /mnt/exherbo && cd /mnt/exherbo | |
# Download and extract the Exherbo stage | |
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 | |
# Update fstab | |
cat <<EOF > /mnt/exherbo/etc/fstab | |
/dev/sda2 / ext4 defaults 0 0 | |
/dev/sda3 /home ext4 defaults 0 2 | |
EOF | |
if [[ -d /sys/firmware/efi ]]; then | |
# Using UEFI booting | |
echo "/dev/sda1 /boot vfat defaults 0 0" >> /mnt/exherbo/etc/fstab | |
else | |
# Using BIOS/Legacy booting | |
echo "/dev/sda1 /boot ext2 defaults 0 0" >> /mnt/exherbo/etc/fstab | |
fi | |
# Chroot into the system | |
mount_filesystems | |
chroot_system | |
# Update the install | |
cd /etc/paludis | |
# Make sure Paludis is configured correctly | |
vim bashrc && vim *conf | |
# Sync all the trees | |
cave sync | |
# Make it bootable | |
# Download and extract the latest stable kernel from The Linux Kernel Archives. | |
# Install the kernel (replace 'path-to-kernel' with the actual path) | |
cd path-to-kernel | |
make nconfig | |
make | |
make modules_install | |
cp arch/x86/boot/bzImage /boot/kernel | |
# Install an init system (systemd is used here) | |
cave resolve world -c | |
cave resolve --execute --preserve-world --skip-phase test sys-apps/systemd | |
# For BIOS/Legacy booting, using GRUB 2 | |
grub-install /dev/sda | |
# Configure GRUB 2 | |
cat <<EOF > /boot/grub/grub.cfg | |
set timeout=10 | |
set default=0 | |
menuentry "Exherbo" { | |
set root=(hd0,1) | |
linux /kernel root=/dev/sda2 | |
} | |
EOF | |
# For UEFI booting, using systemd-boot and kernel-install | |
bootctl install | |
# Copy the kernel you just installed into the appropriate directory | |
kernel-install add kernel-version /boot/vmlinuz-kernel-version | |
# Configure hostname | |
cat <<EOF > /etc/hostname | |
my-hostname | |
EOF | |
# Ensure hostname mapping in /etc/hosts | |
cat <<EOF > /etc/hosts | |
127.0.0.1 my-hostname.domain.foo my-hostname localhost | |
::1 localhost | |
EOF | |
# Install Linux firmware files (if needed) | |
cave resolve linux-firmware | |
# Set root password | |
passwd | |
# Install additional locales if needed | |
localedef -i en_US -f ISO-8859-1 en_US | |
localedef -i ru_RU -f UTF-8 ru_RU.UTF-8 | |
# Change system-wide locale if needed | |
echo LANG="en_US.UTF-8" > /etc/env.d/99locale | |
# Set system timezone (e.g., Copenhagen, Denmark) | |
ln -s /usr/share/zoneinfo/Europe/Copenhagen /etc/localtime | |
# Reboot | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment