Friday, August 5, 2016

Slackware and LXC

I have a fresh Slackware 14.2 I've been enjoying since it came out this month.  I needed a hyper-visor and was getting ready to add Xen (the hyper-visor of choice on Slackware).  I like Xen, but I knew the compile times for the Slackbuilds and it's dependencies would probably take more time than I had at the moment.  Then I remembered LXC.  It comes with.

I didn't know much about LXC so did some quick reading.  They say "it's similar to Docker but easier" - I like the sound of that.  So I check it out.  It's EXACTLY like Solaris containers!  Which I've been using for over 10 years - but, again, easier!  It's pretty slick!  And it installs by default on Slackware 14.2 but there's a few things you need to change.

ON THE HOST

Edit the /etc/rc.d/rc.inet1.conf

Slackware does not have a bridged network device by default BUT it does have it defined and commented out.  I found this works nicely except I was expecting my host interface to use eth0 and lxc guest to use br0.  It was not what I expected but it works fine!

# Example of how to configure a bridge:
# Note the added "BRNICS" variable which contains a space-separated list
# of the physical network interfaces you want to add to the bridge.
IFNAME[0]="eth0"
BRNICS[0]="br0"
#IPADDR[0]=""
#NETMASK[0]=""
USE_DHCP[0]="yes"
#DHCP_HOSTNAME[0]=""

Routing = Yes

You will, of course, need your host to route packets so

# chmod 755 /etc/rc.d/rc.ip_forward

And then start it or restart.  I like to restart to make sure everything is the way it needs to be before relying on it.  You could also just

# echo 0 > /proc/sys/net/ipv4/ip_forward


LXC Config

Really the only other thing you need to do is add a bit to /etc/lxc/default.conf.  This worked for me:

root@slacks:~# cat /etc/lxc/default.conf
lxc.network.type=veth
lxc.network.link=br0
lxc.network.flags=up

ON THE LXC GUEST

Just run netconfig and set a static address or DHCP and then restart rc.inet1.  

WHAT LXC GUEST?!!

Oh, I skipped that bit, eh?  Super simple.  Try this:
  
# lxc-create -n lxcguest -t /usr/share/lxc/templates/lxc-slackware
# lxc-start -n lxcguest -d
# lxc-console -n lxcguest  (it'll tell you how to login)

Now, run netconfig.  

What?!  You're already running Slackware on the host and you'd like to try something different?  Just run list the contents of  /usr/share/lxc/templates and then try one or a dozen of the other 18 pre-installed templates.  Like:

root@slacks:~# ls /usr/share/lxc/templates
lxc-alpine*     lxc-cirros*    lxc-openmandriva*  lxc-sparclinux*
lxc-altlinux*   lxc-debian*    lxc-opensuse*      lxc-sshd*
lxc-archlinux*  lxc-download*  lxc-oracle*        lxc-ubuntu*
lxc-busybox*    lxc-fedora*    lxc-plamo*         lxc-ubuntu-cloud*
lxc-centos*     lxc-gentoo*    lxc-slackware*



If you down like any of those, try something else with this command:

# lxc-create -t /usr/share/lxc/templates/lxc-download -n newguest

You will be given an even bigger choice.  Knowing Slackware and how stable it is, I would stay with the local choices to ensure that legendary stability stays as is (but that's just me). 


THE END

Well, that's all of my notes.  Postive comments and any kind of experiences with LXC are always welcome below.  

No comments: