Antsle Forum

Welcome to our Antsle community! This forum is to connect all Antsle users to post experiences, make user-generated content available for the entire community and more. 

Please note: This forum is about discussing one specific issue at a time. No generalizations. No judgments. Please check the Forum Rules before posting. If you have specific questions about your Antsle and expect a response from our team directly, please continue to use the appropriate channels (email: [email protected]) so every inquiry is tracked. 

Please or Register to create posts and topics.

Is there a way to create an LXC from scratch

For example, use "lxc-create" on the AntMan console?

I tried this to create a Ubuntu 14.04 LXC, but it doesn't appear in the available antlets.

Is there a way to do this? I tried the following:

> sudo lxc-create --template download --name ubuntu14 -- --dist ubuntu --release trusty --arch amd64

wbaker has reacted to this post.
wbaker

Doesn't seem to be an obvious way.  Is there documentation on how to make a "template" and tell antman about it?

What I found so far:
The https://docs.antsle.com/types/ promises that LXC is better but doesn't elaborate on how to work with them other use the three that have been packaged so far.  Building a container on another host and then moving /var/lib/lxc/mycontainer over to /antlets/_templates/mycontainer and /usr/local/antsleOS/lxc-mycontainer.antlet.xml is not enough. Something else configures how /usr/libexec/libvirt_lxc is run with the pre-prepared lxc system (/usr/libexec/libvirt_lxc --name mycontainer --console 20 --security=none --handshake 30 --veth vnet13 --veth vnet15)

Something as easy as lxc-create, lxc-start, lxc-stop, lxc-ls would be good.

OK ... figured out how to do it.  I'll give a sketch here.  It's all done with zpool attributes. And you can just ask the zpools what happened to them to figure it out on your own rig.

I want 'fedora-28' so that is the name in this example.
Assume you have 2 boxes (1) elsewhere.example.org (2) antsle.example.org

Phase 1. Prepare your LXC container on some other host, elsewhere, by any means necessary

elsewhere$ sudo lxc-create -t download -n fedora-28-c1 -- -d fedora -r 28 -a amd64
elsewhere$ sudo chroot /var/lib/lxc/fedora-28-c1/rootfs passwd
elsewhere$ sudo chroot /var/lib/lxc/fedora-28-c1/rootfs useradd -d /home/$USER -s /bin/bash -c "User $USER" $USER
elsewhere$ sudo chroot /var/lib/lxc/fedora-28-c1/rootfs passwd $USER
elsewhere$ sudo chroot /var/lib/lxc/fedora-28-c1/rootfs mkdir /home/$USER/.ssh
elsewhere$ sudo chroot /var/lib/lxc/fedora-28-c1/rootfs tee /home/$USER/.ssh/authorized_keys < ~/.ssh/authorized_keys >/dev/null
elsewhere$ sudo chroot /var/lib/lxc/fedora-28-c1/rootfs chown -R $USER.$USER /home/$USER
elsewhere$ sudo chroot /var/lib/lxc/fedora-28-c1/rootfs bash

chroot# ls -ld /etc/resolv.conf
lrwxrwxrwx. 1 root root 32 Sep 16 01:43 /etc/resolv.conf -> /run/systemd/resolve/resolv.conf
chroot# mkdir /run/systemd/resolve
chroot# cat > /run/systemd/resolve/resolv.conf
# Generated by NetworkManager
search dns.example.org
nameserver 192.168.0.1
nameserver 192.168.6.2
nameserver 192.168.0.3
EOF

chroot# dnf install -y openssh-server sudo
chroot# systemctl enable sshd
chroot# exit

elsewhere$ sudo lxc-ls -f
elsewhere$ sudo lxc-start -n fedora-28-c1
elsewhere$ sudo lxc-ls -f
# observe your new container at e.g. 192.168.122.174
elsewhere$ ssh -o StrictHostKeyChecking=no 192.168.122.174
fedora-28-c1$ ...do stuff...
fedora-28-c1$ exit

elsewhere$ sudo lxc-stop -n fedora-28-c1

Step 2. Pull the image over to antsle.example.org (use appropriate authorized_keys)

elsewhere$ ssh -A root@antsle.example.ort
antsle# SOMEPLACE=/var/tmp
antsle# mkdir $SOMEPLACE/fedora-28-c1
antsle# rsync [email protected]:/var/lib/lxc/fedora-28-c1/rootfs/ /var/tmp/fedora-28-c1/.

Step 3. Prepare the _templates area

antsle# cd /antlets/_templates
antsle# zfs create antlets/_templates/fedora-28.lxc
antsle# rsync -a $SOMEPLACE/fedora-28.lxc/ fedora-28.lxc/
antsle# zfs snapshot antlets/_templates/fedora-28.lxc@snap

Step 4. Prepare the instantiated image area

HOST=subhost
antsle# zfs send antlets/_templates/fedora-28.lxc@snap | zfs recv addon/$HOST
antsle# zfs set antsle:managed-origin=antlets/_templates/fedora-28.lxc@snap addon/$HOST

Step 5. Define a $HOST and use virsh to define it

antsle# cp /usr/local/antsleOS/xml/+lxc.antlet.xml /etc/libvirt/lxc/$HOST.xml
antsle# vi /etc/libvirt/lxc/$HOST.xml
edit the {{variables}} as appropriate
copy off of a nearby running LXC container (e.g. fire up the debian one and see how it looks)
{{mountpoint}} = /addon
{{name}} = $HOST
{{iphex}} = 2 hex digits of the "ith" container 10 = 0a, 15 = 0f ... you know.
antsle# virsh -c lxc:/// define $HOST.xml
// success message is "Domain fully defined from $HOST.xml"

Step 6. Look in antman

You will have two things
1. a running LXC container in Fedora 28
2. a template called "fedora-28"

Johannes Dietzel has reacted to this post.
Johannes Dietzel