Gentoo Linux quick installer script

Published on Author Artem Butusov12 Comments

Why?

Sometimes working gentoo environment could be needed just right now but typical manual installation is taking time.

Let’s say you need Gentoo running on Virtual Box on you physical box to test some gentoo-specific things or you just play with Gentoo distro.

The script in this article will save your time since it is doing basic Gentoo installation steps to get minimal bootable Gentoo instance. It is a little bit naive and straightforward but it is also simple and easy to tune for your needs. Pretty linear bash script that is intended to be executed in guest OS.

How it works

It is actually a minimal set of actions needed to get bootable Gentoo:

  • prepare partitions (boot, swap, root partitions)
  • install latest stage3 and portage snapshot (for x86_64 platform, but that could be altered in script)
  • install bootloader
  • install kernel
    • either quick mode: copy minimal install CD kernel
    • or regular mode: download source and build with genkernel
  • setup dhcp network on first interface
  • enable ssh
  • install your public ssh key for ssh access (password access disabled)
  • all other options like locale, charset, hostname are default, you could login into host and change if you want.

Prerequisites

Instruction below are for macOS host OS and guest Virtual Box instance. For Windows it is similar but you will need to use Putty for SSH.

By the way, even SSH is optional here. You could technically just type manually a few commands directly in virtual box console session to initiate installation.

  • SSH keys! Installed Gentoo will allow to login only using ssh key, password won’t work. SSH public key must be explicitly passed during installation.
    • Windows: Use Putty to generate keys and connect using keys: https://www.a2hosting.com/kb/getting-started-guide/accessing-your-account/using-ssh-keys
    • Linux/macOS: https://www.ssh.com/ssh/key/
  • Install VirtualBox
  • Create new instance (around 15GB is needed for minimal Gentoo)
  • (optional) Setup port forwarding from host to guest for SSH (for example, host 5555 -> guest 22)
  • Download minimal installation CD iso: https://www.gentoo.org/downloads/
  • Attach installation CD to instance
  • Boot from installation CD
  • (optional) Set root’s password (could be any, even very simple, used just for this installation session): passwd
  • (optional) Run SSH: /etc/init.d/sshd start
  • (optional) Connect from host over SSH: ssh root@localhost -p 5555
    • If the same host and port was previously used for SSH connection then previous SSH certificate fingerprint need to be removed to connect. It could be done here: ~/.ssh/known_hosts
  • Put your ssh public key somewhere where Virtual Box instance can download it.
    • for example, run python3 -m http.server 8888 --directory ~/.ssh on the host
    • download public key from guest later as wget http://10.0.2.2:8888/id_rsa.pub (or whatever public key you have)

Installation

THIS SCRIPT WILL DESTROY ALL DATA ON GUEST OS DISK!!! DO NOT RUN ON HOST OS WITH YOUR DATA!!!

  • Download gentoo installer: wget https://raw.githubusercontent.com/sormy/gentoo-vbox-builder/master/gentoo-vbox-sideload.sh
  • Download ssh public key, for example: wget http://10.0.2.2:8888/id_rsa.pub
  • Export ssh public key, for example: export SSH_PUBLIC_KEY="$(cat id_rsa.pub)"
  • (optional) All options that can be configured using environment variables:
    • SSH_PUBLIC_KEY – set to your SSH public key to be able to login into Gentoo after (not set by default)
    • USE_LIVECD_KERNEL – it is up to you, using binary precompiled version is a faster way to get bootable Gentoo (enabled by default).
  • Run script: bash gentoo-vbox-sideload.sh
  • After installation script will beep 10 times and will initiate reboot
  • Do not forget to eject installation CD from instance
  • The instance will be accessible only by SSH, forward local port to SSH guest port to have an access to it

Please note, script will stop if any error will happen.

Alternative

There is also full automated script available that can be executed on the host OS (works well for macOS and Linux, but could be tricky on Windows): https://github.com/sormy/gentoo-vbox-builder.

This script doesn’t require any manual typing in VirtualBox console.

12 Responses to Gentoo Linux quick installer script

  1. Thank you for sharing this script, I tested it today, it worked great.
    The only thing I miss is full disk encryption, I have not found any install script that does that.
    But some bloated gentoo based distros have it (sabayon, redcore, pentoo). Would be nice to
    have a clean system like what your script does – but also with full disk encryption.

    Thanks for sharing this script – saves a lot of time!

  2. Setting USE_LIVECD_KERNEL=0 resulted in an invalid configuration.

    This script is completely broken. You should just delete it so folks don’t waste time attempting to use it.

  3. Hello *,

    @Artem, Butusov
    Thanks you very very much for sharing the script !!!

    @Jeffrey, Walton
    Why when someone shares work with other people , in general someone has something to comment ? Is it that hard to appreciate the work of someone ? I suppose is the nature of human race !
    In case you have better knowledge, you can help in improving the script.

    Wish everyone a wonderful week !

    MfG,
    gentoo_starter

  4. Installed on VirtualBox three times, and the result is the same

    !!! Section ‘gentoo’ in repos.conf has location attribute set to nonexistent directory: ‘/var/db/repos/gentoo’
    !!! Invalid Repository Location (not a dir): ‘/var/db/repos/gentoo’

    Regenerating /etc/ld.so.cache…

    Installing kernel sources…

    !!! Section ‘gentoo’ in repos.conf has location attribute set to nonexistent directory: ‘/var/db/repos/gentoo’
    !!! Invalid Repository Location (not a dir): ‘/var/db/repos/gentoo’

    !!! /etc/portage/make.profile is not a symlink and will probably prevent most merges.
    !!! It should point into a profile within /var/db/repos/gentoo/profiles/
    !!! (You can safely ignore this message when syncing. It’s harmless.)

    !!! Your current profile is invalid. If you have just changed your profile
    !!! configuration, you should revert back to the previous configuration.
    !!! Allowed actions are limited to –help, –info, –search, –sync, and
    !!! –version.

  5. Good evening. So, you can congratulate me, the installation was a success. Here are a few questions that remain unresolved:
    1. This instruction does not describe the procedure for generating SSH keys, which is not clear. I have been using Putti for quite some time, but it is still not clear. Details are required.
    2. After the system boots up, the root user password set in livecd mode does not accept
    3. I did not like the host default name localhost.unknown_domain, is it possible to somehow set script parameter or set it more readable?

    P.S. The problem with the distribution kit is that no one wants to explain in their opinion the simple things that everyone should already know, but this is not so. I totally want to get the minimum basic knowledge in installing and using the distribution kit and thank you very much for your assistance.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.