Before you read
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.
gentoo-vbox-builder doesn’t require any manual typing in VirtualBox console or any manipulations inside VirtualBox as the script referenced below.
However, the script below is easier and should work for any host OS since the script is executed inside guest.
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 your physical box to test some Gentoo-specific things or just to play with Gentoo Linux.
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 performs minimal set of actions 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:
- quick mode: Copy precompiled kernel from install CD.
- or regular mode: Download kernel sources and build kernel using genkernel.
- Setup dhcp wired network on first interface.
- Enable ssh.
- Install access credentials:
- Public SSH key for password-less ssh access.
- Root password for password-enabled ssh or regular terminal login access.
NOTE: All other options like locale, charset, hostname are default. You could login into host and change if you want.
Prerequisites
Instruction below should work for both macOS and Windows.
- 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 2222 -> guest 22)
- Download minimal installation CD iso: https://www.gentoo.org/downloads/
- Attach installation CD to instance
- Boot from installation CD
If you would like to enable SSH public key access:
- 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!!!
- Setup credentials to access Gentoo after installation
- Download ssh public key if needed, for example:
wget http://10.0.2.2:8888/id_rsa.pub
- Export ssh public key if needed, for example:
export SSH_PUBLIC_KEY="$(cat id_rsa.pub)"
- Pick any secure password that can be accepted by Gentoo (keep in mind, password should be kind of secure – at least 8 characters, mix of upper and lower case and digits)
- Export root password if needed, for example:
export ROOT_PASSWORD="Gentoo123"
- Download ssh public key if needed, for example:
- (optional) Configure other environment variables:
- USE_LIVECD_KERNEL – it is up to you, using binary precompiled version is a faster way to get bootable Gentoo (enabled by default).
- Download Gentoo installer:
wget https://raw.githubusercontent.com/sormy/gentoo-quick-installer/mainline/gentoo-quick-installer.sh
- If you don’t want to type this URL, you could connect to guest using SSH
- Run ssh daemon on guest:
/etc/init.d/sshd start
- Change root password on guest:
passwd
- Connect using ssh from host to guest:
ssh -p root@localhost -p 2222
- Run the script:
bash gentoo-quick-installer.sh
- After installation script will try to eject installation CD and will initiate reboot.
- After reboot you should get Gentoo login prompt. If it did not happen, ensure that installation CD is ejected.
Script will stop if any error will happen.
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!
You should use friendlier names in your GitHub. ‘wget https://gist.githubusercontent.com/sormy/7221a65a3becf082aaa3af2ec8dee1bc/raw/317d2aa4819e84b3ee6c8b20f15762684d6d7630/gentoo-installer.sh‘ is kind of ridiculous to try to type on the command line.
It is assumed that you can copy/paste this command to terminal.
I fixed this issue and updated the script. It should work now.
The script dies with the error, ‘cannot stat /mnt/cdrom/isolinux/gentoo: no such file or directory’. The minimal installation CD iso downloaded was http://distfiles.gentoo.org/releases/amd64/autobuilds/20190716T103222Z/install-amd64-minimal-20190716T103222Z.iso from https://www.gentoo.org/downloads/.
I had such high hopes for this script…
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.
I would fix it rather than deleting it. Thanks for feedback.
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
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’
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.
I fixed the script. Now it should work as expected. Tested with default configuration.
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.
Thanks
Out of curiosity… do you still mantain this script? 😉
It would save me a TON of time and I always wondered why Gentoo guys never even considered this idea
Yes, I do
That’s great! I’ll give it a try ASAP! I always get bored by Gentoo installation procedure. Before starting my own I hoped somebody had the same idea. Thank you for your efforts 🙂
BTW: can be good also to install Gentoo in a physical machine? Can we contribute?
I just went through your other instructions (successfully!) to install gentoo on AWS EC2 from stage3, building my own kernel. But it seems like this is a much better way. It’s more or less the same as the install-gentoo-in-place procedure:
https://wiki.gentoo.org/wiki/Replace_a_Linux_installation_with_Gentoo_in-place
It should work on AWS EC2. And it should be really easy if you use amazon’s kernel. Is there any reason not to do that?
There is no reason to not try if you want. You can share results here in comments.