PXE Network Boot




#Preboot Execution Environment, used to load operating system over a network connection.


#PXE network boot is achieved through several network protocols, which includes: TFTP, DHCP,IP,HTTP/NFS, etc.


#Now lets begin building our environment(here I used ubuntu(Focal) as my pxe-server).


#STEP 1 :)


#First lets install the required packages:


sudo apt-get install isc-dhcp-server tftpd-hpa syslinux pxelinux apache2 -y


#Download the ISO file as well.(here I tried to install ubuntu-server(20.04) over network.)


#here syslinux is for the bios files, pxelinux for the pxelinux.0 file.



#STEP 2 :)


#Configure tftp base folder:


mkdir /tftpboot


rsync -av /usr/lib/syslinux/modules/bios/{menu.c32,libutil.c32,ldlinux.c32,libcom32.c32}  /tftpboot


mkdir /tftpboot/pxelinux.cfg


touch /tftpboot/pxelinux.cfg/default


mkdir /tftpboot/ubuntu


mount -o loop,ro /PATH_TO_ISO /tftpboot/ubuntu


#add this in /etc/fstab - so that the mount persists  reboot.


/PATH_TO_ISO /tftpboot/ubuntu iso9660 loop 0 0



#STEP 3 :)


#copy pxelinux.0 to our tftpboot folder and give fullpermissions to the folder.


rsync -av /usr/lib/PXELINUX/pxelinux.0 /tftpboot/


chmod 777 -R /tftpboot/



# edit: /etc/default/tftpd-hpa


TFTP_USERNAME="tftp"

TFTP_DIRECTORY="/tftpboot"

TFTP_ADDRESS=":69"

TFTP_OPTIONS="-l -s"


#restart tftpd-hpa


/etc/init.d/tftpd-hpa restart



#STEP 4 :)



#IF req DHCP configuration


# add something like this to /etc/dhcp/dhcpd.conf


subnet 192.168.1.0 netmask 255.255.255.0 {

  range 192.168.1.50 192.168.1.150;

  option domain-name-servers 8.8.8.8;

  option subnet-mask 255.255.255.0;

  option routers 192.168.1.1;

  option broadcast-address 192.168.1.255;

  default-lease-time 600;

  max-lease-time 7200;

  filename "pxelinux.0";


}


#if your pxe-server is not your dhcp-server add the following in the dhcp-server


filename "pxelinux.0";

next server pxe-server-IP;


# edit your /etc/default/isc-dhcp-server to let the dhcp server know on which interface to work on(for me its eth0)


INTERFACESv4="eth0"


#restart dhcp-service


systemctl restart isc-dhcp-server


#STEP 5 :)


#Edit your /tftpboot/pxelinux.cfg/default



UI menu.c32  


LABEL 1

MENU LABEL ubuntu_installation

KERNEL ubuntu/casper/vmlinuz

INITRD ubuntu/casper/initrd

APPEND url=http://pxe-server-ip/ubuntu/ubuntu.iso ip=dhcp autoinstall 

 



#restart tftpd-hpa


#STEP 6 :)


#Now configure you apache2 server


#First start your apache2 and delete the index.html from /var/www/html/index.html

  mkdir /var/www/html/ubuntu

# we will discuss thi ks folder later(only req if your want to configure kick start files)

  mkdir /var/www/html/ks


rsync -av /PATH_TO_ISO /var/www/html/ubuntu/

#then

chmod -R 777 /var/www/html/ubuntu/


#STEP 7 :)


#restart all services and start the network boot.







#Now you could automate the installtion using cloud-init.

#steps as follows:


#STEP 1 :)


#add the following in your /var/www/html/ks/ folder


nano /var/www/html/ks/user-data


#add the following configurations found for ubuntu 20.04: https://github.com/vrillusions/ubuntu-kickstart/blob/master/20.04/user-data.full


#refer this if you want to make cloud-init user-data conf file: https://www.golinuxcloud.com/generate-user-data-file-ubuntu-20-04/


nano /var/www/html/ks/meta-data


# the pxe-server hostname

instance-id: pxe-server


chmod -R 777 /var/www/html/ks/



#STEP 2 :)


#Edit your /tftpboot/pxelinux.cfg/default



UI menu.c32  


LABEL 1

MENU LABEL ubuntu_installation

KERNEL ubuntu/casper/vmlinuz

INITRD ubuntu/casper/initrd

APPEND url=http://pxe-server-ip/ubuntu/ubuntu.iso ip=dhcp autoinstall ds=nocloud-net;s=http://pxe-server-ip/ks/ cloud-config-url=/dev/null fsck.mode=skip ---



#restart all services; and update firewall rules to allow the required ports.


Comments

Post a Comment

Popular posts from this blog