Search

Recent Posts

Tags


« | Main | »

Cobbler/Linux OS Provisioning via Virtual NICs (VirtualBox)

By Dale Reagan | October 27, 2008

This seems to be a topic of interest so here is a bit more information about using Cobbler to provision Linux systems under VirtualBox.  The steps are fairly simple and allow you to use virtual NICS to reach your Cobbler server.   To use this information you need:  a) a system with an operating Cobbler install and b) Linux VMs configured within VirtualBox.

Within Cobbler you can match an OS profile (i.e. web server, mail server, dB server, etc.) to the MAC address of each VM appropriately configured under VirtualBox.   This is one approach for automating portions of the process for establishing PXE-boot information within Cobbler when using VMs managed by VirtualBox.  Note that the steps outlined below require root level access; also, within a highly automated environment (i.e. your friendly Compute Cloud of choice) all of these steps would be automated. 

  1. create a virtual network bridge interface
  2. create a number of virutal interfaces for use with virtual machines (VMs) under VirtualBox.
  3. within VirtualBox, for each VM that you want to PXE boot, assign a specific ‘vbox’ interface to your virtual machine;  (Settings–>> Network –>> Attached to:  Host Interface; Interface Name:  vbox(number), where ‘number’ is from 0 to 9 – see below) 
  4. extract the MAC network IDs and create entires under Cobbler that match (instead of manually entering them;  See script below)
  5. configure Cobbler to use the bridge NIC for provisioning (i.e. listen for PXE requests) OR if you are already using it, add a ‘real’ interface (i.e. eth1) to the bridge and then you can provision both bare metal and virtual systems without additional networking changes (i.e. modifications to your DNS/DHCP configuration.)  You may also need to adjust other IP ranges within the /etc/cobbler/settings or /etc/cobbler/[dnsmasq|dhcp].template files.

The goal is to auto-generate both system names and assign IP addresses and use the same MAC/IP informatino within Cobbler – something like:

192.168.8.86    virt-fc8-2C-82  virt-fc8-2C-82.bootnet  ### vbox0
192.168.8.87    virt-fc8-CD-A4  virt-fc8-CD-A4.bootnet  ### vbox1
192.168.8.88    virt-fc8-ED-2C  virt-fc8-ED-2C.bootnet  ### vbox2
192.168.8.89    virt-fc8-67-9B  virt-fc8-67-9B.bootnet  ### vbox3
192.168.8.90    virt-fc8-0E-6A  virt-fc8-0E-6A.bootnet  ### vbox4

Steps one and two follow:

### disable the bridge if present
ifconfig virbr0 down 2> /dev/null
### create the bridge if missing
brctl addbr virbr0 2> /dev/null
brctl stp virbr0 on
### assing an IP to the bridge interface
ifconfig virbr0 192.168.8.5
### activate the interface
ifconfig virbr0 up
#######################################################
### delete then (re-)create virtual network interfaces
### new NIC MACs will be created each time to run this so you
### probably will only do this once for any given range
for NUM in 1 2 3 4 5 6 7 8 9 0; do      VBoxDeleteIF vbox${NUM}; done
for NUM in 1 2 3 4 5 6 7 8 9 0; do      VBoxAddIF vbox${NUM} dale ; done
#######################################################
### loop through the list of VBOX interfaces and add them to the network bridge
for VBOX in $(ifconfig | awk ‘/vbox/ {print $1}’) ; do  brctl addif virbr0 ${VBOX}; done
#######################################################
### set permissions for the ‘tun’ device (depends on your system!)
chown vboxuser:vboxusers /dev/net/tun
ls -ld /dev/net/tun

 To see a list of ‘vboxen’ you can use the following command:

VBoxManage list vms | awk ‘/vbox/ {print $3, $4, $8}’

The output should something like:

MAC: 080027560E6A, ‘vbox4′,
MAC: 00FFDB1F2C82, ‘vbox0′,
MAC: 00FFCE9BCDA4, ‘vbox1′,
MAC: 00FFEEC9ED2C, ‘vbox2′,
MAC: 00FFAD69679B, ‘vbox3′,

To convert this MAC format to what Cobbler uses I use a little Awk sub-string magic:

VBoxManage list vms | awk ‘/vbox/ {printf “%s  %s:%s:%s:%s:%s:%s\n”, $8, substr($4,1,2), substr($4,3,2), substr($4,5,2), substr($4,7,2), substr($4,9,2), substr($4,11,2)}’ | sed -e “s/[\',\,]//g” | sort

 The output should be something like:

vbox0  00:FF:DB:1F:2C:82
vbox1  00:FF:CE:9B:CD:A4
vbox2  00:FF:EE:C9:ED:2C
vbox3  00:FF:AD:69:67:9B
vbox4  08:00:27:56:0E:6A

I take the output above and pipe it to a function that creates Cobbler commands.  Here is a sample script that puts these steps together.  The output can be redirected to a file which can be edited or run as a script to create your system entries within Cobbler.

= – = – = Start of Script  Step 4 (if you copy this start with the ‘bash’ line…)
#!/bin/bash
#######################################################
## http://web-tech.ga-usa.com/ – Dale Reagan
## sample script to generate Cobbler system add lines
## note – this is a starting point, not a complete script
## there is little/no error checking and the output will
## vary based on your OS, VirtualBox and Cobbler setup
#######################################################
###
function list_vboxen {
VBoxManage list vms | awk ‘/vbox/ {printf “%s  %s:%s:%s:%s:%s:%s\n”, $8, substr($4,1,2), substr($4,3,2), substr($4,5,2), substr($4,7,2), substr($4,9,2), substr($4,11,2)}’ | sed -e “s/[\',\,]//g” | sort
}
###
function add_cobbler_system {
GATE=192.168.8.5
SUB_NET=255.255.255.0
COB_NAME=${NSYS}
HOST=”virt-${COB_NAME}”
MAC=$(list_vboxen | grep ${OMAC} | awk ‘{print $NF}’)
OPT_B=”–hostname=${HOST} –ip=${IP} –mac=${MAC} –name=${COB_NAME}”
OPT_A=”–netboot-enabled=1 –subnet=${SUB_NET} –gateway=${GATE}”
OPT_C=”–profile=${PROFILE}”
echo “## ${PROFILE} ##”
echo “cobbler system add ${OPT_A} ${OPT_B} ${OPT_C}”
echo ” ”
}
###
function create_cobbles {
declare int VBOX=0
for SYS in $(list_vboxen | awk ‘/^vbox/ {print $NF}’ | awk -F “:” ‘{printf “%s-%s\n”, $5,$6}’)
do
        COUNT=$((COUNT+1))
        IP=192.168.8.${COUNT}
        NSYS=”fc8-${SYS}”
        OMAC=$(echo ${SYS}|tr “-” “:”)
        printf “#Sys: ${NSYS} | ${OMAC} | ${SYS} | ${IP} ## vbox${VBOX}\n”
        add_cobbler_system
        VBOX=$((VBOX+1))
done
}
###
########## select the first Cobbler profile
PROFILE=$(cobbler report –what=profiles | awk ‘/profile/ {print $NF}’ | head -1)
##########
### start with this number for IPs
COUNT=125
### generate the Cobbler commands
case “$1″
in
        list) list_vboxen ;;  ## show my list of vboxen
        create) create_cobbles ;;
        *) create_cobbles ;;
esac

### = – = – = – = END of script

Sample output from the script above:

#Sys: fc8-2C-82 | 2C:82 | 2C-82 | 192.168.8.126 ## vbox0
## FC-8-full_install ##
cobbler system add –netboot-enabled=1 –subnet=255.255.255.0 –gateway=192.168.
8.5 –hostname=virt-fc8-2C-82 –ip=192.168.8.126 –mac=00:FF:DB:1F:2C:82 –name=
fc8-2C-82 –profile=FC-8-full_install

#Sys: fc8-0E-6A | 0E:6A | 0E-6A | 192.168.8.130 ## vbox4
## FC-8-full_install ##
cobbler system add –netboot-enabled=1 –subnet=255.255.255.0 –gateway=192.168.
8.5 –hostname=virt-fc8-0E-6A –ip=192.168.8.130 –mac=08:00:27:56:0E:6A –name=
fc8-0E-6A –profile=FC-8-full_install

If you use the script, then make sure to change the network settings to values appropriate for your network environment.

Topics: Computer Technology, Unix-Linux-Os, Virtual-Cloud Computing, Web Problem Solving, Web Technologies | 1 Comment »

One Response to “Cobbler/Linux OS Provisioning via Virtual NICs (VirtualBox)”

  1. Michael DeHaan Says:
    December 3rd, 2008 at 11:29 am

    Hi Dale,

    Just found this during some random Googling.

    If you’d be interested in adding virtual box to Cobbler/koan properly (with a new virtual type) we’d be glad to have it.

    This may also be easier than the above steps for repeated use.

    Mailing list lives here: https://fedorahosted.org/mailman/listinfo/cobbler

    –Michael


________________________________________________
YOUR GeoIP Data | Ip: 54.197.171.109
Continent: NA | Country Code: US | Country Name: United States
Region: WA | State/Region Name: Washington | City: Seattle
(US only) Area Code: 206 | Postal code/Zip: 98109
Latitude: 47.634399 | Longitude: -122.342201
Note - if using a mobile device your physical location may NOT be accurate...
________________________________________________

Georgia-USA.Com - Web Hosting for Business
____________________________________