Gentoo, My VMs' New HomesteemCreated with Sketch.

in linux •  7 years ago 

Hello to whomever reads this blog and welcome to Gentoo!
I was craving this distro for a long time, but I just couldn't install it . After so many trial and deadly errors inside a test VM, I finally was able to muster the courage needed to actually replace my 2.5 years old Arch VMs host with Gentoo .
Why Gentoo ?
Gentoo is hard for an Arch user, it takes a LOT longer to deploy, and dependencies conflicts are a huge turn off .
BUT, I wanted something more minimal than Arch . Pacman is awesome, but each package's deps are set in stone (PKGBUILDs) and it gets rather boring to edit these whenever you upgrade said package . Let's take Qemu package for example : I run this server entirely headless, it doesn't even have a GPU attached to the main OS (I'm passing all of them to different VMs) . Qemu pulls all kinds of X.org deps, which I obviously don't need and the same is true for Screenfetch too . In Gentoo I just put "-X" in USE flags and never be worried about X deps poisoning my headless pristine machine .
I used Arch ISO to build Gentoo, because it provides an excellent environment for UEFI out of the box . I did this while fasting, and with the lab's lights turned off to build the atmosphere for this scary jump.
This time, I read the Handbook for AMD64 and built my cheat sheet on top of it . Watching GCC codes flying on the screen while getting my 5820k raped with -j13 was satisfying .

The initial "emerge -auND --with-bdeps=y @world" took nearly 49 minutes

Porting my rc scripts from systemd to OpenRC was a challenge too, setting up the network was the hardest part because it NEEDS to be set inside OpenRC's networking stack (I used to call ip commands to set up my network manually) otherwise Samba won't start .
Finally got to install Qemu-9999 (Gentoo's way of saying VCS) and found a OVMF-9999 ebuild which was outdated, updated it and put it inside a local portage tree and it worked after a little bit of messing around . VFIO needed to be built statically inside the kernel because genkernel can't load it first at boot not matter what I would do . Its arguments are passed directly through the UEFI bootloader (Gummiboot! YEAH) .
Anyway, I think I love Gentoo, and I see myself never returning to Arch . Let's just hope that no updates would screw my system down this path .

My current /etc/portage/make.conf

CFLAGS="-march=native -mtune=native -O2 -pipe"
CXXFLAGS="${CFLAGS}"
MAKEFLAGS="-j6"
CHOST="x86_64-pc-linux-gnu"
USE="bindist bash-completion symlink avx2 acl python -debug -X -gtk -gtk2 -gtk3 -qt -qt4 -qt5"
PORTDIR="/usr/portage"
DISTDIR="/usr/src"
PKGDIR="${PORTDIR}/packages"
PORTAGE_TMPDIR="/tmp"
GENTOO_MIRRORS="http://gentoo.prz.rzeszow.pl"
FEATURES="candy"
ACCEPT_LICENSE=""
ACCEPT_KEYWORDS="~amd64"
PORTDIR_OVERLAY="/usr/local/portage"
#EMERGE_DEFAULT_OPTS="--ask"
#ACCEPT_KEYWORDS="
*"

/etc/portage/package.accept_keywords

sys-boot/gummiboot
=app-emulation/qemu-9999 **
=sys-kernel/spl-9999 **
=sys-fs/zfs-9999 **
=sys-fs/zfs-kmod-9999 **
=sys-devel/llvm-9999 **
sys-devel/bc **
sys-kernel/git-sources **
sys-fs/mdadm **
sys-fs/xfsprogs **

/etc/portage/package.use

app-emulation/qemu ** -python -jpeg -png usbredir usb libusb

=dev-lang/python-2.7.11-r2:2.7 sqlite

Here is my contribution to this distro, an up-to-date OVMF-9999 ebuild :

Copyright 1999-2014 Gentoo Foundation

Distributed under the terms of the GNU General Public License v2

$Header: $

EAPI=5

inherit eutils multiprocessing toolchain-funcs

DESCRIPTION="EDK II Open Source UEFI Firmware"
HOMEPAGE="http://tianocore.sourceforge.net"

LICENSE="BSD-2"
SLOT="0"
IUSE="debug +qemu +secure-boot +python_single_target_python2_7"
EGIT_REPO_URI="git://github.com/tianocore/edk2.git"
inherit git-2
KEYWORDS="-* ~amd64"
OPENSSL_PV="1.0.2g"
OPENSSL_P="openssl-${OPENSSL_PV}"
SRC_URI+=" mirror://openssl/source/${OPENSSL_P}.tar.gz"

DEPEND=">=dev-lang/nasm-2.0.7
sys-power/iasl
=dev-lang/python-2.7*[sqlite(+)]"
RDEPEND="qemu? ( app-emulation/qemu )"

src_prepare() {

This build system is impressively complicated, needless to say

it does things that get confused by PIE being enabled by default.

Add -nopie to a few strategic places... :)

if gcc-specs-pie; then
epatch "${FILESDIR}/edk2-nopie.patch"
fi

if use secure-boot; then
local openssllib="${S}/CryptoPkg/Library/OpensslLib"
mv "${WORKDIR}/${OPENSSL_P}" "${openssllib}" || die
cd "${openssllib}/${OPENSSL_P}"
epatch "${openssllib}/EDKII_${OPENSSL_P}.patch"
cd "${openssllib}"
sh -e ./Install.sh || die
cd "${S}"
fi
}

src_configure() {
./edksetup.sh || die

TARGET_NAME=$(usex debug DEBUG RELEASE)
TARGET_TOOLS="GCC49"
case $ARCH in
amd64) TARGET_ARCH=X64 ;;
#x86) TARGET_ARCH=IA32 ;;
*) die "Unsupported $ARCH" ;;
esac
}

src_compile() {
emake ARCH=${TARGET_ARCH} -C BaseTools -j1

./OvmfPkg/build.sh
-a "${TARGET_ARCH}"
-b "${TARGET_NAME}"
-t "${TARGET_TOOLS}"
-n $(makeopts_jobs)
-D SECURE_BOOT_ENABLE=$(usex secure-boot TRUE FALSE)
-D FD_SIZE_2MB
|| die "OvmfPkg/build.sh failed"
}

src_install() {
local fv="Build/OvmfX64/${TARGET_NAME}_${TARGET_TOOLS}/FV"
insinto /usr/share/${PN}/x64/
newins ${fv}/OVMF.fd ovmf_x64.bin
newins ${fv}/OVMF_CODE.fd ovmf_code_x64.bin
newins ${fv}/OVMF_VARS.fd ovmf_vars_x64.bin
}

It compiles amd64 binaries only as I don't need IA32 on my machine and install both unified OVMF as well as split CODE+VARS inside /usr/share/ovmf/x64/
My Gentoo's installation cheat sheet :

date MMDDhhmmYYYY

cd /mnt/

tar xvjpf stage3-*.tar.bz2 --xattrs

nano /mnt/etc/portage/make.conf

nano /mnt/etc/resolv.conf

mount -t proc proc /mnt/proc

mount --rbind /sys /mnt/sys

mount --make-rslave /mnt/sys

mount --rbind /dev /mnt/dev

mount --make-rslave /mnt/dev

chmod 1777 /dev/shm

chroot /mnt /bin/bash

source /etc/profile

export PS1="(CHROOT) $PS1"

emerge-webrsync

emerge --sync

nano /etc/locale.gen

locale-gen

eselect locale list

eselect locale set X

env-update && source /etc/profile && export PS1="(CHROOT) $PS1"

emerge --ask --update --deep --newuse --with-bdeps=y @world

perl-cleaner reallyall

echo "Asia/Riyadh" > /etc/timezone

emerge --config sys-libs/timezone-data

emerge --ask sys-kernel/git-sources

emerge --ask sys-kernel/genkernel

nano /mnt/etc/fstab

genkernel --menuconfig all (ACTIVATE VFIO, VIRTIO, VHOST, BRIDGE, UNIVERSAL TUN/TAP support inside the kernel "*")

CD TO /boot AND RENAME THE KERNEL TO vmlinuz AND THE INITRAMFS TO initramfs.img

nano /etc/conf.d/hostname

nano /mnt/etc/conf.d/net

ln -s /etc/init.d/net.lo /etc/init.d/net.eth0

rc-update add net.eth0 default

passwd

emerge dcron

rc-update add dcron default

crontab /etc/crontab

DON'T FORGET TO POPULATE THE CRONTAB!

rc-update add sshd default

emerge -a e2fsprogs xfsprogs dosfstools btrfs-progs bridge-utils dhcpcd

emerge --ask sys-boot/gummiboot

gummiboot install

nano /mnt/boot/loader/loader.conf

nano /mnt/boot/loader/entries/gentoo.conf

exit

cd

umount -l /mnt/dev{/shm,/pts,}

umount /mnt{/boot,/sys,/proc,}

reboot

Please do NOT run these commands automatically, these were meant as a quick referance of the steps detailed in the Handbook .
Regards .

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @seaofdata! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You published your First Post
You made your First Vote
You got a First Vote
Award for the number of upvotes received

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Congratulations @seaofdata! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You published 4 posts in one day

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!