mirror of
https://github.com/outbackdingo/matchbox.git
synced 2026-01-27 10:19:35 +00:00
pxe: Add libvirt PXE server Vagrantfile and scripts
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.vagrant
|
||||
42
README.md
Normal file
42
README.md
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
`pxe` provides a Vagrantfile and scripts for setting up a PXE server in libvirt or on physical hardware.
|
||||
|
||||
## Setup
|
||||
|
||||
To develop with with Vagrant, install the dependencies
|
||||
|
||||
# Fedora 22/23
|
||||
dnf install vagrant vagrant-libvirt virt-manager
|
||||
|
||||
## Usage
|
||||
|
||||
The Vagrantfile will setup a `pxe_default` VM running a PXE server with a configured static IP address, DHCP range, CoreOS kernel image, and cloud-config. The VM will be connected to a network called `vagrant-libvirt`.
|
||||
|
||||
### libvirt Provider
|
||||
|
||||
vagrant up --provider libivrt
|
||||
vagrant ssh
|
||||
|
||||
Once the PXE server has started, you can start client VMs within the `vagrant-libvirt` network which should boot as PXE clients.
|
||||
|
||||
Launch `virt-manager` to create a new virtual machine. When prompted, select Network Boot (PXE), skip adding a disk, and choose the `vagrant-libvirt` network.
|
||||
|
||||
If you see "Nothing" to boot, try force resetting the client VM.
|
||||
|
||||
Use SSH to connect to a client VM if booting and parsing the cloud-config succeeded. The CLIENT_IP will be visible in the virt-manager console.
|
||||
|
||||
ssh core@CLIENT_IP # requires ssh_authorized_keys entry in cloud-config
|
||||
|
||||
### Configuration
|
||||
|
||||
TODO
|
||||
|
||||
### Reload
|
||||
|
||||
If you change the Vagrantfile or a configuration variable, reload the VM with
|
||||
|
||||
vagrant reload --provision
|
||||
|
||||
To try a new cloud-config, you can also scp the file onto the dev PXE server.
|
||||
|
||||
scp new-config.yml core@NODE_IP:/var/www/html/pxe-cloud-config.yml
|
||||
81
Vagrantfile
vendored
Normal file
81
Vagrantfile
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# All Vagrant configuration is done below. The "2" in Vagrant.configure
|
||||
# configures the configuration version (we support older styles for
|
||||
# backwards compatibility). Please don't change it unless you know what
|
||||
# you're doing.
|
||||
Vagrant.configure(2) do |config|
|
||||
# The most common configuration options are documented and commented below.
|
||||
# For a complete reference, please see the online documentation at
|
||||
# https://docs.vagrantup.com.
|
||||
|
||||
# Every Vagrant development environment requires a box. You can search for
|
||||
# boxes at https://atlas.hashicorp.com/search.
|
||||
config.vm.box = "fedora/23-cloud-base"
|
||||
|
||||
# Disable automatic box update checking. If you disable this, then
|
||||
# boxes will only be checked for updates when the user runs
|
||||
# `vagrant box outdated`. This is not recommended.
|
||||
# config.vm.box_check_update = false
|
||||
|
||||
# Create a forwarded port mapping which allows access to a specific port
|
||||
# within the machine from a port on the host machine. In the example below,
|
||||
# accessing "localhost:8080" will access port 80 on the guest machine.
|
||||
# config.vm.network "forwarded_port", guest: 80, host: 8080
|
||||
|
||||
# Create a private network, which allows host-only access to the machine
|
||||
# using a specific IP.
|
||||
|
||||
# Brdige Static IP address
|
||||
config.vm.network "public_network", ip: "192.168.32.10", dev: "wlp3s0"
|
||||
|
||||
# Create a public network, which generally matched to bridged network.
|
||||
# Bridged networks make the machine appear as another physical device on
|
||||
# your network.
|
||||
# config.vm.network "public_network"
|
||||
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
libvirt.management_network_name = "vagrant-libvirt"
|
||||
libvirt.management_network_address = "192.168.32.0/24"
|
||||
end
|
||||
|
||||
# Share an additional folder to the guest VM. The first argument is
|
||||
# the path on the host to the actual folder. The second argument is
|
||||
# the path on the guest to mount the folder. And the optional third
|
||||
# argument is a set of non-required options.
|
||||
# config.vm.synced_folder "../data", "/vagrant_data"
|
||||
|
||||
# Provider-specific configuration so you can fine-tune various
|
||||
# backing providers for Vagrant. These expose provider-specific options.
|
||||
# Example for VirtualBox:
|
||||
#
|
||||
# config.vm.provider "virtualbox" do |vb|
|
||||
# # Display the VirtualBox GUI when booting the machine
|
||||
# vb.gui = true
|
||||
#
|
||||
# # Customize the amount of memory on the VM:
|
||||
# vb.memory = "1024"
|
||||
# end
|
||||
#
|
||||
# View the documentation for the provider you are using for more
|
||||
# information on available options.
|
||||
|
||||
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
|
||||
# such as FTP and Heroku are also available. See the documentation at
|
||||
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
|
||||
# config.push.define "atlas" do |push|
|
||||
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
|
||||
# end
|
||||
|
||||
# Provision a PXE Server
|
||||
config.vm.provision :shell, :privileged => true, :path => "scripts/pxe.sh"
|
||||
|
||||
# Enable provisioning with a shell script. Additional provisioners such as
|
||||
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
|
||||
# documentation for more information about their specific syntax and use.
|
||||
# config.vm.provision "shell", inline: <<-SHELL
|
||||
# sudo apt-get update
|
||||
# sudo apt-get install -y apache2
|
||||
# SHELL
|
||||
end
|
||||
78
scripts/pxe.sh
Normal file
78
scripts/pxe.sh
Normal file
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash -e
|
||||
# Setup a minimal PXE Server
|
||||
|
||||
# PXE Server IP should be the static IP set in the Vagrantfile.
|
||||
export NODE_IP=192.168.32.10
|
||||
|
||||
# dnsmasq - your all in one DHCP, TFTP, and DNS
|
||||
dnf install -yq dnsmasq
|
||||
|
||||
cp /etc/dnsmasq.conf /etc/dnsmasq.old
|
||||
cat << EOF > "/etc/dnsmasq.conf"
|
||||
dhcp-range=192.168.32.2,192.168.32.254,12h
|
||||
dhcp-boot=pxelinux.0
|
||||
enable-tftp
|
||||
tftp-root=/var/lib/tftpboot
|
||||
dhcp-authoritative
|
||||
log-queries
|
||||
log-dhcp
|
||||
conf-dir=/etc/dnsmasq.d,.rpmnew,.rpmsave,.rpmorig
|
||||
EOF
|
||||
|
||||
# TFTP
|
||||
|
||||
# Create TFTP root directory
|
||||
if [ ! -d "/var/lib/tftpboot/pxelinux.cfg" ]; then
|
||||
mkdir -p "/var/lib/tftpboot/pxelinux.cfg"
|
||||
fi
|
||||
|
||||
# TFTP pxelinux.cfg
|
||||
cat << EOF > "/var/lib/tftpboot/pxelinux.cfg/default"
|
||||
default coreos
|
||||
prompt 1
|
||||
timeout 15
|
||||
|
||||
display boot.msg
|
||||
|
||||
label coreos
|
||||
menu default
|
||||
kernel coreos_production_pxe.vmlinuz
|
||||
append initrd=coreos_production_pxe_image.cpio.gz cloud-config-url=http://$NODE_IP/pxe-cloud-config.yml
|
||||
EOF
|
||||
|
||||
# TFTP ldlinux.c32 pxelinux.0
|
||||
dnf install -yq syslinux
|
||||
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/pxelinux.0
|
||||
cp /usr/share/syslinux/ldlinux.c32 /var/lib/tftpboot/ldlinux.c32
|
||||
|
||||
# TFTP kernel image and options
|
||||
dnf install -yq wget
|
||||
wget -q -O /var/lib/tftpboot/coreos_production_pxe.vmlinuz http://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe.vmlinuz
|
||||
wget -q -O /var/lib/tftpboot/coreos_production_pxe_image.cpio.gz http://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe_image.cpio.gz
|
||||
restorecon -R /var/lib/tftpboot
|
||||
|
||||
systemctl enable dnsmasq
|
||||
systemctl start dnsmasq
|
||||
|
||||
# HTTP
|
||||
|
||||
# static HTTP server
|
||||
dnf install -yq httpd
|
||||
|
||||
# TODO - this static config is exactly what we can improve upon
|
||||
cat << EOF > "/var/www/html/pxe-cloud-config.yml"
|
||||
#cloud-config
|
||||
coreos:
|
||||
units:
|
||||
- name: etcd2.service
|
||||
command: start
|
||||
- name: fleet.service
|
||||
command: start
|
||||
ssh_authorized_keys:
|
||||
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDp9dypy87zDQgoMm9tk9aKVNDXemN2bp+taQzY4I2BS74H850SjvxVqMHbTcZVi+gMmUev9DPo5xfDOeTPeaT5fnNaKTLNGLezGM0pjMtKWOrZSQqK2YywjT/VdnBvNG6zKHE/MgpexLdkqiPJGPSHhRB+rQ5JX1FL3Qpt9prD2tW8audLmZ6PorC8/HLIwgBIrlh8JFbVFYGEy4dFImz2eyTqNUxDhP2hx17Drvssy/D6HR4zehgP1MGJWOKGfFlE2xe+hy+S6fjkPK5Nc7MR0uqhCkJHpCfVFjbHyZsQK3oi30Afe9t/CdRfPgQW+daeA7yBd1d/56A8QEbRf7W8wO5/CaSBoomA3bufJwwtT50oQwi3r0+hapivvmlUo3WhXwFoPV/XLyQUNGMWKmOWEqqmREFpi/NVnfItU8CenowvDoly0FkreztO4bAAhMd0w4/bAUisRHlucXXifqFEZr5NUt0BIaZmjavbXDadajzhwbK5mWpijuLoiuYCsa+5pQjFVlZRo5f3F3dQ5nREgRSWJPkxzllHygdEeKqxcE4slZJwZbrBgV4OT2nwGjBpfHsbBKBZRM6eKOiDIOVf/hh4+9+GirHWKosv3HRKHH9TisfIFlZoxzxY6E87oPvlf+7rEwHhuaPUoThSXxB6JS9LiOcqxjgL1ltfapgLqQ== dghubble@gmail.com
|
||||
EOF
|
||||
|
||||
systemctl enable httpd
|
||||
systemctl start httpd
|
||||
|
||||
echo "Done"
|
||||
Reference in New Issue
Block a user