Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shizonic/e0d5bcaddef1594fe16be6afe29c8611 to your computer and use it in GitHub Desktop.
Save shizonic/e0d5bcaddef1594fe16be6afe29c8611 to your computer and use it in GitHub Desktop.
Install Gentoo Desktop into BtrFS subvolumes
#!/usr/bin/env bash
# WARNING!!
# This will obliterate all the data in your partition!! (not actually true, but act as if it was)
# Do NOT execute this script if you don't fully understand it!
# a few vars
amount_of_swap=$( free --si -g | grep Mem: | gawk '{ print $2 + 1}' )
# create partitions
# I would add your amount of RAM + something (1 GB maybe?) to the swap partition (#3) instead of 9.
sgdisk -Z /dev/sda
sgdisk -o /dev/sda
sgdisk -n 1::+8M -t 1:ef02 /dev/sda
sgdisk -n 2::+1G -t 2:8300 /dev/sda
sgdisk -n 3::+${amount_of_swap}G -t 3:8200 /dev/sda
sgdisk -n 4:: -t 4:8300 /dev/sda
# create filesystems
mkfs -t btrfs -L boot /dev/sda2
mkfs -t btrfs -L btrfsroot /dev/sda4
mkswap /dev/sda3
# create subvols
mkdir /mnt/gentoo
mount /dev/sda4 /mnt/gentoo
cd /mnt/gentoo
btrfs subvol create root
btrfs subvol create home
btrfs subvol create srv
btrfs subvol create var
# unmount
cd ..
umount gentoo
#!/usr/bin/env bash
# This is a recipe; not a script. You should try to run it chunk by chunck.
# The shebang is only for syntax highlighting
# Chroot
## Please, run this right after running script 00
mount -o defaults,noatime,compress=lzo,autodefrag,subvol=root /dev/sda4 /mnt/gentoo
## create dirs for mounts
cd /mnt/gentoo
mkdir srv home root var boot
## mount
mount -o defaults,noatime,compress=lzo,autodefrag,subvol=home /dev/sda4 /mnt/gentoo/home
mount -o defaults,noatime,compress=lzo,autodefrag,subvol=srv /dev/sda4 /mnt/gentoo/srv
mount -o defaults,noatime,compress=lzo,autodefrag,subvol=var /dev/sda4 /mnt/gentoo/var
mount -o defaults,noatime /dev/sda2 /mnt/gentoo/boot
## get gentoo stage3
curl -O http://distfiles.gentoo.org/releases/amd64/autobuilds/current-stage3-amd64-systemd/stage3-amd64-systemd-20180103.tar.bz2
## uncompress
tar -xapf stage3-amd64-systemd-20180103.tar.bz2
rm -f stage3-amd64-systemd-20180103.tar.bz2
## mount proc, sys and dev
mount -t proc none proc
mount --rbind /sys sys
mount --rbind /dev dev
## activate swap
swapon /dev/sda3
## get dns
cp -u /etc/resolv.conf /mnt/gentoo/etc/
## chroot
env -i HOME=/root TERM=$TERM chroot . bash -l
## mtab
cat /proc/mounts > /etc/mtab
## emerge
emaint -A sync
emerge --oneshot portage
## environment
source /etc/profile
export PS1="(chroot) $PS1"
# Setup
cat << 'EOF' > /etc/fstab
# <fs> <mountpoint> <type> <opts> <dump/pass>
shm /dev/shm tmpfs nodev,nosuid,noexec 0 0
/dev/sda4 / btrfs rw,noatime,compress=lzo,autodefrag,subvol=root 0 0
/dev/sda4 /home btrfs rw,noatime,compress=lzo,autodefrag,subvol=home 0 0
/dev/sda4 /srv btrfs rw,noatime,compress=lzo,autodefrag,subvol=srv 0 0
/dev/sda4 /var btrfs rw,noatime,compress=lzo,autodefrag,subvol=var 0 0
/dev/sda3 none swap sw 0 0
/dev/sda2 /boot btrfs rw,noatime 0 0
EOF
## local time in MX
ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime
## add cpu flags
emerge app-portage/cpuid2cpuflags
cpu_flags=$( cpuid2cpuflags )
## append to my make.conf
use_remove='-accessibility -altivec -apache2 -aqua -big-endian -bindist -boundschecking -bsf -canna -clamav -connman -coreaudio -custom-cflags -debug -dedicated -emacs -handbook -ibm -infiniband -iwmmxt -kde -kontact -libav -libedit -libressl -libsamplerate -mono -mule -neon -oci8 -oci8-instant-client -oracle -oss -pch -pcmcia -plasma -qmail-spp -qt4 -qt5 -static -syslog -sysvipc -tcpd -xemacs -yahoo -zsh-completion'
use_add='symlink unicode vim-syntax'
make_opts="-j$(( 1 + 1 + $( lscpu -p | tail -n 1 | cut -d ',' -f 1 ) ))"
cat << EOF > /etc/portage/make.conf
CFLAGS="-mtune=native -O2 -pipe"
CXXFLAGS=\${CFLAGS}
CHOST="x86_64-pc-linux-gnu"
ACCEPT_KEYWORDS="~amd64"
MAKEOPTS="${make_opts}"
ADD="${use_add}"
REMOVE="${use_remove}"
USE="\$REMOVE \$ADD"
${cpu_flags}
# Portage Opts
FEATURES="parallel-fetch parallel-install ebuild-locks"
EMERGE_DEFAULT_OPTS="--with-bdeps=y"
AUTOCLEAN="yes"
# Ruby
RUBY_TARGETS="ruby23 ruby24 ruby25"
EOF
## set profiles
eselect profile set default/linux/amd64/17.0/desktop/gnome/systemd
## update everything and cleanup
emerge -juDN @world
emerge -c
## install commonly used tools
emerge -juDN vim bash-completion btrfs-progs
emerge -juDN app-portage/eix app-portage/gentoolkit sys-process/htop sys-process/glances sys-process/lsof
eselect bashcomp enable --global gentoo
## install vanilla sources and genkernel-next
emerge -C genkernel
emerge -juDN genkernel-next sys-kernel/gentoo-sources sys-kernel/linux-firmware
## Remember to enable:
## * all virtio devices; at least: virtio_pci and virtio_blk
## * btrfs support
genkernel --menuconfig --btrfs --virtio all
grub-install --no-floppy /dev/sda
# Configure real root and stuff
# Do not forget to append systemd to the kernel command line: GRUB_CMDLINE_LINUX="real_init=/lib/systemd/systemd quiet"
vim /etc/default/grub
# systemd
# remove udev since systemd will manage
emerge --deselect sys-fs/udev
## Setup machine ID to activate journaling
systemd-machine-id-setup
## set hostname
nostnamectl set-hostname my.example.tld
## set locale (after reboot)
# localectl set-locale LANG=<LOCALE>
## set time and date
# timedatectl --help
# update grub
grub-mkconfig -o /boot/grub/grub.cfg
# activate dhcp
systemctl enable NetworkManager
# set root password
passwd
# reboot (and pray, think wishfully, cross your fingers or whatever you do to influence reality... not!)
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment