User:Jbara/Installing Gentoo on Free Oracle VPS

From Gentoo Wiki
Jump to:navigation Jump to:search

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.

As of writing it is possible to get a free 4 core virtual machine with 24GB of RAM and 200GB of diskspace. A credit card or debit card is required for sign up.

Creating a temporary Gentoo Chroot

First create a temporary Gentoo root file system.

root #mkdir /gentoo

Next, download the stage3 tarball for the system Just make sure to pick the ARM64 tarball and not an amd64. Place the tarball in `/gentoo`

root #tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner

It is a good idea to backup the kernel modules that came with oracle Linux.

root #cp -a /lib/modules /gentoo/lib/modules
root #mount --types proc /proc /gentoo/proc
root #mount --rbind /sys /gentoo/sys
root #mount --make-rslave /gentoo/sys
root #mount --rbind /dev /gentoo/dev
root #mount --make-rslave /gentoo/dev
root #mount --bind /run /gentoo/run
root #mount --make-slave /gentoo/run
root #cp -a /etc/resolv.conf /gentoo/etc/

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

root #mkdir /gentoo/mnt/oracle
root #mount --rbind / /gentoo/mnt/oracle

Now, enter the intermediate system.

root #chroot /gentoo
root #env-update && . /etc/profile

Replacing your old filesystem with gentoo

At this point, start by selectively deleting folders and replacing them with ones from the Gentoo fs.

root #cd /mnt/oracle
root #for dir in bin etc lib lib64 media opt sbin usr; do

> rm -rf "$dir"; cp -a "/$dir" .

> done
root #mv var deleteme
root #cp -a /var .
Note
The /var directory 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 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 the terminal

Chroot to the new system

Re-run the preparation to do another chroot.

root #mount --types proc /proc /mnt/oracle/proc
root #mount --rbind /sys /mnt/oracle/sys
root #mount --make-rslave /mnt/oracle/sys
root #mount --rbind /dev /mnt/oracle/dev
root #mount --make-rslave /mnt/oracle/dev
root #mount --bind /run /mnt/oracle/run
root #mount --make-slave /mnt/oracle/run

After this chroot into your newly created Gentoo filesystem. This one being the final target.

root #chroot /mnt/oracle

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

Configuration

Check the handbook Installing the base system however configuring your repos.conf and run `emerge-webrsync` is all that is needed.

root #mkdir -p /etc/portage/repos.conf
root #cp /usr/share/portage/config/repos.conf /etc/portage/repos.conf/gentoo.conf
root #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.

root #emerge --ask net-misc/openssh

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.

root #ssh-keygen -A
root #rc-update add sshd default
Note
Before rebooting you may 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 will need to modify the firewall in Oracle's panel to add whichever port you decide to test externally as everything but port 22 is firewalled by default. Don't forget to get it back to port 22 afterwards.

Post Installation

Warning
It is not recommended to change the name of the volume

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.

root #lvremove /dev/ocivolume/oled
root #lvextend /dev/ocivolume/root /dev/sda3

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.

root #vgextend ocivolume /dev/sda4
root #lvextend /dev/ocivolume/root /dev/sda4

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`

root #xfs_growfs /

"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 advised 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.

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

Add to default runlevel

root #root # rc-update add net.eth0 default
CODE /etc/rc.conf
rc_hotplug="!net.*"
rc_depend_strict="NO"

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 (in `/boot/loader/entries/*-$(uname -r).conf` *) to get predictable interface names like eth0 instead of enp0s3. mount /dev/sda2 /boot to see this.

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