본문 바로가기

리눅스

우분투 24.04에서 PXE 부팅을 통해 cloud-init 기반의 Autoinstall을 사용하여 운영체제를 설치하는 방법

반응형

우분투 24.04에서 PXE 부팅을 통해 cloud-init 기반의 Autoinstall을 사용하여 운영체제를 설치하는 방법

PXE 서버 구성

필수 패키지 설치

sudo apt update

sudo apt install -y dnsmasq syslinux-common pxelinux ipxe \
  whois curl

설치되는 주요 패키지

  • dnsmasq: DHCP + TFTP + DNS 통합 서버
  • syslinux-common, pxelinux: Legacy BIOS 부팅 지원
  • ipxe: 네트워크 부팅 펌웨어
  • whois: 패스워드 해시 생성용

TFTP 루트 디렉토리 구성

  • TFTP는 부팅 파일을 전송하는 프로토콜입니다.
sudo mkdir -p /srv/tftp
sudo chown -R dnsmasq:nogroup /srv/tftp
sudo chmod -R 755 /srv/tftp

부팅 바이너리 복사

  • Legacy BIOS 및 UEFI 부팅을 모두 지원하도록 필요한 파일들을 복사합니다.
# iPXE 바이너리 (Legacy & UEFI)
sudo cp /usr/lib/ipxe/undionly.kpxe /srv/tftp/
sudo cp /usr/lib/ipxe/snponly.efi /srv/tftp/

# SYSLINUX 모듈
sudo cp /usr/lib/syslinux/modules/bios/ldlinux.c32 /srv/tftp/

HTTP 서버 구성

Nginx 설치

sudo apt install -y curl gnupg2 ca-certificates lsb-release ubuntu-keyring
curl -fsSL https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

sudo apt update
sudo apt install -y nginx
sudo systemctl enable --now nginx

Nginx 웹 서버 설정

  • 기존 설정 파일을 백업하고 PXE용 설정을 생성합니다.
sudo mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.backup
sudo tee /etc/nginx/conf.d/pxe-server.conf > /dev/null << 'EOF'
server {
    listen 80 default_server;
    server_name _;
    root /usr/share/nginx/html;
    autoindex on;
    
    # 큰 파일 다운로드 지원
    client_max_body_size 10G;
    
    # ISO 파일 캐싱 설정 (성능 향상)
    location ~* \.(iso|img|vmlinuz|initrd)$ {
        expires 30d;
        add_header Cache-Control "public, immutable";
    }
    
    # 부팅 스크립트는 캐싱하지 않음
    location ~* \.(ipxe|cfg)$ {
        expires off;
        add_header Cache-Control "no-cache, no-store, must-revalidate";
    }
    
    # Cloud-Init 설정 파일
    location /autoinstall/ {
        add_header Content-Type text/plain;
    }
}
EOF

운영체제 파일 준비

디렉토리 구조 생성

sudo mkdir -p /usr/share/nginx/html/{iso,ubuntu/24.04}

우분투 24.04 ISO 다운로드 및 추출

cd /usr/share/nginx/html/iso
wget https://releases.ubuntu.com/noble/ubuntu-24.04.3-live-server-amd64.iso

임시 마운트 디렉토리 생성 및 ISO 마운트

sudo mkdir /mnt/iso
sudo mount -o loop,ro ubuntu-24.04.3-live-server-amd64.iso /mnt/iso
sudo cp /mnt/iso/casper/{vmlinuz,initrd} /usr/share/nginx/html/
sudo rsync -az /mnt/iso/{pool,dists,install} /usr/share/nginx/html/ubuntu/24.04/.
sudo umount /mnt/iso
728x90

부팅 설정

PXE 부팅 메뉴 설정(PXELINUX)

sudo mkdir -p /srv/tftp/pxelinux.cfg
sudo vim /srv/tftp/pxelinux.cfg/default
sudo tee /srv/tftp/pxelinux.cfg/default > /dev/null << 'EOF'
DEFAULT menu.c32
PROMPT 0
TIMEOUT 300
ONTIMEOUT ubuntu-24.04-autoinstall
MENU TITLE Ubuntu 24.04 PXE Install
MENU AUTOBOOT Starting automatic install in # seconds

# 메뉴 색상 설정
MENU COLOR screen 37;40      #80ffffff #00000000 std
MENU COLOR border 30;44      #40000000 #00000000 std
MENU COLOR title 1;36;44    #c00090f0 #00000000 std
MENU COLOR sel 7;37;40      #c000ffff #00000000 std
MENU COLOR unsel 37;44      #90ffffff #00000000 std
MENU COLOR help 37;40       #c0ffffff #00000000 std

# === Ubuntu 자동 설치 (기본) ===
LABEL ubuntu-24.04-autoinstall
  MENU LABEL ^1 - Ubuntu 24.04 Autoinstall (cloud-init)
  KERNEL vmlinuz
  INITRD initrd
  APPEND root=/dev/ram0 ramdisk_size=1500000 ip=dhcp url=http://192.168.0.142/iso/ubuntu-24.04.3-live-server-amd64.iso autoinstall ds=nocloud-net;s=http://192.168.0.142/autoinstall/ cloud-config-url=/dev/null console=ttyS0,115200n8 console=tty0

# === 수동 설치 ===
LABEL ubuntu-manual-install
  MENU LABEL ^2 - Ubuntu 24.04 Manual Install
  KERNEL vmlinuz
  INITRD initrd
  APPEND root=/dev/ram0 ramdisk_size=1500000 ip=dhcp url=http://192.168.0.142/iso/ubuntu-24.04.3-live-server-amd64.iso console=ttyS0,115200n8 console=tty0

# === 디버그 모드 ===
LABEL ubuntu-debug-mode
  MENU LABEL ^3 - Ubuntu Debug Mode (Troubleshooting)
  KERNEL vmlinuz
  INITRD initrd
  APPEND root=/dev/ram0 ramdisk_size=2000000 ip=dhcp url=http://192.168.0.142/iso/ubuntu-24.04.3-live-server-amd64.iso autoinstall ds=nocloud-net;s=http://192.168.0.142/autoinstall/ cloud-config-url=/dev/null console=ttyS0,115200n8 console=tty0 debug BOOT_DEBUG=1

# === 로컬 디스크 부팅 ===
LABEL local-boot
  MENU LABEL ^4 - Boot from Local Disk
  LOCALBOOT 0

# === 메모리 테스트 ===
LABEL memtest86
  MENU LABEL ^5 - Memtest86+ Memory Test
  KERNEL memtest86+.bin

# === 시스템 재시작 ===
LABEL reboot
  MENU LABEL ^6 - Reboot System
  COM32 reboot.c32

# === 시스템 종료 ===
LABEL poweroff
  MENU LABEL ^7 - Power Off System
  COM32 poweroff.c32
EOF

DHCP/TFTP 서버 설정(dnsmasq)

  • dnsmasq를 DHCP 서버, TFTP 서버 그리고 DNS 캐시로 사용합니다.
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.backup
sudo vim /etc/dnsmasq.conf
sudo tee /etc/dnsmasq.conf > /dev/null << 'EOF'
# 네트워크 인터페이스 설정 (실제 인터페이스명으로 변경 필요)
interface=enp0s3
bind-interfaces

# DHCP 설정
dhcp-range=192.168.10.106,192.168.10.110,255.255.255.0,12h
dhcp-option=option:router,192.168.0.1
dhcp-option=option:dns-server,8.8.8.8,8.8.4.4
dhcp-authoritative

# TFTP 설정
enable-tftp
tftp-root=/srv/tftp
dhcp-boot=pxelinux.0
dhcp-option=option:tftp-server,192.168.10.102

# iPXE 감지 및 분기
dhcp-match=set:ipxe,175

# Legacy BIOS
dhcp-boot=tag:!ipxe,undionly.kpxe

# UEFI
dhcp-match=set:efi-x86_64,option:client-arch,7
dhcp-boot=tag:efi-x86_64,tag:!ipxe,snponly.efi

# iPXE 진입 후 HTTP 스크립트 로드
dhcp-boot=tag:ipxe,http://192.168.10.102/boot.ipxe

# 로그 활성화 (문제 해결용)
log-dhcp
log-queries
EOF

설정 문법 검사

sudo dnsmasq --test

서비스 활성화 및 재시작

sudo systemctl enable --now dnsmasq
sudo systemctl restart dnsmasq

iPXE 부팅 스크립트 작성(HTTP 제공)

sudo vim /usr/share/nginx/html/boot.ipxe
sudo tee /usr/share/nginx/html/boot.ipxe > /dev/null << 'EOF'
#!ipxe
set base http://192.168.10.102
set seedfrom http://192.168.10.102/autoinstall/

kernel ${base}/vmlinuz initrd=initrd autoinstall ip=dhcp url=${base}/iso/ubuntu-24.04.3-live-server-amd64.iso ds=nocloud-net;s=${seedfrom} cloud-config-url=/dev/null
initrd ${base}/initrd
boot
EOF
sudo chown www-data:www-data /usr/share/nginx/html/boot.ipxe

자동 설치 구성(Cloud-Init 파일 제공)

Meta-Data 파일 생성

sudo tee /usr/share/nginx/html/autoinstall/meta-data > /dev/null << 'EOF'
instance-id: ubuntu-autoinstall-001
local-hostname: ubuntu-server
EOF

User-Data 파일 생성

  • 패스워드 해시 생성
# 패스워드 : ubuntu1!
openssl passwd -6 'ubuntu1!'
sudo tee /usr/share/nginx/html/autoinstall/user-data > /dev/null << 'EOF'
#cloud-config
autoinstall:
  version: 1
  
  # 사용자 계정 설정
  identity:
    hostname: autoinstalled-server
    password: "$6$7tUafIA6FEeUzS59$8ES67iWLiFd3fVyoAKQnrOqUm4T4qigAuH20tOJA8NjZYHBCouFIQVyIf4yYqxmAQqvUDr6zex1e0By01f0el1"
    username: ubuntu
  
  # 지역 및 키보드 설정
  locale: ko_KR.UTF-8
  keyboard:
    layout: us
    toggle: null
  
  # 네트워크 설정 (DHCP 사용)
  network:
    version: 2
    ethernets:
      eth0:
        dhcp4: true
  
  # 스토리지 설정 (가장 큰 디스크에 자동 설치)
  storage:
    layout:
      name: direct
      match:
        size: largest
  
  # SSH 설정
  ssh:
    allow-pw: false
    install-server: true
  
  # 설치할 패키지
  packages:
    - openssh-server
    - curl
    - wget
    - net-tools
EOF

권한 설정

sudo chown -R www-data:www-data /usr/share/nginx/html/autoinstall
sudo systemctl restart nginx

서비스 재시작

sudo systemctl restart dnsmasq nginx

웹 서버 접근 확인

curl -I http://192.168.0.142/boot.ipxe
curl -I http://192.168.0.142/ubuntu/24.04/vmlinuz
curl -I http://192.168.0.142/autoinstall/user-data

서버에서 PXE 부팅(클라이언트 서버)

  1. F12 → Network Boot (PXE)
  2. 무인 설치 시작

설치 로그 확인 (디버깅)

설치 중 콘솔

Ctrl + Alt + F2

주요 로그 파일

# Cloud-Init 로그
/var/log/cloud-init.log
/var/log/cloud-init-output.log

# Subiquity 설치 로그
/var/log/installer/subiquity-debug.log

 

참고URL

- ubuntu releases : Ubuntu 24.04.3 (Noble Numbat)

- Ubuntu Documentation : How to use cloud-init

- GitHub : canonical/cloud-init

 

728x90
반응형