In my previous article I explained how to install Ubuntu in a LXC container. But once a Gentoo user, always a Gentoo user. So lets see how to install Gentoo inside of a LXC Container from a provided template.
The installation part is exactly the same as it was for Ubuntu. The only difference is at the lxc-create command, you select Gentoo stable here ;). So if you did not install your SSD yet and do not know anything about the lxc-create command, read about it here!
First steps to a usable Gentoo Container
If you already tried to attach your newly created container, you should have noticed you have no network by default like you had with Ubuntu, and the standard Gentoo way to configure your NIC does not seem to work.
Get network connection
To solve or network problem, we need to change the configurations of the host, OpenWRT in my case. Here we have to change the configuration file of the Gentoo container.
lxc.network.ipv4 = 192.168.1.222/24 # replace 222 by the IP of you choice lxc.network.ipv4.gateway = 192.168.1.1 # You can also set it to auto
let’s restart or container, you should now have a network connection.
# lxc-start -n gentoo
# lxc-attach -n gentoo
now that we have a network connection, you could try to update the portage tree with ’emerge –sync’. But this will fail because Gentoo does not seem to know where to find the Portage servers! and portage itself is not properly setup by the makers of this container.
domain myLanDomain nameserver 192.168.1.1
this should do for the network problem!
Lets fix portage
The network connection is working at last, but portage is still a problem!
# nano /etc/portage/repos.conf/gentoo.conf
[DEFAULT] main-repo = gentoo [gentoo] location = /usr/portage sync-type = rsync sync-uri = rsync://rsync.gentoo.org/gentoo-portage auto-sync = yes
Updating the system
# rm -r /usr/portage/metadata/news/*
# emerge -1 sys-devel/libtool
# eselect profile list
# eselect profile set 30 # default/linux/arm/17.0/musl/armv7a
# emerge screen
# emerge -1 sandbox
# . /etc/profile
# emerge -uDN –with-bdeps=y @world
After updating portage emerge gave some errors on news files that are corrupted. The only way to solve this problem was by removing the folder where the news items resent. If you want to know what the news items were about, you can still read them here.
The next thing to do should be updating the profile, for the first time in years Gentoo has updated their profiles (13 -> 17) and it is very important to update your profile as soon as possible, so now is the perfect time. The official documentation recommends a slightly other upgrading path than the one I use, you can read all about it here
Because emerging the updated system can take quite a wile it is recommended to install “screen”, this way you can close the terminal while the compiling is still going on. If you do this, you can get back to the same console later by doing ‘screen -r’. In case you are not familiar with screen, make sure to read the man page, it’s a very interesting tool.
The emerge @world command can fail at some point, before googling (or contacting me, try starting it again, in my case it worked this way. You are upgrading some very old compilers, that is why some failed builds are normal.
Hooray! We now have or working Gentoo container. It still has some points of improvement, like using distcc in combination with crossdev to compile on more powerful computers. But by now I am very satisfied with this install and I will come back to these optimizations at another time.
External links & sources
- Official Gentoo installation Handbook
- Turris forum: Gentoo LXC up and running
- Gentoo forum: Cannot emerge libtool