การทำ PXE server บน Debian

อ้างอิง
Install Debian 9 (Stretch) via PXE Network Boot Server และ
Diskless PXE netboot How-To for Debian 8 Jessie

บทความนี้เป็นบันทึกเรียนรู้และทดลองทำ PXE Server ซึ่งทดสอบระบบโดยการติดตั้ง Debian โดย boot ตัวติดตั้งผ่าน Network แทน CD/USB

ซึ่งสามารถนำไปประยุกต์ใช้ในการทำ diskless PC ได้ เพียงแต่ศึกษาเพิ่มเติมการ boot OS ต่างๆ

สิ่งที่ต้องการ

สภาพแวดล้อม

  • Network มี 2 range คือ
    1. 192.168.1.0/24 เป็น network กลางที่สามารถออก Internet ได้
    2. 192.168.56.0/24 เป็น Host only network ซึ่งเป็น network ภายในเครื่องฯ ที่ทำ Virtual Box.
  • คอมพิวเตอร์ VM มี 2 ตัว
    1. Srv-1 เป็น Debian 10 Buster ทำหน้าที่เป็น server ที่จะเป็นทั้ง DHCP and TFTP โดยถูกกำหนด fixed ip เป็น 192.168.56.61
    2. PXEClient1 ทำหน้าที่เป็นเครื่องลูก ที่จะทดสอบ boot จาก PXE เพื่อทำการติดตั้ง Debian โดยจะได้ fixed ip จาก DHCP server
$ sudo install tftpd-hpa syslinux pxelinux nfs-kernel-server isc-dhcp-server syslinux-utils syslinux

ขั้นตอนการติดตั้ง

การทดลองทำบน Virtual Box จึงติดตั้งทุกอย่างบน Server VM เดียว และ Client VM อีกหนึ่งสำหรับทดสอบระบบ

DHCP Server

หากระบบที่ใช้งานอยู่ มี DHCP Server อยู่แล้ว ก็ไม่ต้องติดตั้ง DHCP Server นี้อีก แต่ต้องตั้งค่า DHCP ให้ติดต่อ TFTP Server (ศึกษาการตั้งค่าจากคู่มือ DHCP Server ที่ใช้งาน)

  • บน Linux นั้น ส่วนมากจะใช้ ISC DHCP Server คำสั่งติดตั้ง

    ​​$ sudo apt update
    ​​$ sudo apt install -y isc-dhcp-server
    
  • เมื่อติดตั้งเสร็จ ก็ทำการตั้งค่า DHCP Server โดยมี 2 ไฟล์ที่ต้อง update คือ /etc/dhcp/dhcpd.conf และ /etc/default/isc-dhcp-server.conf

    /etc/dhcp/dhcpd.conf กำหนด IP range ที่จะใช้ และ options ต่างๆ รวมถึงการทำ fix ip

    ​​authoritative;    # เปิดการใช้ dhcp server นี้
    ​​
    ​​## ตั้งค่า IP ที่จะใช้งาน และ option ต่างๆ
    ​​subnet 192.168.56.0 netmask 255.255.255.0 {
    ​​  range 192.168.56.150 192.168.56.170;
    ​​  option routers 192.168.56.1;
    ​​  allow bootp;
    ​​  allow booting;
    ​​  filename "pxelinux.0";
    ​​}
    ​​
    ​​## หากต้องการกำหนด IP ให้อุปกรณ์
    ​​host srv2 {
    ​​  hardware ethernet 08:00:27:55:40:24;
    ​​  fixed-address 192.168.56.155;
    ​​}
    

    /etc/default/isc-dhcp-server.conf กำหนด NIC ที่จะให้ dhcp แจก IP กับ network ไหน

    ​​INTERFACESv4="enp0s8"
    ​​#INTERFACESv6=""
    
  • ตั้งค่าต่างๆ แล้ว ลอง restart isc-dhcp-server จากประสบการณ์หากตั้งค่าถูกแล้ว ต้องทำการ reboot server ด้วย

    ​​$ sudo systemctl stop isc-dhcp-server
    ​​$ sudo systemctl start isc-dhcp-server
    ​​$ sudo systemctl status isc-dhcp-server
    

หากพบว่ามี dhcp รันอยู่แล้ว ให้ทำการ sudo reboot

TFTP Server

  • ติดตั้ง tftpd-hpa

    ​​$ sudo apt install tftpd-hpa
    ​​$ sudo mkdir -p /srv/tftp /srv/nfs1
    

    และจัดเตรียม

  • ตรวจสอบไฟล์ /etc/default/tftpd-hpa ตามการตั้งค่า ดังนี้

    ​​TFTP_USERNAME="tftp"
    ​​TFTP_DIRECTORY="/srv/tftp"
    ​​TFTP_ADDRESS="0.0.0.0:69"
    ​​TFTP_OPTIONS="--secure"
    
  • restart service

    ​​$ sudo systemctl stop tftpd-hpa
    ​​$ sudo systemctl start tftpd-hpa
    ​​$ sudo systemctl status tftpd-hpa
    

เตรียม Debian Net Boot

  • ติดตั้ง Syslinux bootloader
    ​​$ sudo apt install syslinux-utils syslinux
    
  • ทำการ download และ uncompress
    ​​$ wget http://ftp.nl.debian.org/debian/dists/buster/main/installer-amd64/current/images/netboot/netboot.tar.gz
    ​​$ cd /srv/tftp
    ​​$ sudo tar xzvf ~/netboot.tar.gz 
    ​​$ sudo cp /usr/lib/syslinux/memdisk /srv/tftp/
    ​​$ sudo ln -s /srv/tftp/debian-installer/amd64/bootnetx64.efi /srv/tftp/
    

รายละเอียดเพิ่มเติมอื่น สามารถอ่านได้จากอ้างอิงข้างต้น

คลิป YouTube

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

After the scene

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →


Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

ความคิดเห็นคำแนะนำของท่านต่อบทความนี้ จะถูกนำมาใช้ในการพัฒนาปรับปรุงงานเขียนของผม อย่างไงก็รบกวนแสดงความเห็นคิดด้วยนะครับ

สนับสนุนการเงินได้ที่

  • บัญชีกสิกรไทย 003–3–29344–5