Skip to content

Instantly share code, notes, and snippets.

@epcim
Forked from tuxfight3r/ipxe_with_dhcp.txt
Created April 13, 2023 08:33
Show Gist options
  • Save epcim/725bec33141eaad8aa2bfca99b52403e to your computer and use it in GitHub Desktop.
Save epcim/725bec33141eaad8aa2bfca99b52403e to your computer and use it in GitHub Desktop.
ipxe kickstart over http - dhcp and static configuration
#clone the repo
git clone http://git.ipxe.org/ipxe.git
cd ipxe/src
cat >ubuntu-amd64-installer.ipxe <<EOF
#!ipxe
dhcp
echo Starting Ubuntu x64 installer for ${hostname}
set base-url http://archive.ubuntu.com/ubuntu/dists/trusty/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64
kernel ${base-url}/linux
initrd ${base-url}/initrd.gz
#NOTE: make sure you update the LOCAL_NETWORK_IP and preseed file present there
imgargs linux auto=true url=http://LOCAL_NETWORK_IP/preseed.cfg
boot ||
# If everything failed, give the user some options
echo Boot from ${base-url} failed
prompt --key 0x197e --timeout 2000 Press F12 to investigate || exit
shell
EOF
#create iso file for use
make bin/ipxe.iso EMBED=./ubuntu-amd64-installer.ipxe
#create usb bootable
make bin/ipxe.usb EMBED=./ubuntu-amd64-installer.ipxe
#transfer the usb image to your usbdisk
#Note: XX is your usbdevice id.
dd if=bin/ipxe.usb of=/dev/sdXX
#clone the repo
git clone http://git.ipxe.org/ipxe.git
cd ipxe/src
cat >ubuntu-amd64-installer.ipxe <<EOF
#!ipxe
#static ip settings
ifopen net0
set net0/ip 192.168.1.240
set net0/netmask 255.255.255.0
set net0/gateway 192.168.1.1
set dns 192.168.1.1
set hostname puppet1
set domain_name domain.local
#dhcp
echo "Configured IP Details:"
show net0/ip
show net0/netmask
show net0/gateway
show dns
show hostname
show domain_name
route
set menutimeout 5
echo Starting Ubuntu x64 installer for ${hostname}
set base-url http://archive.ubuntu.com/ubuntu/dists/trusty/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64
kernel ${base-url}/linux priority=critical
initrd ${base-url}/initrd.gz
#NOTE: make sure you update the LOCAL_NETWORK_IP and preseed file present there
imgargs linux auto=true url=http://LOCAL_NETWORK_IP/preseed.cfg interface=eth0 hostname=${hostname} domain=${domain_name} netcfg/disable_dhcp=true netcfg/get_ipaddress=${net0/ip} netcfg/get_netmask=${net0/netmask} netcfg/get_gateway=${net0/gateway} netcfg/get_nameservers=${dns}
boot ||
# If everything failed, give the user some options
echo Boot from ${base-url} failed
prompt --key 0x197e --timeout 2000 Press F12 to investigate || exit
shell
EOF
#create iso file for use
make bin/ipxe.iso EMBED=./ubuntu-amd64-installer.ipxe
#create bootable iso for vmware
make bin/8086100f.mrom bin/808610d3.mrom bin/10222000.rom bin/15ad07b0.rom bin/ipxe.iso EMBED=./ubuntu-amd64-installer.ipxe
#create usb bootable
make bin/ipxe.usb EMBED=./ubuntu-amd64-installer.ipxe
#transfer the usb image to your usbdisk
#Note: XX is your usbdevice id.
dd if=bin/ipxe.usb of=/dev/sdXX
#!ipxe
#static ip settings
ifopen net0
set net0/ip 192.168.1.100
set net0/netmask 255.255.255.0
set net0/gateway 192.168.1.2
set dns 192.168.1.2
set hostname puppet1
set domain_name domain.local
set repo_server 192.168.1.240
set preseed_file preseed.cfg
#dhcp
set menu-timeout 10000
menu iPXE boot menu
item
item ubuntu_netboot_14_04 Install Ubuntu Trusty 14.04
item reboot_ipxe Reboot iPXE Menu
item debug_ipxe Debug iPXE Network Connectivity
item
choose --timeout ${menu-timeout} --default ubuntu_netboot_14_04 target && goto ip_details || goto debug_ipxe
:ip_details
# If everything failed, give the user some options
echo Entering to shell for Debug
echo "Configured IP Details:"
show net0/ip
show net0/netmask
show net0/gateway
show dns
show hostname
show domain_name
show repo_server
show preseed_file
route
goto ${target}
:ubuntu_netboot_14_04
echo Starting Ubuntu Trusty 14.04_x64 installer for ${hostname}
set base-url http://archive.ubuntu.com/ubuntu/dists/trusty/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64
kernel ${base-url}/linux priority=critical
initrd ${base-url}/initrd.gz
imgargs linux auto=true url=http://${repo_server}/${preseed_file} interface=eth0 hostname=${hostname} domain=${domain_name} netcfg/disable_dhcp=true netcfg/get_ipaddress=${net0/ip} netcfg/get_netmask=${net0/netmask} netcfg/get_gateway=${net0/gateway} netcfg/get_nameservers=${dns}
boot ||
:debug_ipxe
#for ping/nslookup to work enable ping/nslookup command in config.h while buidling ipxe
echo "Interface Stat: net0"
ifstat net0
echo "Ping to gateway ${net0/gateway} should work from here"
shell
:reboot_ipxe
echo "press any key to reboot"
exit
#create iso file for use
#make bin/ipxe.iso EMBED=./ubuntu-amd64-installer.ipxe
#create bootable iso for vmware
#make bin/8086100f.mrom bin/808610d3.mrom bin/10222000.rom bin/15ad07b0.rom bin/ipxe.iso EMBED=./ubuntu-amd64-installer.ipxe
#create usb bootable
#make bin/ipxe.usb EMBED=./ubuntu-amd64-installer.ipxe
#transfer the usb image to your usbdisk
#Note: XX is your usbdevice id.
#dd if=bin/ipxe.usb of=/dev/sdXX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment