[PXE] 서버 구축 - 1 (BIOS 장비를 부팅시켜보자)
PXE 기술을 누군가에게 설명을 할 필요가 있어서, 다시 적어보는 글이다.
Ubuntu 24.04 LTS 버전을 기준으로 작성한다.
먼저 필요한 패키지는 다음과 같다.
Packages
isc-dhcp-server -> IP 할당 및 DHCP Option 66,67에 대한 응답용
tftpd-hpa -> Bootloader file 전송용
nfs-kernel-server -> Bootloader 전송 이후의 파일 전송용
apache2 -> Autoinstall / kickstart 파일 전송용
pxelinux -> Legacy (BIOS)용 bootloader
sudo apt install -y isc-dhcp-server tftpd-hpa nfs-kernel-server apache2 pxelinux
로 한번에 설치가 가능하다.
Directory List
/tftpboot : TFTP Server Root Directory
/tftpboot/pxelinux.cfg : BIOS (Legacy) 환경의 Default directory
/tftpbood/boot : UEFI 환경의 Default directory
/data/os : ISO를 마운트 후 통째로 복사 해 둔 Directory
/var/www/html : Apache2 Web Server Default directory (autoinstall, kickstart용)
pxeliunx
먼저 /tftpboot 디렉터리를 생성한다.
mkdir /tftpboot
pxelinux는 apt로 설치 하게되면, 파일들이 나눠서 설치 되는데,
메인이 되는 pxelinux.0는
/usr/lib/PXELINUX/pxelinux.0
에 있고, 메뉴와 모듈들은
/usr/lib/syslinux/modules/bios/
안에 있다.
다음 명령어로 필요한 파일들을 /tftpboot에 복사한다.
cp /usr/lib/PXELINUX/pxelinux.0 /tftpboot/
cp /usr/lib/syslinux/modules/bios/{ldlinux,libutil,menu}.c32 /tftpboot/
다음과 같이 되면 된다.
dobob@dobob-PXE:/tftpboot# ll
total 220
drwxrwxrwx 2 root root 4096 Dec 2 17:39 ./
drwxr-xr-x 24 root root 4096 Dec 2 17:39 ../
-rw-r--r-- 1 root root 118676 Dec 2 17:39 ldlinux.c32
-rw-r--r-- 1 root root 23736 Dec 2 17:39 libutil.c32
-rw-r--r-- 1 root root 26084 Dec 2 17:39 menu.c32
-rw-r--r-- 1 root root 42392 Dec 2 17:39 pxelinux.0
DHCP Server
/etc/dhcp/dhcpd.conf
# Global DHCP Configuration
authoritative;
default-lease-time 600;
max-lease-time 7200;
# PXE Boot Configuration
allow booting;
allow bootp;
# PXE Architecture Detection
option client-architecture code 93 = unsigned integer 16;
#Subnet decleration
subnet 172.16.0.0 netmask 255.255.255.0 {
range 172.16.0.2 172.16.0.254;
option subnet-mask 255.255.255.0;
option broadcast-address 172.16.0.255;
option routers 172.16.0.1;
option domain-name-servers 1.1.1.1, 8.8.8.8;
#tftpd server address
next-server 172.16.0.1;
# UEFI x86-64
if option client-architecture = 00:07 {
filename "grubx64.efi";
}
elsif option client-architecture = 00:09 {
filename "grubx64.efi";
}
# Legacy BIOS
else {
filename "pxelinux.0";
}
}
Next-server 부분이 중요하며, 해당 IP에서 tftp 서버가 있어야만 한다.
UEFI x86-64는 UEFI시 불러오는 grub2부트로더를 가져올때 사용하는 구문이다.
isc-dhcp-server interface 지정
/etc/default/isc-dhcp-server
1 # Defaults for isc-dhcp-server (sourced by /etc/init.d/isc-dhcp-server)
2
3 # Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
4 #DHCPDv4_CONF=/etc/dhcp/dhcpd.conf
5 #DHCPDv6_CONF=/etc/dhcp/dhcpd6.conf
6
7 # Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
8 #DHCPDv4_PID=/var/run/dhcpd.pid
9 #DHCPDv6_PID=/var/run/dhcpd6.pid
10
11 # Additional options to start dhcpd with.
12 # Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
13 #OPTIONS=""
14
15 # On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
16 # Separate multiple interfaces with spaces, e.g. "eth0 eth1".
17 INTERFACESv4="eth1"
18 INTERFACESv6=""
위와 같이 있을 때 INTERFACEv4=에 실제 사용할 인터페이스, 즉 DHCP를 뿌려줄 Interface를 지정해준다.
tftpd-hpa
/etc/default/tftpd-hpa
1 # /etc/default/tftpd-hpa
2
3 TFTP_USERNAME="tftp"
4 TFTP_DIRECTORY="/tftpboot"
5 TFTP_ADDRESS=":69"
6 TFTP_OPTIONS="--secure"
4번째 줄을 /tftpboot으로 수정한다.
이후 service를 재 시작 하여 적용한다.
sudo systemctl restart tftpd-hpa
NFS Server
ISO파일을 그대로 옮겨둔 디렉터리인 /data/os를 사용하기 위해 디렉터리를 생성한다.
mkdir -p /data/os
이후 NFS를 클라이언트에서 Mount시킬 수 있게 /etc/exports/ 에 다음과 같이 추가한다.
/etc/exports
/data/os 172.16.0.0/24(ro,sync,no_subtree_check)
이후 다음 명령어로 적용 후 Service를 Restart한다.
sudo exportfs -ra
sudo systemctl restart nfs-kernel-server
위와 같이 완료 했으면, 일단 서비스로 실행되는 부분은 모두 완료 된 것이다.
이제 세부적인 설정을 진행하도록 하자.
현 상황에서 PXE Booting을 하게 되면 다음과 같이 보이게 된다.

PXE (BIOS) Menu
/tftpboot/pxelinux.cfg 디렉터리를 하나 생성한다.
mkdir -p /tftpboot/pxelinux.cfg
이후 해당 디렉터리 아래 default라는 파일을 만들고, 아래 내용을 넣는다.
default menu.c32
prompt 0
timeout 100
menu title OS SELECTION MENU
label local
menu label Boot local disk
localboot 0
label ubuntu-24.04LTS-Server
menu label Install Ubuntu 20.04 LTS
kernel vmlinuz_2404
APPEND root=/dev/nfs boot=casper maybe-ubiquity netboot=nfs ip=dhcp nfsroot=172.16.0.1:/data/os/ubuntu2404 initrd=initrd_2404
여기서 제일 먼저 살펴볼 곳은 kernel과 initrd부분이다.
kernel과 initrd는 Ubuntu24.04 AMD64 Server ISO안에 있는 파일에서 가져와서 이름을 바꾼다.
sudo mount ubuntu-24.04.5-live-server-amd64.iso /mnt
cp /mnt/casper/{initrd,vmlinuz} /tftpboot
위와 같이, 뒤에 태그를 붙혀서 관리하는게 편하다. 다른 배포판, 즉 RHEL기반에서는 또 다른 이미지를 사용하기에, 뒤에 태그를 붙혀 vmlinuz와 initrd를 관리 하는 편이 좋다.
nfsroot의 주소는 nfs서버가 돌아가고 있는 주소로 대체하고, 경로는 /data/os/하위경로 로 정한다.
하위 경로에는 ISO파일을 마운트 한 부분을 전부 cp명령을 통하여 옮겨야한다. (.disk 디렉터리도 확실히 옮겨졌는지 확인 해야한다.)
위 step을 완료하면, BIOS환경에서는 다음과 같이 OS SELECTION 화면이 나오게 된다.
