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.
root #
mkdir /gentoo
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`
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 since we will be sticking with their kernels for quite a while.
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 your /
root #
mkdir /gentoo/mnt/oracle
root #
mount --rbind / /gentoo/mnt/oracle
Now we are ready to enter the intermediate system.
root #
chroot /gentoo
Replacing your old filesystem with gentoo
At this point we 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 .
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.
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.
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 you can chroot into your newly created gentoo filesystem. This one being the final target.
root #
chroot /mnt/oracle
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`
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 dafault
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. 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.
Post Installation
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 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.
root #
root # ln -s /etc/init.d/net.lo /etc/init.d/net.eth0
Add to default runlevel
root #
root # rc-update add default
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.
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
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