Skip to content

Instantly share code, notes, and snippets.

@luckylittle
Last active July 29, 2021 01:03
Show Gist options
  • Save luckylittle/0cc58b9362a11cb50ce471a4b1a52736 to your computer and use it in GitHub Desktop.
Save luckylittle/0cc58b9362a11cb50ce471a4b1a52736 to your computer and use it in GitHub Desktop.
Configuration of PXE Boot & Repository server in VirtualBox for automated install of RHEL 8.2 (VirtualBox <-> laptop)
default menu.c32
prompt 0
timeout 300
ONTIMEOUT local
label 1
menu label ^1) Install RHEL 8 with Local Repo
kernel rhel8/vmlinuz
append initrd=rhel8/initrd.img method=http://192.168.130.2/rhel8 devfs=nomount
label 2
menu label ^2) Boot from local drive
#interface=eth1
#bind-interfaces
domain=localhost.localdomain.local
#DHCP range-leases
dhcp-range=192.168.130.10,192.168.130.11,255.255.255.0,1h
#PXE
dhcp-boot=pxelinux.0,pxeserver,192.168.130.2
#Gateway
dhcp-option=3,192.168.130.2
#DNS
dhcp-option=6,192.168.130.2,8.8.8.8
server=8.8.4.4
#Broadcast address
dhcp-option=28,192.168.130.255
#NTP server
dhcp-option=42,0.0.0.0
pxe-prompt="Press F8 for menu.",30
pxe-service=x86PC,"Install RHEL 8 from PXE server 192.168.130.2",pxelinux
enable-tftp
tftp-root=/var/lib/tftpboot
HWADDR=08:00:27:47:52:54
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=192.168.130.2
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME="Wired connection 1"
UUID=7c5b0265-464a-3b3d-9c42-88499a09aaf0
ONBOOT=yes
AUTOCONNECT_PRIORITY=-999
DNS1=8.8.4.4
IPADDR1=192.168.130.2
PREFIX1=32
#!/bin/bash
sudo su -
# NetworkManager
nmcli con mod Wired\ connection\ 1 ipv4.method static
nmcli con mod Wired\ connection\ 1 ipv4.address 192.168.130.2
nmcli con up Wired\ connection\ 1
# DNSMasq
dnf install dnsmasq -y
mv /etc/dnsmasq.conf /etc/dnsmasq.conf.backup
cp -v dnsmasq.conf /etc/
# Syslinux
dnf install syslinux -y
# TFTP
dnf install tftp-server -y
cp -rv /usr/share/syslinux/* /var/lib/tftpboot
mkdir /var/lib/tftpboot/pxelinux.cfg
cp -v default /var/lib/tftpboot/pxelinux.cfg/
# Assign optical disc rhel-8.2-x86_64-dvd.iso in VirtualBox to the machine
mount /dev/sr0 /mnt
mkdir /var/lib/tftpboot/rhel8
cp -v /mnt/images/pxeboot/vmlinuz /var/lib/tftpboot/rhel8
cp -v /mnt/images/pxeboot/initrd.img /var/lib/tftpboot/rhel8
# Apache
dnf install httpd -y
setenforce 0
mkdir /var/www/html/rhel8
# Do not forget to copy the hidden files (e.g. .treeinfo), they are important!
cp -rvT /mnt /var/www/html/rhel8
chown -Rv apache:apache /var/www/html/rhel8
# Start services
systemctl stop firewalld
systemctl disable firewalld
systemctl start dnsmasq
systemctl start httpd
systemctl enable dnsmasq
systemctl enable httpd
# Test Apache2
curl http://localhost/rhel8/.treeinfo
@luckylittle
Copy link
Author

luckylittle commented Jul 28, 2021

This was working for me with Fedora 34 & UEFI

Scenario: Desktop computer <--> Laptop via Ethernet cable, peer to peer. VirtualBox Fedora 34 is used as PXE boot & DHCP.

  1. Have 2x NICs in your Fedora 34 Server VirtualBox machine, one is bridged Ethernet (eno1), one is bridged WiFi (wlp0s20u3i2).
  2. Mount Fedora-Server-dvd-x86_64-34-1.2.iso to the VirtualBox machine.
  3. Configure the interface bridged to Ethernet to have static IPv4 address 192.168.1.1/24, default gateway 192.168.1.2 via nmcli.
    Run:
  • Install the tools dnf install tftp-server dhcp httpd
  • Install & export shim dnf install shim-x64 grub2-efi-x64 --installroot=/tmp/fedora --releasever 34
  • Create UEFI folder in tftpboot mkdir -p /var/lib/tftpboot/uefi
  • Copy shim to the UEFI folder on tftpboot cp /tmp/fedora/boot/efi/EFI/fedora/{shimx64.efi,grubx64.efi} /var/lib/tftpboot/uefi/
  • Get vmlinuz image wget https://download.fedoraproject.org/pub/fedora/linux/releases/34/Server/x86_64/os/images/pxeboot/vmlinuz -O /var/lib/tftpboot/vmlinuz
  • Get initrd image wget https://download.fedoraproject.org/pub/fedora/linux/releases/34/Server/x86_64/os/images/pxeboot/initrd.img -O /var/lib/tftpboot/initrd.img
  • Copy all files from the Fedora Server image to the Apache server cp -rvT /mnt /var/www/html/f34
  • Create vi /etc/dhcp/dhcpd.conf:
subnet 192.168.1.0 netmask 255.255.255.0 {
 authoritative;
 default-lease-time 60;
 max-lease-time 120;
 ddns-update-style none;
 option domain-name-servers 192.168.1.1;
 option routers 192.168.1.1;
 range 192.168.1.2 192.168.1.255;
 filename "uefi/shimx64.efi";
 next-server 192.168.1.1;
}
  • Create vi /var/lib/tftpboot/uefi/grub.cfg:
function load_video {
        insmod efi_gop
        insmod efi_uga
        insmod video_bochs
        insmod video_cirrus
        insmod all_video
}

load_video
set gfxpayload=keep
insmod gzio

menuentry 'Exit this grub' {
        exit
}

menuentry 'Install Fedora 64-bit'  --class fedora --class gnu-linux --class gnu --class os {
        linuxefi vmlinuz ip=dhcp inst.repo=http://192.168.1.1/f34
        initrdefi initrd.img
}
  • Disable + stop firewalld and start + enable dhcpd & tftp.socket & tftp.service & httpd.
  • Make sure cable is connected between desktop and the laptop. Boot laptop from the network. Laptop will get 192.168.1.2 address via DHCP and automatically load NBP filename uefi/shimx64.efi and start the boot & installation process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment