View previous topic :: View next topic |
Author |
Message |
escfrpls n00b

Joined: 14 Feb 2025 Posts: 6
|
Posted: Fri Mar 21, 2025 2:41 pm Post subject: Installing Gentoo use a bash script? |
|
|
Hey, everybody!
Guys, I have a strange desire to make an installation of Gentoo for myself, installation bash script, booting from the boot drive (example ubuntu, arch, it does not matter).
I sat for a while and wrote a script, but I'm not sure if I did it right , can you point out the mistakes to me?
Yes, I plan to test it some more on a VM before using it on a install PC, but if you don't mind, can you email me where my errors are?
Thx!
Code: |
#!/bin/bash
exec > >(tee /var/log/gentoo_install.log) 2>&1
set -e
# --------------------------
# System Configuration
# --------------------------
DISK="/dev/ddrivename"
BOOT_PART="${DISK}p1"
ROOT_PART="${DISK}p2"
SWAP_PART="${DISK}p3"
HOSTNAME="gentoo"
USERNAME="username"
TIMEZONE="Europe/City"
# --------------------------
# Password Input
# --------------------------
read -sp "Enter root password: " ROOT_PASS
echo
read -sp "Enter password for $USERNAME: " USER_PASS
echo
# --------------------------
# Disk Preparation
# --------------------------
wipefs -af $DISK
parted -s $DISK mklabel gpt
parted -s $DISK mkpart primary fat32 1MiB 513MiB
parted -s $DISK set 1 esp on
parted -s $DISK mkpart primary ext4 513MiB -32GiB
parted -s $DISK mkpart primary linux-swap -32GiB 100%
# --------------------------
# Creating Filesystems
# --------------------------
mkfs.fat -F 32 -n BOOT $BOOT_PART
mkfs.ext4 -L GENTOO -F $ROOT_PART
mkswap -L SWAP $SWAP_PART
swapon $SWAP_PART
# --------------------------
# Mounting Partitions
# --------------------------
mount $ROOT_PART /mnt/gentoo
mkdir -p /mnt/gentoo/boot
mount $BOOT_PART /mnt/gentoo/boot
# --------------------------
# Download and Extract Stage3 Tarball
# --------------------------
STAGE3_URL=$(curl -s https://distfiles.gentoo.org/releases/amd64/autobuilds/latest-stage3-amd64-openrc.txt | grep -o 'https://.*stage3.*tar.xz')
echo "Downloading stage3: $STAGE3_URL"
wget "$STAGE3_URL" -O /mnt/gentoo/stage3.tar.xz
# If integrity check causes issues, it is omitted:
# wget "${STAGE3_URL}.CONTENTS" -O /mnt/gentoo/stage3.CONTENTS
# echo "Verifying stage3 integrity..."
# tar tvf /mnt/gentoo/stage3.tar.xz | awk '{print $6}' > /mnt/gentoo/stage3.LIST
# if ! diff -q /mnt/gentoo/stage3.CONTENTS /mnt/gentoo/stage3.LIST; then
# echo "Stage3 integrity check failed!"
# exit 1
# fi
echo "Extracting stage3..."
tar xpvf /mnt/gentoo/stage3.tar.xz --xattrs-include='*.*' --numeric-owner -C /mnt/gentoo
# --------------------------
# Set root password in chroot environment
# --------------------------
echo "Setting root password..."
echo "root:$ROOT_PASS" | chroot /mnt/gentoo chpasswd
unset ROOT_PASS
# --------------------------
# Create necessary directories
# --------------------------
mkdir -p /mnt/gentoo/etc/portage
mkdir -p /mnt/gentoo/etc/env.d
mkdir -p /mnt/gentoo/etc/X11/xorg.conf.d
# --------------------------
# Configure make.conf
# --------------------------
CPU_FLAGS=$(chroot /mnt/gentoo cpuid2cpuflags | cut -d: -f2)
cat <<EOF > /mnt/gentoo/etc/portage/make.conf
COMMON_FLAGS="-march=znver4 -O2 -pipe"
CFLAGS="\${COMMON_FLAGS}"
CXXFLAGS="\${COMMON_FLAGS}"
MAKEOPTS="-j\$(nproc)"
ACCEPT_KEYWORDS="amd64"
CPU_FLAGS_X86="$CPU_FLAGS"
USE="
X
acpi
alsa
bluetooth
imagemagick
lm-sensors
multilib
networkmanager
pulseaudio
vaapi
vdpau
vulkan
xinerama
xvmc
-geoip
-geolocate
-gnome
-kde
-nvidia
-plasma
-systemd
-telemetry
-wayland
"
VIDEO_CARDS="amdgpu radeonsi"
INPUT_DEVICES="libinput evdev"
LINGUAS="en"
L10N="en"
GENTOO_MIRRORS="https://gentoo.mirror.gda.cloud.ovh.net/ http://ftp.icm.edu.pl/pub/Linux/gentoo/"
FEATURES="parallel-fetch parallel-install"
EOF
# --------------------------
# Kernel Configuration and Firmware Installation
# --------------------------
chroot /mnt/gentoo emerge -q sys-kernel/gentoo-sources linux-firmware
KERNEL_EXTRA='
CONFIG_HID_SONY=y
CONFIG_HID_XBOX=y
CONFIG_HID_PLAYSTATION=y
CONFIG_SND_USB_AUDIO=y
CONFIG_DRM_AMDGPU=y
CONFIG_IA32_EMULATION=y
CONFIG_EXT4_FS_POSIX_ACL=y
CONFIG_R8169=y
CONFIG_R8169_VLAN=y
CONFIG_R8169_NAPI=y
'
echo "$KERNEL_EXTRA" > /mnt/gentoo/usr/src/linux/.config
# --------------------------
# Build and Install Kernel
# --------------------------
chroot /mnt/gentoo /bin/bash <<EOF
cd /usr/src/linux
make olddefconfig
make -j\$(nproc) && make modules_install
make install
EOF
# --------------------------
# Add Guru overlay and sync repositories
# --------------------------
chroot /mnt/gentoo emerge -q app-eselect/eselect-repository
chroot /mnt/gentoo eselect repository enable guru
chroot /mnt/gentoo emerge --sync
# --------------------------
# Install Essential Packages
# --------------------------
chroot /mnt/gentoo emerge -q \
sys-apps/dbus \
sys-devel/gcc \
x11-base/xorg-server \
media-libs/mesa \
media-libs/vulkan-loader \
x11-wm/i3 \
x11-misc/dmenu \
app-admin/doas \
media-sound/pulseaudio \
net-wireless/bluez \
games-emulation/xboxdrv \
media-video/vlc \
app-admin/htop \
media-libs/alsa-lib \
media-sound/alsa-utils \
media-plugins/alsa-plugins \
www-client/firefox \
x11-misc/pcmanfm \
app-editors/vim \
x11-terms/st \
app-shells/zsh \
app-shells/zsh-completion \
net-misc/networkmanager \
net-im/signal-desktop-bin \
net-im/discord-bin \
games-util/steam-launcher \
sys-boot/grub \
efibootmgr
# --------------------------
# System Cleanup
# --------------------------
chroot /mnt/gentoo emerge -q @preserved-rebuild
chroot /mnt/gentoo emerge --depclean
# --------------------------
# Network Configuration
# --------------------------
chroot /mnt/gentoo rc-update add NetworkManager default
# --------------------------
# Create User and Set Password
# --------------------------
chroot /mnt/gentoo useradd -m -G wheel,audio,video,input,plugdev,portage,network $USERNAME
echo "$USERNAME:$USER_PASS" | chroot /mnt/gentoo chpasswd
unset USER_PASS
# --------------------------
# Configure doas and set default shell
# --------------------------
echo "permit persist :wheel" > /mnt/gentoo/etc/doas.conf
chroot /mnt/gentoo eselect shell set /bin/zsh
chroot /mnt/gentoo usermod -s /bin/zsh root
chroot /mnt/gentoo usermod -s /bin/zsh $USERNAME
# --------------------------
# Setup Zsh for the User
# --------------------------
cat <<EOF > /mnt/gentoo/home/$USERNAME/.zshrc
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
autoload -Uz compinit
compinit
PROMPT='%F{blue}%n@%m%f %F{green}%~%f %# '
EOF
chroot /mnt/gentoo chown $USERNAME:$USERNAME /home/$USERNAME/.zshrc
# --------------------------
# Setup i3 window manager configuration
# --------------------------
mkdir -p /mnt/gentoo/home/$USERNAME/.config/i3
mkdir -p /mnt/gentoo/home/$USERNAME/.config/i3status
wget https://github.com/escfrpls/i3-config/raw/main/config -O /mnt/gentoo/home/$USERNAME/.config/i3/config
wget https://github.com/escfrpls/i3-config/raw/main/i3status.conf -O /mnt/gentoo/home/$USERNAME/.config/i3status/config
echo -e "\n# Set st as default terminal\nbindsym \$mod+Return exec st" >> /mnt/gentoo/home/$USERNAME/.config/i3/config
chroot /mnt/gentoo chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
# --------------------------
# Configure DisplayPort for X11
# --------------------------
cat <<EOF > /mnt/gentoo/etc/X11/xorg.conf.d/10-monitor.conf
Section "Monitor"
Identifier "DP-0"
Modeline "3440x1440_165" 791.50 3440 3696 4064 4688 1440 1443 1453 1527 +hsync -vsync
Option "PreferredMode" "3440x1440_165"
EndSection
Section "Device"
Identifier "AMDGPU"
Driver "amdgpu"
Option "VariableRefresh" "true"
EndSection
EOF
# --------------------------
# Localization and Timezone Configuration
# --------------------------
chroot /mnt/gentoo ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
echo "en_US.UTF-8 UTF-8" > /mnt/gentoo/etc/locale.gen
chroot /mnt/gentoo locale-gen
echo "LANG=en_US.UTF-8" > /mnt/gentoo/etc/env.d/02locale
# --------------------------
# Install GRUB Bootloader
# --------------------------
chroot /mnt/gentoo grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Gentoo
chroot /mnt/gentoo grub-mkconfig -o /boot/grub/grub.cfg
# --------------------------
# Final Message
# --------------------------
echo "Installation complete! After reboot:"
echo "1. Log in as $USERNAME"
echo "2. Start networking: doas rc-service NetworkManager start"
echo "3. Verify display: xrandr --output DP-0 --mode 3440x1440 --rate 165"
|
|
|
Back to top |
|
 |
NeddySeagoon Administrator


Joined: 05 Jul 2003 Posts: 55185 Location: 56N 3W
|
Posted: Fri Mar 21, 2025 3:37 pm Post subject: |
|
|
escfrpls,
Welcome to Gentoo.
There is a serious lack of error checking/handling.
Code: | # --------------------------
# Password Input
# --------------------------
read -sp "Enter root password: " ROOT_PASS
echo
read -sp "Enter password for $USERNAME: " USER_PASS
echo |
Require the passwords to be entered twice and compare the entries.
Code: | # --------------------------
# Disk Preparation
# --------------------------
wipefs -af $DISK |
That will ruin you whole day if the disk is fat fingered.
Code: | STAGE3_URL=$(curl -s https://distfiles.gentoo.org/releases/amd64/autobuilds/latest-stage3-amd64-openrc.txt ... | but I'm installing on arm64 ...
OK that' out of scope :)
I understand we have a few systemd users too :)
Code: | echo "Extracting stage3..."
tar xpvf /mnt/gentoo/stage3.tar.xz --xattrs-include='*.*' --numeric-owner -C /mnt/gentoo |
Do you really need the -v option?
It only slows things down.
Code: | COMMON_FLAGS="-march=znver4 -O2 -pipe" | That's not generally applicable. I have a zen3, others have Intel CPUs
Build and run Code: | app-misc/resolve-march-native | and use whatever that spits out.
You do that already for cpuid2cpuflags, I think.
Code: | CONFIG_DRM_AMDGPU=y | make that a module or include the firmware into the kernel binary.
Not everyone will have an AMD GPU.
Where do you set the profile?
latest-stage3-amd64-openrc.txt has a profile set but is it correct?
USE
are included in a desktop profile.
USE
Chose the right profile and get these for free.
Over my dead body
Code: | net-im/signal-desktop-bin \
net-im/discord-bin \ |
Some of the packages you emerge should not be listed in the world set. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
 |
escfrpls n00b

Joined: 14 Feb 2025 Posts: 6
|
Posted: Fri Mar 21, 2025 4:38 pm Post subject: |
|
|
NeddySeagoon wrote: | make that a module or include the firmware into the kernel binary.
Not everyone will have an AMD GPU. |
Oh yeah, I use, my processor 7900xtx and my video card is from 7900xtx.
NeddySeagoon wrote: | but I'm installing on arm64 ...
OK that' out of scope
I understand we have a few systemd users too |
Mmm, I don't get it. I don't want to use the system, so I have to choose arm64?
NeddySeagoon wrote: | latest-stage3-amd64-openrc.txt has a profile set but is it correct? |
That's right, my typo.
[quote="NeddySeagoon"]net-im/signal-desktop-bin \
net-im/discord-bin \ /quote]
It's not critical, you don't have to install it hehe
thanks for the tips! |
|
Back to top |
|
 |
