<!--
.. title: A gentoo installation story - continued!
.. slug: a-gentoo-installation-story-continued
.. date: 2025-01-19 20:14:21 UTC
.. tags: install,linux,security,gentoo
.. category: 
.. link: 
.. description: 
.. type: text
.. author: Dejice Jacob
-->

## The birth of a Gentoo Linux KDE Desktop
I have previously journaled ([Part-I](../an-encrypted-boot-gentoo-installation-story))
my attempt to create an encrypted Gentoo Linux desktop. Please follow that first. 
It was a little more involved than I expected. I had to revisit some of the steps one or two times. 
Some of the steps in that post might better fit in this post. But hindsight is a wonderful thing. 
Now we come to building out what the general public think of as a computer (the Desktop). 

## Install some useful utilities 
```bash
localost / $ eselect profile list # to get a list of desktop profiles 
localost / $ eselect profile set <KDE-openrc>  # I will also setup i3 tiling window manager
localost / $ echo "Europe/London" > /etc/timezone
localost / $ emerge --sync 
localost / $ emerge --quiet-build --ask --config sys-libs/timezone-data 
localost / $ emerge --quiet-build --ask app-misc/screen sys-process/htop
```
#### Setup WiFi (Optional) 
In ([Part-I](../an-encrypted-boot-gentoo-installation-story)), 
I already had ethernet and used that for installation. However, if WiFi is something that is 
required, then the following instructions should set up WiFi. Bear in mind that WiFi drivers 
could be missing from your kernel configuration. Searching 
the [Gentoo forums](https://forums.gentoo.org) for a similar issue would be helpful. 

I will be installing `network-manager` later on
and will have to disable both *dhcpcd* and *wpa-supplicant*. If we forget, then we will have 
two instances of DHCP and WiFi daemons duelling each other. 
```bash
localost / $ emerge --quiet-build --ask net-misc/dhcpcd
localost / $ emerge --ask --verbose net-wireless/wpa_supplicant
localost / $ cp /usr/share/dhcpcd/hooks/10-wpa_supplicant /lib/dhcpcd/dhcpcd-hooks/
localost / $ bzcat  /usr/share/doc/wpa_supplicant-<ver-no>/wpa-supplicant.conf.bz2 > /etc/wpa_supplicant/wpa_supplicant.conf
```
Almost all variations of a wpa-supplicant configuration can be obtained from 
"*/usr/share/doc/wpa_supplicant-<ver-no>/wpa_supplicant.conf.bz2*". Uncomment the
following in `/etc/wpa_supplicant/wpa_supplicant.conf`. 
```bash
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel
eapol_version=1
ap_scan=1
fast_reauth=1
```
Also generate the network connection parameters and insert into `wpa_supplicant.conf` using `wpa_passphrase`
and remove every other configuration in that file. In case you have a more complicated set-up, then you will 
have to configure this according to your setup. 
```bash
localost / $ wpa_passphrase ${ssid} ${passphrase}  >> /etc/wpa_supplicant/wpa_supplicant.conf
```
Change the value of `wpa_supplicant_args` in `/etc/conf.d/wpa_supplicant.conf` to: 
```bash
wpa_supplicant_args="-B -M -c/etc/wpa_supplicant/wpa_supplicant.conf"
```
Now add the `dhcpcd` and `wpa_supplicant` services to default runlevel and start the services. 
```bash 
localost / $ rc-update add dhcpcd default
localost / $ rc-update add wpa_supplicant default
localost / $ rc-service dhcpcd start
localost / $ rc-service wpa_supplicant start
```

#### [Setting up NTP](https://wiki.gentoo.org/wiki/Ntp#Ntpd)
Networking and "time" dependent programs require accurate date and time information. This is achieved by installing **NTPD**. 
```bash
localost / $ emerge --ask net-misc/ntp
localost / $ rc-update add ntpd default
localost / $ rc-service ntpd start
```

<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Gentoo_Live_GUI_USB_running_KDE.png/640px-Gentoo_Live_GUI_USB_running_KDE.png"
 title="A Gentoo KDE Desktop"
 alt="Gentoo KDE desktop">
</img>



## [Install the KDE desktop](https://wiki.gentoo.org/wiki/KDE)
While Wayland seems to be the future, I am still quite comfortable with the `X` server. It also helps that the 
`i3wm` window manager also is dependent on `X-sever`. The **KDE** meta-package is comprehensive and installs 
all the KDE applications and dependencies. 
```bash
localhost / $ emerge --ask kde-plasma/plasma-meta
```
Ensure that the KDE display manager `sddm` is installed; then ensure that the "**DISPLAYMANAGER**" variable is set 
to *sddm*. 
```bash 
DISPLAYMANAGER="sddm"
```
Add the requisite services to openrc to start at boot, 
```bash
localost / $ rc-update add dbus default
localost / $ rc-update add display-manager default
localost / $ rc-update add elogind boot
```

<img src="https://media2.giphy.com/media/v1.Y2lkPTc5MGI3NjExc2t3czJ2YTF6MHJheGRlNHplenlmbGhpN214Mng3czBrcnQya203dCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/DUtVdGeIU8lmo/giphy.gif"
 title="Restarting always works!"
 alt="IT crowd">
</img>
In my case, at this point, I found that just starting up the boot displaymanager from *openrc* did not get `sddm` to start.
Rebooting the machine sorted the crashing display manager out. 


#### Debugging:  [Install *X-server*](https://wiki.gentoo.org/wiki/X_server)
If there are any problems with bringing up KDE, using X-server to debug the issue is very useful. 
In case it was not already installed when *KDE-meta* was installed, 
start with installing X-server and  driver  packages.
```bash
localost / $ emerge --ask --verbose x11-base/xorg-drivers x11-base/xorg-server
```
To test out that the X-server is working correctly install a few **X** applications
```bash
localost / $ emerge -a x11-terms/xterm x11-apps/xclock x11-wm/twm
localost / $ startx   # to test if display server is working
```

#### Sidenote: Uninstall dhcp and wpa-supplicant
Keeping `dhcpcd` and `wpa-supplicant` running in the background led me to some incredibly 
annoying and hard to debug problems with networking. The KDE deskptop already installs 
`NetworkManager` and this will in turn call an instance of *dhcp*  and *wpa_supplicant*. 
You do NOT need your own version fighting with it. So... 
```bash
localost / $ rc-service stop dhcpcd
localost / $ rc-update del dhcpcd
localost / $ rc-service stop wpa_supplicant
localost / $ rc-update del wpa_supplicant
```
## Congratulations! 
If you have persevered with the process this far, congratulations! You should have a
desktop machine that you have compiled from source. Obviously, I have cleverly 
hidden all the frustrating debug work that went into steps going wrong. Along with 
this, there are issues with drivers or kernel features required by some software
component not being turned **ON**. However, that is what the incredible 
gentoo [forums](https://forums.gentoo.org/) and [wiki](https://wiki.gentoo.org/wiki/Main_Page) 
are for. Happy compiling and debugging.
