Skip to content

Instantly share code, notes, and snippets.

@xmawja
Last active May 3, 2025 19:00
Show Gist options
  • Save xmawja/da6a7ee664271631ae5cd4de0dc4f249 to your computer and use it in GitHub Desktop.
Save xmawja/da6a7ee664271631ae5cd4de0dc4f249 to your computer and use it in GitHub Desktop.
Gentoo BTRFS Installation Guide - How To Install Gentoo On BTRFS
#!/bin/sh
# Gentoo BTRFS Installation Guide
# First Step You Need to boot From Gentoo Live Cd
## reference https://gist.github.com/renich/90e0a5bed8c7c0de40d40ac9ccac6dfd
####################################################
# Partition Your Disks
# referenses https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Disks#Partitioning_the_disk_with_GPT_for_UEFI
# Print Partions That Attached TO Your System
lsblk
# Using fdisk Tool To Format Your Partition
# While Formating with cfdisk type x to enter advance mode and make lable for the disks
# <X> Refer To Disk Name That Attached To Your System
fdisk /dev/sd<X>
# After Oartitioninig Your disk
# Print That Partition
lsblk
## The Result Is Someting Like This
/dev/sd<X>1 = EFI
/dev/sd<X>2 = BOOT
/dev/sd<X>3 = SWAP
/dev/sd<X>4 = ROOT
# Create File Systems Format
# Format Your EFI partition
mkfs.vfat -F 32 -n EFI /dev/sd<X>1
# boot partion type ext4 because grub log not working with btrfs
mkfs -t ext4 -L BOOT /dev/sda<X>2
# Format Your swap Partition And Activated
mkswap -L SWAP /dev/sda<X>3
swapon /dev/sd<X>3
# Format Your BTRFS partition
mkfs -t btrfs -L ROOT /dev/sd<X>4
# mount Your TopVolume BTROOT Partition
mount /dev/sd<X>4 /mnt
# Create Your BTRFS Subvolume
cd /mnt
btrfs subvol create @
btrfs subvol create @home
btrfs subvol create @opt
btrfs subvol create @srv
btrfs subvol create @tmp
btrfs subvol create @usr
btrfs subvol create @var
btrfs subvol create @snapshots
btrfs subvol create @vms
# Print BTRFS subVolume
btrfs subvolume list /mnt
# unmount Your Partition
cd
umount -l /mnt
#!/bin/sh
# Gentoo BTRFS Installation Guide
# Second Steps Is To Install The System
## reference https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage
### reference https://wiki.gentoo.org/wiki/Btrfs/System_Root_Guide
### reference https://wiki.gentoo.org/wiki/Btrfs/Native_System_Root_Guide
###############################################
# mkdir gentoo directory to be mount on
mkdir /mnt/gentoo
# mount root
mount -o defaults,noatime,space_cache=v2,compress-force=zstd,autodefrag,subvol=@ /dev/sda4 /mnt/gentoo
# Create BOOT and other Directory to be mount on boot partion
# create desire directorys to be mountes as a SubVolume
mkdir -p /mnt/gentoo/{boot,home,opt,srv,tmp,usr,var,vms,.snapshots}
# mount other subvolumes
mount -o defaults,noatime,space_cache=v2,compress-force=zstd,autodefrag,subvol=@home /dev/sda4 /mnt/gentoo/home
mount -o defaults,noatime,space_cache=v2,compress-force=zstd,autodefrag,subvol=@opt /dev/sda4 /mnt/gentoo/opt
mount -o defaults,noatime,space_cache=v2,compress-force=zstd,autodefrag,subvol=@srv /dev/sda4 /mnt/gentoo/srv
mount -o defaults,noatime,space_cache=v2,compress-force=zstd,autodefrag,subvol=@tmp /dev/sda4 /mnt/gentoo/tmp
mount -o defaults,noatime,space_cache=v2,compress-force=zstd,autodefrag,subvol=@usr /dev/sda4 /mnt/gentoo/usr
mount -o defaults,noatime,space_cache=v2,compress-force=zstd,autodefrag,subvol=@var /dev/sda4 /mnt/gentoo/var
mount -o defaults,noatime,space_cache=v2,compress-force=zstd,autodefrag,subvol=@vms /dev/sda4 /mnt/gentoo/vms
mount -o defaults,noatime,space_cache=v2,compress-force=zstd,autodefrag,subvol=@snapshots /dev/sda4 /mnt/gentoo/.snapshots
# mount BOOT partition
mount -o defaults,relatime /dev/sd<X>2 /mnt/gentoo/boot
# Change Directory
cd /mnt/gentoo
# Download stag3 tarball
links https://www.gentoo.org/downloads/mirrors/
# Unpacking the stage3 tarball
tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner
#!/bin/sh
# Portage Make Configuration file
## reference https://wiki.gentoo.org/wiki//etc/portage/make.conf
## reference https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage#Configuring_compile_options
# Configure Portage Make File
nano -w /mnt/gentoo/etc/portage/make.conf
# Compiler flags to set for all languages
COMMON_FLAGS="-march=native -O2 -pipe"
# Use the same settings for both variables
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
QEMU_SOFTMMU_TARGETS="arm x86_64 sparc"
QEMU_USER_TARGETS="x86_64"
MAKEOPTS="-j4 -l4"
PORTAGE_NICENESS="1"
EMERGE_DEFAULT_OPTS="--jobs=4 --load-average=4 --with-bdeps y --complete-graph y"
FEATURES="candy fixlafiles unmerge-orphans parallel-install"
## (For mouse, keyboard, and Synaptics touchpad support)
INPUT_DEVICES="libinput"
## (For NVIDIA cards)
VIDEO_CARDS="nouveau"
## (For AMD/ATI cards)
VIDEO_CARDS="amdgpu radeonsi"
# Configure ACCEPT_KEYWORDS Packeges
ACCEPT_KEYWORDS="~amd64"
# Configure the ACCEPT_LICENSE variable
ACCEPT_LICENSE="-* @FREE"
# Grub Platforms
GRUB_PLATFORMS="efi-64"
# global USE flags
USE="dist-kernel wayland dbus elogind pipewire screencast jit lto vaapi verify-sig saveconfig -systemd -gnome -kde -xfce -cinnamon -mate -deepin -unity -budgie -consolekit"
# NOTE: This stage was built with the bindist Use flag enabled
# This sets the language of build output to English.
# Please keep this setting intact when reporting bugs.
LC_MESSAGES=C
#!/bin/sh
# Base Installation
## reference https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Base
#################################################
# Copy DNS info
cp --dereference /etc/resolv.conf /mnt/gentoo/etc/
# Mounting the necessary filesystems
mount --types proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/dev
mount --rbind /run /mnt/gentoo/run
mount --make-rslave /mnt/gentoo/run
# Entering the new environment
# chroot
#env -i HOME=@ TERM=linux chroot . bash -l
chroot /mnt/gentoo /bin/bash
# Source ENV
source /etc/profile
# Change Terminal PS1 Name
export PS1="(chroot) ${PS1}"
# make efi directory to be mounted
mkdir /boot/efi
# mount Your BOOT Partition
mount /dev/sd<X>1 /boot/efi
# Configuring Portage
emerge-webrsync
# Optional: Updating the Gentoo ebuild repository
emerge --sync
# UPDATING: Portage if nessesery
emerge --oneshot sys-apps/portage
# Choosing the right profile
eselect profile list
# Set The Right NUMBER of the Profile
eselect profile set NUMBER
# Updating the @world set FLAGS
emerge -auvDN @world
emerge --ask --verbose --update --deep --newuse @world
# TimeZone
# local timezone
ls /usr/share/zoneinfo
echo "Europe/Paris" > /etc/timezone
# provide time automatic based on local timezone above
emerge --config sys-libs/timezone-data
# Configure locales
nano -w /etc/locale.gen >>
en_US ISO-8859-1
en_US.UTF-8 UTF-8
fr_FR ISO-8859-1
fr_FR.UTF-8 UTF-8
ar_SA ISO-8859-1
ar_SA.UTF-8 UTF-8
# Generate Locale
locale-gen
# Locale selection
eselect locale list
# SET locate NUMBER
eselect locale set NUMBER
# UPDATE: env
env-update
# Source env Profile
source /etc/profile
# OPTION: change prompte
export PS1="(chroot) ${PS1}"
# Kernel configuration and compilation
## reference https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Kernel
#################################################
# Installing firmware and/or microcode
emerge -auv sys-kernel/linux-firmware
# Packages Accept Keywords
dispatch-conf
# fix The License Problem
echo "sys-kernel/linux-firmware linux-fw-redistributable no-source-code" | tee -a /etc/portage/package.license
echo "sys-kernel/linux-firmware @BINARY-REDISTRIBUTABLE" | tee -a /etc/portage/package.license
# Or edit package.license
nano -w /etc/portage/package.license >>
# Accepting both licenses for linux-firmware
sys-kernel/linux-firmware linux-fw-redistributable no-source-code
# Accepting any license that permits redistribution
sys-kernel/linux-firmware @BINARY-REDISTRIBUTABLE
## there are three way to configure gentoo kernel
# if you want to use pre compiled Bin Kernel
# choose one or other
# compiled config with some gentoo patches
emerge -auv sys-kernel/gentoo-kernel
# pre build kernel dont need to compile
emerge -av sys-kernel/gentoo-kernel-bin
# Manually rebuilding the initramfs
emerge -av @module-rebuild
# If any kernel modules (e.g. ZFS) are needed at early boot, rebuild the initramfs afterward via
emerge --config sys-kernel/gentoo-kernel
emerge --config sys-kernel/gentoo-kernel-bin
# for manual gentoo kernel configuration sources
emerge -auv sys-kernel/gentoo-sources
# List and Choose The Kernel
eselect kernel list
# select The Right NUMBER For you
eselect kernel set NUMBER
# View selected kernel
ls -l /usr/src/linux
# symlink the desire kernel if not linked MANUALY
ln -sf /usr/src/linux-6.0.8-gentoo /usr/src/linux
# Manual configuration
emerge -auv sys-apps/pciutils
# Move To Kernel DIrectory
cd /usr/src/linux
# SU and Open The Configuration
make menuconfig
# Kernel COnfiguration
## reference https://wiki.gentoo.org/wiki/Kernel/Gentoo_Kernel_Configuration_Guide
# SU and make modules And Generate BZimage image
make && make modules_install install
# SU and make install cfg
make install
# Kernel Command line
# add rootflags=subvol=root to your kernel cmdline
root=/dev/sda3 rootflags=subvol=@
root=/dev/sda3 rootflags=subvol=/
## TROBLESHOTING https://www.reddit.com/r/Gentoo/comments/yqcvmi/gentoo_stuck_on_loading_linux_51575gentoo/
## https://www.reddit.com/r/Gentoo/comments/q4wtal/grub_hangs_on_loading_initial_ramdisk/
## https://wiki.gentoo.org/wiki/Framebuffer#Early_framebuffer_drivers
#!/bin/sh
# Configuring The System
## reference https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/System
##################################################
# Print Filesystem Partition labels and UUIDs
blksid
# or by
lsblk -f
# Open And Edit fstab with Proper Guide Scheme
cd /mnt/gentoo/etc/fstab
nano -w /etc/fstab
# A full /etc/fstab example
## Adjust any formatting difference and additional partitions created from the Preparing the disks step
# or by UUID
# <file system> <mount point> <type> <options> <dump> <pass>
UUID=624sv-6326 /boot/efi vfat umask=0077 0 2
UUID=0073174b /boot ext4 defaults 1 2
UUID=828553f4 none swap sw 0 0
UUID=37da2701 / btrfs defaults,compress=zstd,space_cache=v2,subvol=@ 0 0
UUID=37da2701 /home btrfs defaults,compress=zstd,space_cache=v2,subvol=@home 0 0
UUID=37da2701 /opt btrfs defaults,compress=zstd,space_cache=v2,subvol=@opt 0 0
UUID=37da2701 /srv btrfs defaults,compress=zstd,space_cache=v2,subvol=@srv 0 0
UUID=37da2701 /tmp btrfs defaults,compress=zstd,space_cache=v2,subvol=@tmp 0 0
UUID=37da2701 /usr btrfs defaults,compress=zstd,space_cache=v2,subvol=@usr 0 0
UUID=37da2701 /var btrfs defaults,compress=zstd,space_cache=v2,subvol=@var 0 0
UUID=37da2701 /vms btrfs defaults,compress=zstd,space_cache=v2,subvol=@vms 0 0
UUID=37da2701 /.snapshots btrfs defaults,compress=zstd,space_cache=v2,subvol=@snapshots 0 0
##############################################################################################################
## Networking information
# Host and domain information
nano -w /etc/conf.d/hostname
# Set the hostname variable to the selected host name
hostname="Fossland"
# Check Network Adapter Device Name
ip a
# Put Your Device hostname
nano -w /etc/conf.d/net >>
hostname="Fossland"
## NETWORK
# DHCP via dhcpcd (any init system)
emerge --ask net-misc/dhcpcd
# To enable and then start the service on OpenRC systems:
rc-update add dhcpcd default
rc-service dhcpcd start
# netifrc (OpenRC)
emerge --ask --noreplace net-misc/netifrc
# Static IP definition
nano -w /etc/conf.d/net >>
config_eth0="192.168.0.2 netmask 255.255.255.0 brd 192.168.0.255"
routes_eth0="default via 192.168.0.1"
# DHCP definition
nano -w /etc/conf.d/net >>
# Put Your Network Device Name (ip a) result
config_eth0="dhcp"
# Automatically start networking at boot
cd /etc/init.d
# Link and Change eth0 with tour Network Device Name
ln -s net.lo net.eth0
# run network at boot
rc-update add net.eth0 default
# The hosts file
nano -w /etc/hosts >>
127.0.0.1 tux.homenetwork tux localhost
## System information
# Root password
passwd
# Init and boot configuration OpenRC
nano -w /etc/rc.conf
# edit keyboard layout
nano -w /etc/conf.d/keymaps
# edit hwclock option
nano -w /etc/conf.d/hwclock
#
## reference https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Tools
###################################################
# System logger
emerge --ask app-admin/sysklogd
# run on boot
rc-update add sysklogd default
# Optional: Cron daemon
emerge --ask sys-process/cronie
# RUN on boot
rc-update add cronie default
# init dcron
crontab /etc/crontab
# Optional: File indexing
emerge --ask sys-apps/mlocate
# Optional: RUN Remote access
rc-update add sshd default
# Filesystem Tools
emerge -auv sys-fs/e2fsprogs
emerge -auv sys-fs/dosfstools
emerge -auv sys-fs/btrfs-progs
# rootfstype=btrfs
## reference https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Bootloader
###############################################
## Configuring the bootloader
# Default: GRUB
emerge --ask --verbose sys-boot/grub
# grub install
grub-install --target=x86_64-efi --efi-directory=/boot/efi --removable
# grub COnfigurations
grub-mkconfig -o /boot/grub/grub.cfg
# Alternative: efibootmgr
emerge --ask sys-boot/efibootmgr
# Create Boot Location and copy bzimag to it
mkdir -p /boot/efi/boot
cp /boot/vmlinuz-* /boot/efi/boot/bootx64.efi
# tell gento where to compile bzimage
efibootmgr --create --disk /dev/sda --part 2 --label "Gentoo" --loader "\efi\boot\bootx64.efi"
# for BIN kernel with initramfs
#efibootmgr -c -d /dev/sda -p 2 -L "Gentoo" -l "\efi\boot\bootx64.efi" initrd='\initramfs-genkernel-amd64-5.15.52-gentoo root=/dev/sd<X>1 rootflags=subvol=root'
efibootmgr -c -d /dev/sda -p 1 -L "Gentoo" -l "\efi\boot\bootx64.efi" -u "initrd=\initramfs-5.15.52-gentoo.img root=/dev/sd<X>1 rootflags=subvol=root"
# if there is problems with the boot can delete by
# ENTERY-NUM = the boot entry number
efibootmgr -b ENTERY-NUM - B
# Rebooting the system
exit
cd
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -R /mnt/gentoo
reboot
## reference https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Finalizing
## User administration
# Adding a user for daily use
useradd -m -G users,wheel,audio -s /bin/bash xmawja
# Changing user password
passwd xmawja
# super user
emerge --ask app-admin/doas
# configuration
nano /etc/doas.conf >>
permit :wheel
# change permision
chown -c root:root /etc/doas.conf
chmod -c 0400 /etc/doas.conf
## Disk cleanup
# Removing tarballs
rm /stage3-*.tar.*
#!/bin/sh
## reference https://wiki.gentoo.org/wiki/Xorg
#######################################
# install x server and desire driver
emerge --ask x11-base/xorg-server
emerge --ask x11-base/xorg-drivers
## For Minimal X11 Setup just install below packages
emerge -auv x11-libs/libX11
emerge -auv x11-base/xorg-server
emerge -auv x11-libs/libXrandr
emerge -auv x11-libs/libXinerama
emerge -auv x11-libs/libXft
emerge -auv x11-apps/xinit
emerge -auv x11-apps/xrdb
emerge -auv x11-apps/mesa-progs
emerge -auv x11-apps/xrandr
emerge -auv x11-drivers/xf86-video-vboxvideo
emerge -auv x11-misc/unclutter
emerge -auv x11-misc/xclip
emerge -auv x11-misc/pcmanfm
# recomended apps for linux
# REFERENCE https://wiki.gentoo.org/wiki/Recommended_applications
#!/bin/sh
## reference https://wiki.gentoo.org/wiki/Wayland
## reference https://wiki.gentoo.org/wiki/Hyprland
## reference https://wiki.hyprland.org/Getting-Started/Installation/
#############################################
# install wayland
emerge -av dev-libs/wayland
# install eselect repository
emerge --ask app-eselect/eselect-repository
# create eselect repos directory
mkdir -p /etc/portage/repos.conf
# enable guru user overlays repos
eselect repository enable guru
# sync the repos
emerge --sync
# install hyprland window manager
emerge -av gui-wm/hyprland
# install SDDM display manager
emerge -av x11-misc/sddm
usermod -a -G video sddm
# enable display-manager for openrc user needed
emerge -av gui-libs/display-manager-init
rc-update add display-manager default
rc-update add elogind boot
# change the default displaymanager from xdm to sddm
nano -w /etc/conf.d/display-manager >>
CHECKVT=7
DISPLAYMANAGER="sddm"
# install kitty terminal
emerge -av x11-terms/kitty
## audio && and video configuration
emerge --ask media-sound/alsa-utils
rc-update add alsasound boot
# install and configure pipewire
emerge -av media-video/pipewire
emerge -av media-video/wireplumber
# if using external sound card
aplay -l
# and change the number of card with your desire slot number
# that output of aplay -l command
nano /etc/asound.conf >>
defaults.pcm.!card 0
defaults.pcm.!device 0
# install brave browser
# NOTE brave browser not available in gentoo source
# its available in gentoo overlay
eselect repository enable brave-overlay
emaint sync -r brave-overlay
emerge -av www-client/brave-bin
## NOTE ##
# this configuration recommendet to use with normal user not with the root user
# clone hyprland configuration
cd
git clone https://github.com/xmawja/dotfiles-wayland.git
cd dotfiles-wayland
mv * ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment