Gentoo - MaskRay/Config GitHub Wiki

On the host,

qemu-system-x86_64 -enable-kvm -m 16384 -smp 8 -cpu host -bios /usr/share/ovmf/OVMF.fd -drive file=~/Images/gentoo.qcow2,if=virtio -net nic,model=virtio -nic user,hostfwd=tcp::2224-:22 -fsdev local,id=Dev,path=$HOME/Dev,security_model=none -device virtio-9p-pci,fsdev=Dev,mount_tag=Dev

On the guest,

sudo mount -t 9p Dev /home/ray/Dev -o trans=virtio,msize=$[5*1024*1024]

Installation

After chroot,

mkdir --parents /mnt/gentoo/etc/portage/repos.conf
cp /mnt/gentoo/usr/share/portage/config/repos.conf /mnt/gentoo/etc/portage/repos.conf/gentoo.conf

emerge eix app-eselect/eselect-repository
eselect repository enable musl
emaint sync -r musl

Kernel and bootloader

elfutils is from the musl overlay.

emerge elfutils gentoo-sources efibootmgr

cd /usr/src/linux
make menuconfig

https://wiki.gentoo.org/wiki/EFI_stub https://wiki.gentoo.org/wiki/QEMU/Linux_guest

Processor type and features  --->
    [*] EFI runtime service support
    [*]   EFI stub support
    [ ]     EFI mixed-mode support
    ...
    [*] Linux guest support --->
        [*] Enable Paravirtualization code
        [*] KVM Guest support (including kvmclock)
    ...
    [*] Built-in kernel command line
    (root=/dev/vda2)
Device Drivers  --->
    [*] Virtio drivers  --->
        <*> PCI driver for virtio devices
    [*] Block devices  --->
        <*> Virtio block driver
    SCSI device support  --->
        [*] SCSI low-level drivers  --->
            [*] virtio-scsi support
    [*] Network device support  --->
        [*] Network core driver support
            <*> Virtio network driver
    Graphics support  --->
        <*> Virtio GPU driver
make -j 4
make install modules_install

cp /boot/vmlinuz-* /boot/efi/boot/bootx64.efi
efibootmgr --create --disk /dev/vda --part 2 --label "Gentoo" --loader "\efi\boot\bootx64.efi"

In case the disk does not book, type the following in the UEFI shell then reboot:

bcfg boot add 0 FS0:\efi\boot\bootx64.efi

/etc/fstab

/dev/vda2               /               xfs             noatime         0 1
/dev/vda1               /boot               vfat        noatime         0 1
tmpfs                   /tmp            tmpfs           defaults        0 0
tmpfs                   /var/tmp/portage tmpfs          size=4G,uid=portage,gid=portage,mode=775,nosuid,noatime,nodev  0 0

Network

emerge dhcpcd

cd /etc/init.d
ln -s net.lo net.enp0s3

```sh
rc-update add net.enp0s3 default
rc-update add sshd default

File sharing

Networking support  --->
  Plan 9 Resource Sharing Support (9P2000)  --->
    <*> 9P Virtio Transport

File Systems  --->
  Network File Systems  --->
    <*> Plan 9 Resource Sharing Support (9P2000)

llvm-project

https://wiki.gentoo.org/wiki/Clang

# Work around lack of execinfo.h.
euse -D gwasan libfuzzer

#/var/tmp/portage/sys-libs/compiler-rt-sanitizers-13.0.0/work/compiler-rt/lib/hwasan/hwasan_exceptions.cpp:32:9: error: unknown type name '_Unwind_Word'
#typedef _Unwind_Word GetGRFn(_Unwind_Context* context, int index);
euse -D hwasan

euse -E clang default-compiler-rt default-lld llvm-libunwind
LLVM_COMMON=(-GNinja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DLLVM_APPEND_VC_REV=OFF -DLLVM_ENABLE_BINDINGS=OFF -DLLVM_ENABLE_LLD=On -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;lldb;lld;compiler-rt' -DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi;libunwind')
cmake -Sllvm -Bout/release -DCMAKE_BUILD_TYPE=Release ${LLVM_COMMON} -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-gentoo-linux-musl -DCLANG_DEFAULT_LINKER=lld -DCLANG_DEFAULT_CXX_STDLIB=libc++ -DCLANG_DEFAULT_RTLIB=compiler-rt -DCLANG_DEFAULT_UNWINDLIB=libunwind -DLIBCXX_HAS_MUSL_LIBC=On