zen_desu Apprentice

Joined: 25 Oct 2024 Posts: 248
|
Posted: Fri Mar 21, 2025 4:45 pm Post subject: |
|
|
I think you could distill the script down into essential steps, and add a few variables, maybe for things like architecture type or compiler options, that way the script does more than install your exact preferences. _________________ µgRD dev
Wiki writer |
|
Back to top |
|
 |
NeddySeagoon Administrator


Joined: 05 Jul 2003 Posts: 55185 Location: 56N 3W
|
Posted: Fri Mar 21, 2025 7:26 pm Post subject: |
|
|
escfrpls,
Gentoo supports many different architectures.
Your script hard codes amd64 with openrc on zen4. That will be a small subset of Gentoo installs.
amd64 is correct for you.
I have amd64 and arm64 here.
I was trying to get across that your script would be more generally useful if the user could choose the CPU architecture, openrc/systemd and profile.
zen_desu provided further hints.
AMDGPU cannot work without its firmware.
The firmware must be available when the module is initialised.
If you set AMDGPU=y, thats before the root filesystem is mounted, so the firmware must be included in the kernel binary.
When AMDGPU=m, the firmware can be read from /lib/firmware and AMDGPU will help itself to the right firmware.
The kernel will become huge trying to cater to different GPUs, even just AMD GPUs.
As it stands, your script may work in a VM, as it won't use AMDGPU but all you will get on real hardware is a blank console.
At least, it will be blank after AMDGPU starts with no firmware. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
 |
escfrpls n00b

Joined: 14 Feb 2025 Posts: 6
|
Posted: Fri Mar 21, 2025 7:46 pm Post subject: |
|
|
Thanks for the advice, the topic can be closed.
Probably you are right, it will be easier for me to install the base system and then automate the installation with a script (everything else) - it will be faster and easier.
Thanks again for the advice! |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|