1
0
mirror of https://gist.github.com/a929dfdb0cdb7dd946d313bde708900e.git synced 2024-12-04 10:51:32 -08:00

finish writing gentoo_nspawn_container_on_Digital_Ocean.md

This commit is contained in:
Trent Palmer 2017-05-20 22:32:39 -07:00
parent fe436a649c
commit 34c0c3c74e

View File

@ -1 +1,68 @@
## Install a Gentoo nspawn Container on Ubuntu 17.04 on Digital Ocean.
## Install a Gentoo nspawn Container on Ubuntu 17.04 on Digital Ocean.
Spin up an Ubuntu 17.04 droplet, because nspawn containers are slightly
more difficult with Ubuntu 16.04. Install systemd-container.
```bash
apt install systemd-container
```
After installing systemd-container you will discover a new directory,
/var/lib/machines, and you can create a directory there for a new container.
You'll need a systemd stage3 tarball for gentoo and you can get those from the
[Gentoo Website](http://distfiles.gentoo.org/releases/amd64/autobuilds/current-stage3-amd64-systemd/)
After checking the hash you can extract it to your new folder
```bash
cd /var/lib/machines/gentoocontainer/
tar xvjpf /path/to/stage3-*.tar.bz2 --xattrs --numeric-owner
cd ../
```
Start the container so you can create a root password
```bash
systemd-nspawn -D gentoocontainer
passwd
logout
```
Because of how Digital Ocean sets up networking, if you want to subnet
the container, start systemd-network (systemd-resolved is probably already running).
And optionally it's also pretty straightforward to create a /usr/portage directory
on the host operating system, and then bind that directory to the container.
```bash
# start the container and login as root
systemd-nspawn -b -D gentoocontainer
# to subnet the container
# start systemd-networkd on host
# and add -n flag
systemctl start systemd-networkd
systemd-nspawn -b -D gentoocontainer -n
# to bind /usr/portage
# create /usr/portage on host
mkdir /usr/portage
# and add the --bind option
systemd-nspawn -b -D gentoocontainer -n --bind=/usr/portage
```
You should have a root command line on the container, and there really are only
two further things to consider: the container probably inherits timezone
from the host, but not locale. And your MAKEOPTS="-j<some number>", some things
seem to not compile if your MAKEOPTS j number is more than the number of
cores on the host.
Your systemd-nspawn command will open up one root console, but if you use
a multi-plexer like byobu you can run additional sessions with machinectl
commands
```bash
# also works with new users in the container which you might create
machinectl shell root@gentoocontainer
# and then to get the whole environment call bash
bash
# to power down the container
poweroff
```