From a8cea4e501a37bf5572d4e656452f39e6d9527c3 Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Sun, 17 Jan 2016 15:57:22 -0700 Subject: [PATCH] Restore shell-based LXD environment Move `lxd` (Ansible-based) to `lxd-ansible`. Restore `lxd` from earlier commit as `lxd-shell`. --- {lxd => lxd-ansible}/README.md | 0 {lxd => lxd-ansible}/Vagrantfile | 0 {lxd => lxd-ansible}/ansible.cfg | 0 {lxd => lxd-ansible}/machines.yml | 0 {lxd => lxd-ansible}/provision.yml | 0 lxd-shell/README.md | 45 ++++++++++++++++++++++++++++++ lxd-shell/Vagrantfile | 43 ++++++++++++++++++++++++++++ lxd-shell/servers.yml | 5 ++++ lxd-shell/setup.sh | 17 +++++++++++ 9 files changed, 110 insertions(+) rename {lxd => lxd-ansible}/README.md (100%) rename {lxd => lxd-ansible}/Vagrantfile (100%) rename {lxd => lxd-ansible}/ansible.cfg (100%) rename {lxd => lxd-ansible}/machines.yml (100%) rename {lxd => lxd-ansible}/provision.yml (100%) create mode 100755 lxd-shell/README.md create mode 100755 lxd-shell/Vagrantfile create mode 100755 lxd-shell/servers.yml create mode 100755 lxd-shell/setup.sh diff --git a/lxd/README.md b/lxd-ansible/README.md similarity index 100% rename from lxd/README.md rename to lxd-ansible/README.md diff --git a/lxd/Vagrantfile b/lxd-ansible/Vagrantfile similarity index 100% rename from lxd/Vagrantfile rename to lxd-ansible/Vagrantfile diff --git a/lxd/ansible.cfg b/lxd-ansible/ansible.cfg similarity index 100% rename from lxd/ansible.cfg rename to lxd-ansible/ansible.cfg diff --git a/lxd/machines.yml b/lxd-ansible/machines.yml similarity index 100% rename from lxd/machines.yml rename to lxd-ansible/machines.yml diff --git a/lxd/provision.yml b/lxd-ansible/provision.yml similarity index 100% rename from lxd/provision.yml rename to lxd-ansible/provision.yml diff --git a/lxd-shell/README.md b/lxd-shell/README.md new file mode 100755 index 0000000..e5f0aed --- /dev/null +++ b/lxd-shell/README.md @@ -0,0 +1,45 @@ +# Running LXC-Based OS Containers with LXD + +These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) quickly and relatively easily experiment with LXD (pronounced "lex-dee"), a new daemon and CLI client for working with LXC-based OS containers. The configuration was tested using Vagrant 1.7.2, VMware Fusion 6.0.5, and the Vagrant VMware plugin. + +## Contents + +* **README.md**: This file you're currently reading. + +* **servers.yml**: This YAML file contains a list of VM definitions and associated configuration data. It is referenced by `Vagrantfile` when Vagrant instantiates the VMs. No changes should be necessary to use this file. + +* **setup.sh**: This shell script is called by the Vagrant shell provisioner and configures `rkt` inside the VM created by Vagrant. No changes should be needed to this file. + +* **Vagrantfile**: This file is used by Vagrant to spin up the virtual machines. This file is fairly extensively commented to help explain what's happening. You should be able to use this file unchanged; all the VM configuration options are stored outside this file. + +## Instructions + +These instructions assume you've already installed VMware Fusion, Vagrant, and the Vagrant VMware plugin. Please refer to the documentation for those products for more information on installation or configuration. + +1. Use `vagrant box add` to install an Ubuntu 14.04 x64 box for the "vmware_fusion" provider. I have a base box you can use for this purpose; to use my Ubuntu 14.04 x64 base box, add the box with `vagrant box add slowe/ubuntu-trusty-x64`. (In theory you should be able to use this Vagrant environment with VMware Workstation as well, but only VMware Fusion was tested.) + +2. Place the files from the `lxd` directory of this GitHub repository (the "lowescott/learning-tools" repository) into a directory on your system. You can clone the entire "learning-tools" repository (using `git clone`), or just download the specific files from the `lxd` directory. + +3. Edit `servers.yml` to ensure that the box specified in that file matches the Ubuntu 14.04 x64 base box you just installed and will be using. _I recommend that you do not change any other values in this file unless you know it is necessary._ + +4. From a terminal window, change into the directory where the files from this directory are stored and run `vagrant up` to bring up the VMs specified in `servers.yml` and `Vagrantfile`. (By default, it will create and power on only a single VM.) + +5. Once Vagrant has finished creating, booting, and provisioning the VM (note you'll need Internet access for this step), log into the VM (named "lxd-01" by default) using `vagrant ssh`. + +6. Add the public LinuxContainers.org image repository by running `lxc remote add lxc-org images.linuxcontainers.org`. + +7. Copy the 32-bit Ubuntu 14.04 container image to your system with the command `lxc image copy lxc-org:/ubuntu/trusty/i386 local: --alias=trusty32`. + +8. Launch a container based on this image with the command `lxc launch trusty32 lxd-test-01`. This will start a container named "lxd-test-01" based on the "trusty32" image (which is an alias for the image you copied in step 7). + +9. Run `file /bin/ls` and note the output. (You'll use the output for comparison in just a moment.) + +10. Open a shell in the 32-bit container you launched in step 8 with the command `lxc exec lxd-test-01 /bin/bash`. + +11. Inside the container, run `file /bin/ls` and compare the output to the output of the same command you ran outside the container. You'll see that inside the container the file is reported as a 32-bit ELF executable; outside the container the same file is listed as a 64-bit ELF executable. + +12. Press Ctrl-D to exit the shell in the container. + +13. The container is still running, so stop the container with `lxc stop lxd-test-01`. + +There you have it---a way to quickly and easily experiment with LXD. Enjoy! diff --git a/lxd-shell/Vagrantfile b/lxd-shell/Vagrantfile new file mode 100755 index 0000000..1ef3280 --- /dev/null +++ b/lxd-shell/Vagrantfile @@ -0,0 +1,43 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Specify Vagrant version, Vagrant API version, and Vagrant clone location +Vagrant.require_version ">= 1.6.0" +VAGRANTFILE_API_VERSION = "2" +ENV['VAGRANT_VMWARE_CLONE_DIRECTORY'] = '~/.vagrant' + +# Require 'yaml' module +require 'yaml' + +# Read YAML file with VM details (box, CPU, and RAM) +servers = YAML.load_file('servers.yml') + +# Create and configure the VMs +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + + # Always use Vagrant's default insecure key + config.ssh.insert_key = false + + # Iterate through entries in YAML file to create VMs + servers.each do |servers| + config.vm.define servers["name"] do |srv| + + # Don't check for box updates + srv.vm.box_check_update = false + srv.vm.hostname = servers["name"] + srv.vm.box = servers["box"] + + # Enable default synced folder + srv.vm.synced_folder ".", "/vagrant" + + # Perform final provisioning activities + srv.vm.provision "shell", path: "setup.sh", privileged: true + + # Configure VMs with RAM and CPUs per settings in servers.yml + srv.vm.provider :vmware_fusion do |vmw| + vmw.vmx["memsize"] = servers["ram"] + vmw.vmx["numvcpus"] = servers["vcpu"] + end # srv.vm.provider + end # config.vm.define + end # servers.each +end # Vagrant.configure diff --git a/lxd-shell/servers.yml b/lxd-shell/servers.yml new file mode 100755 index 0000000..2ba0494 --- /dev/null +++ b/lxd-shell/servers.yml @@ -0,0 +1,5 @@ +--- +- name: lxd-01 + box: slowe/ubuntu-trusty-x64 + ram: 512 + vcpu: 1 diff --git a/lxd-shell/setup.sh b/lxd-shell/setup.sh new file mode 100755 index 0000000..7810665 --- /dev/null +++ b/lxd-shell/setup.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Initial housekeepting +export DEBIAN_FRONTEND=noninteractive + +# Add the PPA repository for LXD/LXC stable +if [[ ! -e /etc/apt/sources.list.d/ubuntu-lxc-lxd-stable-trusty.list ]]; then + sudo add-apt-repository -y ppa:ubuntu-lxc/lxd-stable +fi + +# Update package list +sudo apt-get update + +# Install LXC/LXD if not already installed +if [[ ! -e /usr/bin/lxd ]]; then + sudo apt-get -y install lxd +fi