User:Jbara/Installing Gentoo on Free Oracle VPS

Oracle offers free tier aarch64 based vps running Oracle Linux. Gentoo enthusiasts will probably want to install Gentoo on such a machine to make the most out of it. This guide explains in details how you can turn that headless machine into a Gentoo system.

Creating a temporary Gentoo Chroot
First create a temporary gentoo root file system.

Next you are going to need to download the stage3 tarball of your choice. Just make sure you pick an ARM tarball and not an amd64. Place the tarball in `/gentoo`

It is a good idea to backup the kernel modules that came with oracle linux since we will be sticking with their kernels for quite a while.

Now create the and bind /gentoo/mnt/oracle to your /

Now we are ready to enter the intermediate system.

Replacing your old filesystem with gentoo
At this point we start by selectively deleting folders and replacing them with ones from the gentoo fs.


 * Note: Var needs to be moved instead of deleted because some oracle programs are still using it. Trying to delete it will result in `Resource busy` error message.
 * Note: If you are following along in a machine that has a graphical session running. It is advised to do the previous step on tty since it breaks most programs including your terminal*

Chroot to the new system
You can now run the preparation to do another chroot.

After this you can chroot into your newly created gentoo filesystem. This one being the final target.

The system you just chrooted into is going to be the end result.

Configuration
First you mght need to configure portage. Check the handbook Installing the base system But generally you only need to configure your repos.conf and run `emerge-webrsync`

It might be important for your setup to set your root password now. From here you can get your system ready for next reboot. You might want to install net-misc/openssh for the next reboot. Just make sure to configure it properly so you can get access to your system on your next reboot.

Do not forget to run `ssh-keygen -A` and add your public rsa key to `~/.ssh/authorized_keys`. After that you can add it to your default runtime level.

Don't forget to get it back to port 22 after wards.* It is more recommended to use Utelnetd instead as it's possible to test it before rebooting.
 * Before rebooting. You might want to consider changing the port in `/etc/ssh/sshd_config` and testing ssh with `/usr/sbin/sshd -ddd` to check for any error messages. You probably won't be able to access it from the outside due to the firewall still running.

Post Installation

 * WARNING: It is not recommended to change the name of the volume group*

Managing storage
Once rebooted there are a couple of things you might want to conside doing. Such as expanding your `/` to take all the space instead of limiting yourself to 30G. After adding `lvm` to your global `USE` and updating `@world` with `--newuse`. Install `sys-fs/lvm2` and follow the following steps.

Logical volume
First Remove `"oled"` logical volume and add the space to `"root"` logical volume.

This will give you the remaining 15G on `/dev/sda3`. The next step is to get the unallocated 153G. First allocate it by pressing `n` in fdisk. {RootCmd|root # fdisk /dev/sda}} After creating the new partition. Change the its type with the t key, set it to `lvm`. Add it to the volume group and extend the logical volume.

Growing FS
Finally, to make use of the needed space on the logical volume. You need to grow your filesystem. On xfs this is done by the `xfs_grow` provided by `sys-fs/xfsprogs`

"net" generic service (OpenRC)
Openrc uses netifrc to manage the network without the need for a network manager. While dhcp is probably being managed by the initramfs. This is fine for basic functionalities, but some services depend on the `net` generic service. First emerge a dhcp client of choice. It is adviced to disable all dhcp server functionalities. (e.g. disable `server` use flag for `net-misc/dhcp`) Assuming the network interface name is `eth0` this should start the netifrc service for it.

Add to default runlevel

Afterwards, reboot your system, the "net" generic service and all services that depend on it should work just fine.
 * Note: You you can set net.ifnames=0 in grub.cfg (named at* `/boot/loader/entries/*-$(uname -r).conf` *) to get predictable interface names like eth0 instead of enp0s3*

Docker containers (OpenRC)
In this configuration. The kernel and kernel command line arguments confuse dockerd. Making it think the Cgroup driver that needs to be used is systemd instead of cgroupfs. If you're planning on using docker. Consider adding `--exec-opt native.cgroupdriver=cgroupfs` to `DOCKER_OPTS` in `/etc/conf.d/docker`.

Changing the bootloader
The boot process is currently complicated and messy. With configuration files calling other configuration files and so on. Arm's boot process is already complicated. Therefore a good practice is to switch to a clean boot process. Another advantage of this is to be able to change your kernel. First of all