Technical Details

This page shows how Gentoo Studio is built. Comments and suggestions are welcome.

In the beginning, Gentoo Studio was an audio-for-Gentoo guide. Then I started manually creating stage4’s. Then I migrated to Catalyst. Somewhere along the way, NeddySeagoon created a sticky on forums.gentoo.org for Gentoo Studio – thanks, Neddy!

The stage4 tarball is built with Catalyst on a computer set aside for Gentoo Studio development. The tarball is then test-installed in a virtual machine, followed by a test install on a spare physical computer.

I try to comment my files so that they are self-explanatory. After a long lull in development due to life happening, I’ve decided to rebuild all the scripts from scratch to try to clear out accumulated cruft. So as of 19 August 2021, these files produce a basic working Gentoo Studio:

(Note that some lines wrapped when I pasted them here.)

autobuild.sh:

#!/bin/bash

catalyst -af stage1.spec
catalyst -af stage2.spec
catalyst -af stage3.spec
catalyst -af stage4-1.spec
catalyst -af stage4-2.spec

stage1.spec:

subarch: amd64
target: stage1
version_stamp: latest
rel_type: default
profile: default/linux/amd64/17.1
snapshot: latest
source_subpath: stage3-amd64-seed
update_seed: yes
update_seed_command: --update --deep --newuse @system @world

stage2.spec:

subarch: amd64
target: stage2
version_stamp: latest
rel_type: default
profile: default/linux/amd64/17.1
snapshot: latest
source_subpath: default/stage1-amd64-latest

stage3.spec:

subarch: amd64
target: stage3
version_stamp: latest
rel_type: default
profile: default/linux/amd64/17.1
snapshot: latest
source_subpath: default/stage2-amd64-latest
portage_confdir: /root/catalyst/etc/portage

stage4-1.spec:

subarch: amd64
version_stamp: latest
target: stage4
rel_type: default
profile: default/linux/amd64/17.1
snapshot: latest
source_subpath: default/stage3-amd64-latest.tar.bz2
# This stage needs its own confdir to get harfbuzz/freetype to behave
portage_confdir: /root/catalyst/stage4-1tmp/etc/portage

# Calling harfbuzz first bypasses circular deps between harfbuzz and freetype
# After this, we have catalyst call stage4-2.spec to continue
stage4/packages:
media-libs/harfbuzz

stage4-2.spec:

subarch: amd64
version_stamp: latest
target: stage4
rel_type: default
profile: default/linux/amd64/17.1/desktop
snapshot: latest
source_subpath: default/stage4-amd64-latest.tar.bz2
portage_confdir: /root/catalyst/etc/portage
portage_overlay: /var/lib/layman/audio-overlay

# Use flags we want that aren't here are provided by the desktop profile globally
# At some point these should all be checked out to make sure they're still in use (qt3support?)
stage4/use:
aacplus
audacious
cddb
cdio
consolekit
corefonts
dssi
encode
equalizer
faac
ffmpeg
fftw
fluidsynth
freesound
gudev
gtk3
hwdb
id3
id3tag
ieee1394
jack
ladspa
lame
libsamplerate
lv2
matroska
midi
minizip
mpg123
musepack
musicbrainz
netjack
opus
pcre16
python
python_targets_python3_5
qt3support
quicktime
realtime
rubberband
shine
shout
skins
sndfile
soundtouch
taglib
theora
timidity
twolame
vamp
vcd
wav
wavpack
xine
xkb
xvfb
xvmc
-pulseaudio
-systemd
-xscreensaver

# Notes:
# /dev/vcs-git required for eix-sync to work
stage4/packages:
app-admin/syslog-ng
app-editors/nano
app-portage/cpuid2cpuflags
app-portage/eix
app-portage/gentoolkit
app-portage/repoman
app-portage/smart-live-rebuild
app-portage/ufed
dev-vcs/git
gnome-extra/nm-applet
media-plugins/alsa-plugins
media-plugins/calf
media-plugins/swh-plugins
media-sound/a2jmidid
media-sound/alsa-tools
media-sound/alsa-utils
media-sound/amsynth
media-sound/ardour
media-sound/audacious
media-sound/audacity
media-sound/bristol
media-sound/cadence
media-sound/chuck
media-sound/fluidsynth
media-sound/frescobaldi
media-sound/hydrogen
media-sound/gigedit
media-sound/jack-rack
media-sound/jack2
media-sound/jamin
media-sound/linuxsampler
media-sound/lmms
media-sound/musescore
media-sound/qjackctl
media-sound/qsampler
media-sound/rosegarden
media-sound/zynaddsubfx
net-misc/dhcpcd
net-misc/networkmanager
sys-apps/usbutils
sys-boot/grub
sys-kernel/genkernel
sys-kernel/linux-firmware
sys-kernel/rt-sources
x11-base/xorg-server
x11-misc/lightdm
xfce-base/xfce4-meta
xfce-extra/xfce4-alsa-plugin
xfce-extra/xfce4-power-manager

