LXD on Centos 7

howto
snap

(Stéphane Graber) #1

Introduction

A lot of people have been asking us how to run LXD on Centos/RHEL 7 in the past.

Up until now, our answer has usually been to use some of the Fedora packages for liblxc, combined with a hand built version of LXD that you then have to manually integrate with your system. So certainly doable but not exactly clean or easy.

But now there is finally a cleaner, much more supportable way for you to get LXD on those systems as there is now a build of snapd that works with Centos/RHEL, letting you use the official LXD snap on those systems.

Note that the state of snapd on Centos/RHEL is still considered early days, so some features may be missing or broken. We did add automatic testing on our side as we do for all the other distributions and so far everything looks good.

Setting things up

The instructions below are based on a clean Centos 7.4 installation.

# Install snapd
yum install yum-plugin-copr epel-release
yum copr enable ngompa/snapcore-el7
yum install snapd
systemctl enable --now snapd.socket

# Install ZFS (skip if you don't want it)
yum install http://download.zfsonlinux.org/epel/zfs-release.el7_4.noarch.rpm
yum-config-manager --disable zfs
yum-config-manager --enable zfs-kmod
yum install zfs

# Configure the kernel
grubby --args="user_namespace.enable=1" --update-kernel="$(grubby --default-kernel)"
grubby --args="namespace.unpriv_enable=1" --update-kernel="$(grubby --default-kernel)"
echo "user.max_user_namespaces=3883" > /etc/sysctl.d/99-userns.conf
reboot

# Install the LXD snap
snap install lxd

# Configure LXD
lxd init

# Launch containers
lxc launch ubuntu:16.04 c1

Let us know if you notice anything missing/broken!


Weekly status #35
(Joe Gillotti) #2

Rather than applying the new kernel params to only the current kernel, it’s safer to add them to the GRUB_CMDLINE_LINUX variable in /etc/default/grub and then generate the new grub conf with grub2-mkconfig >/boot/grub2/grub.cfg so they apply to all kernels.


(Tatrasiel R) #3

Hey all,
anyone having troubles with adding this repo on step two?
I don’t see a way to install snapd in centos7.

Does anyone have a way get this working in Centos 7 with a modern kernel?

yum copr enable ngompa/snapcore-el7


    sudo yum copr enable ngompa/snapcore-el7
Loaded plugins: copr, fastestmirror, ovl

You are about to enable a Copr repository. Please note that this
repository is not part of the main Fedora distribution, and quality
may vary.

The Fedora Project does not exercise any power over the contents of
this repository beyond the rules outlined in the Copr FAQ at
<https://fedorahosted.org/copr/wiki/UserDocs#WhatIcanbuildinCopr>, and
packages are not held to any quality or securty level.

Please do not file bug reports about these packages in Fedora
Bugzilla. In case of problems, contact the owner of this repository.

Do you want to continue? [y/N]: y
Error: [Errno 14] HTTPS Error 404 - Not Found

(Stéphane Graber) #4

What architecture are you doing this on?

I reinstalled a Centos7 system last week and the instructions still worked fine.


(Tatrasiel R) #5

Hey Steven,
x86-64

uname -a
Linux intrellica-02-a 3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 19:03:37 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)

Perhaps I am wrong , but I don’t think this is an arch issue, but an access to repo one.

sudo yum copr enable ngompa/snapcore-el7

Is returning a 404. I wonder if there is a workaround for getting snapd installed on centos . Once this is installed, then the rest might work.

Correct me if I am wrong.

Thanks


(Stéphane Graber) #6

I was thinking it could be an architecture problem since the repo is only available for x86_64, but that’s what you’re running.


(Stéphane Graber) #7

Looks like it might have to do with the release of the latest RHEL/CentOS point release with COPR not yet finding the repo for it?

Anyway, the following worked here:

As a temporary replacement for yum copr enable ngompa/snapcore-el7


(Tatrasiel R) #8

Thanks , this seems to be going forward. I will let you know if something breaks.

Perhaps not the person to ask, but just out of curiosity , utilizing the snapd method, will I be able to continue updating my kernel and having LXD work with it?

EDIT:
It looks like it’s still struggling with name spaces.

Name: c1
Remote: unix://
Architecture: x86_64
Created: 2018/05/24 18:04 UTC
Status: Stopped
Type: persistent
Profiles: default

Log:

lxc 20180524180431.776 ERROR    lxc_start - start.c:lxc_spawn:1607 - Invalid argument - Failed to clone a new set of namespaces
lxc 20180524180431.818 WARN     lxc_network - network.c:lxc_delete_network_priv:2591 - Failed to remove interface "veth2HCR66" from "lxdbr0": Invalid argument
lxc 20180524180431.819 ERROR    lxc_start - start.c:__lxc_start:1866 - Failed to spawn container "c1"
lxc 20180524180431.819 ERROR    lxc_conf - conf.c:userns_exec_1:4116 - Failed to clone process in new user namespace
lxc 20180524180431.819 WARN     lxc_cgfsng - cgroups/cgfsng.c:cgfsng_destroy:1651 - Failed to destroy cgroups
lxc 20180524180431.819 ERROR    lxc_container - lxccontainer.c:wait_on_daemonized_start:824 - Received container state "ABORTING" instead of "RUNNING"
lxc 20180524180431.819 WARN     lxc_commands - commands.c:lxc_cmd_rsp_recv:130 - Connection reset by peer - Failed to receive response for command "get_cgroup"

(Stéphane Graber) #9

Did you run the gruby commands above and rebooted your system afterwards?

Without those, you won’t be able to setup namespaces which would explain the error.

Can you show cat /proc/cmdline ?


(Alex) #10

Good afternoon!
I decided this question this way:

$ cat << EOT > /etc/yum.repos.d/ngompa-snapcore-el7.repo
[ngompa-snapcore-el7]
name=Copr repo for snapcore-el7 owned by ngompa
baseurl=https://copr-be.cloud.fedoraproject.org/results/ngompa/snapcore-el7/epel-7-x86_64/
type=rpm-md
skip_if_unavailable=True
gpgcheck=1
gpgkey=https://copr-be.cloud.fedoraproject.org/results/ngompa/snapcore-el7/pubkey.gpg
repo_gpgcheck=0
enabled=1
enabled_metadata=1
EOT
$ yum update
$ yum install snapd

And further on the instructions. In CentOS 7.5 (1804) everything works fine.


(Tatrasiel R) #11

hey I am sorry I didn’t see the message for the reply on this but here is the command you requested.

cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-3.10.0-862.3.2.el7.x86_64 root=PARTUUID=eb3e2c88-901e-4843-a847-def87272fe6b ro console=tty0 crashkernel=auto console=ttyS0,9600 LANG=en_US.UTF-8 user_namespace.enable=1 namespace.unpriv_enable=1

(Stéphane Graber) #12

And you’re still running into that same error?
I just checked and my system matches your kernel version and command line.