Tuesday, June 28, 2016

easy and fast way to setup ubuntu net install using pxe, tftp + dhcp

*** setup information ***
- interface to provide net install to client: vmnet2, ip address 192.168.13.1


1- install necessary packages
$ sudo apt-get install pxelinux syslinux dnsmasq

2- create a directory to store all data
$ mkdir ~/ubuntutftp && cd ~/ubuntutftp

3- download linux kernel and initram from ubuntu repository
ubuntu have release many versions over the years, you choose the one you want,
some of the latest are precise, trusty, xenial and yakkety

- example i want yakkety
$ export dist=yakkety
$ wget wget http://archive.ubuntu.com/ubuntu/dists/$dist/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/linux
$ wget http://archive.ubuntu.com/dists/$dist/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/initrd.gz


4- copy necessary file to our directory,
$ cp /usr/lib/PXELINUX/pxelinux.0 ~/ubuntutftp
$ cp /usr/lib/syslinux/modules/bios/*.c32 ~/ubuntutftp

5- update boot menu
$ mkdir pxelinux.cfg

- create file ~/ubuntutftp/pxelinux.cfg/default with the following content
default menu.c32
prompt 0
timeout 300
ONTIMEOUT local
menu title ########## PXE Boot Menu ##########
label 1
menu label ^1) install ubuntu net install
kernel linux
append initrd=initrd.gz
menu label ^2) install ubuntu netinstall


6- create script file to start our tftp, dhcp name it as dnsmasq-tftp.sh with content below
#/bin/bash
ifconfig vmnet2 192.168.13.1 up
dnsmasq -i vmnet2 --dhcp-range=192.168.13.100,192.168.13.200 \
    --dhcp-boot=pxelinux.0 \
    --enable-tftp --tftp-root=/home/user1/ubuntutftp/ -d -p0 -K --log-dhcp --bootp-dynamic


7- start our ubuntu net install instance
$ sudo sh dnsmasq-tftp.sh 


now when we connect a client with the same network segment with our server, and choose to boot from NIC, then they will get the install screen as below, and follow the scree to install ubuntu



No comments:

Post a Comment