# Don't use stage4/empty. We might need relevant dirs in fsscript.

stage4/fsscript: /root/catalyst/fsscript.sh

fsscript.sh:

#!/bin/bash

### SYSTEM FILES ###
# fstab should be done by the installer script because we don't know yet whether the user has legacy or EFI.
# This section should precede system updates so eix-sync will pick up the overlay.
# Using /var/lib/layman makes this compatible in case the user installs layman.
mkdir -p /etc/portage/repos.conf
cat > /etc/sysctl.conf <<EOF
vm.swappiness = 10
dev.rtc.max-user-freq=3072
dev.hpet.max-user-freq=3072
EOF
cat > /etc/security/limits.d/audio.conf <<EOF
@audio - rtprio 95
@audio - memlock unlimited
EOF
cat > /etc/udev/rules.d/firewire.rules <<EOF
KERNEL=="fw0", GROUP="audio", MODE="0664"
KERNEL=="fw1", GROUP="audio", MODE="0664"
KERNEL=="fw2", GROUP="audio", MODE="0664"
EOF
cat > /etc/udev/rules.d/timer-permissions.rules <<EOF
KERNEL=="rtc0", GROUP="audio"
KERNEL=="hpet", GROUP="audio"
EOF
cat > /etc/portage/repos.conf/audio-overlay.conf <<EOF
[audio-overlay]
location = /var/lib/layman/audio-overlay
sync-type = git
sync-uri = https://github.com/gentoo-audio/audio-overlay.git
auto-sync = yes
EOF
cat > /etc/conf.d/display-manager <<EOF
CHECKVT=7
DISPLAYMANAGER="lightdm"
EOF
cat >> /etc/portage/make.conf <<EOF
ALSA_CARDS="*"
EMERGE_DEFAULT_OPTS="--quiet"
CONFIG_PROTECT="protect-owned"
MAKEOPTS="-j2"
EOF
# TODO: write a skel file for a default Gentoo Studio appearance
# TODO: Check if snd-seq is now auto-loaded. It wasn't in previous iterations.

### SYSTEM UPDATES ###
cp /usr/share/portage/config/repos.conf /etc/portage/repos.conf/gentoo.conf
emerge-webrsync
eix-sync
# Doing --fetchonly first lets me disconnect my hotspot sooner.
emerge -fuDN --keep-going --with-bdeps=y --backtrack=250 @system @world
emerge -uDN --keep-going --with-bdeps=y --backtrack=250 @system @world
smart-live-rebuild
emerge --depclean
revdep-rebuild

### KERNEL ***
# Kernel would not compile in stage4.spec due to not finding /tmp/kerncache/rt/sources.
# Kernel has to be genkernelled now to generate a .config, unless we can find a shorter way to do this.
# Make bzImage only to save time.
eselect kernel set 1
genkernel bzImage
# In order to get full preemption, we need to:
# replace
# CONFIG_PREEMPT_VOLUNTARY=y
# CONFIG_PREEMPT is not set
# with
# CONFIG_PREEMPT=y
# CONFIG_PREEMPT_COUNT=y
# CONFIG_PREEMPTION=y
sed -i 's/CONFIG_PREEMPT_VOLUNTARY=y/CONFIG_PREEMPT=y\nCONFIG_PREEMPT_COUNT=y\nCONFIG_PREEMPTION=y/' /usr/src/linux/.config
sed -i 's/# CONFIG_PREEMPT is not set//' /usr/src/linux/.config
# Save a cp of the config for safekeeping.
cp /usr/src/linux/.config /usr/src/linux/.config_full_preempt
# Now run genkernel again to make this take effect.
# genkernel will run a silent make oldconfig, accepting the default changes relevant to config_preempt.
genkernel --kernel-config=/usr/src/linux/.config_full_preempt all
# Get rid of old kernels from previous build runs
rm /boot/*.old
# We may need to cp/mv the files from /boot since a boot partition will be mounted during install.

# Old news shouldn't concern new users
eselect news read all

STAGE4/EMPTY REPLACEMENT ***
# This reduces the tarball size by rm'ing !needed files.
rm /var/cache/distfiles/*
rm -rf /usr/src/linux/*

What’s next:

I need to re-write the installer script and do the VM/real machine test installs. This in itself could take some time.

While I’m at it, I’m also adding most of the stuff from audio-overlay into stage4/packages.

Comments and suggestions on any part of this are always welcome.