1. 測試作業系統:Ubuntu server 22.04 minimal installation 準備 ISO:https://image.icpc.global/icpc2024/ubuntu-22.04.1-icpc2024-20240430-amd64.iso 以下稱 wfos.iso 如果硬碟大小不夠的話(ubuntu server 好像會預設 LVM 只用一半空間的話要 sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv然後 sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

  2. 安裝套件

    > sudo apt update
    > sudo apt upgrade
    > reboot
    > sudo apt install vim tree isc-dhcp-server tftpd-hpa nfs-kernel-server apache2 syslinux pxelinux syslinux-efi -y
    
  3. 設定 DHCP

    # 要先設定好 PXE server 在 <有線網卡名字> 的 IP 為 10.217.47.1
    # > sudo ip addr add 10.217.47.1/24 dev <有線網卡名字>
    # > sudo ip link set dev <有線網卡名字> up
    > sudo vim /etc/dhcp/dhcpd.conf
    
    # 加入下面的內容
    subnet 10.217.47.0 netmask 255.255.255.0 {
      range 10.217.47.100 10.217.47.200;
      option routers 10.217.47.1;
      option broadcast-address 10.217.47.255;
      default-lease-time 600;
      max-lease-time 7200;
      next-server 10.217.47.1;
      # filename "pxelinux.0";
      filename "syslinux.efi";
    }
    
    > sudo vim /etc/default/isc-dhcp-server
    # 加入下面的內容
    INTERFACES="<有線網卡名字>"
    
    > sudo systemctl restart isc-dhcp-server
    # 確認 dhcp server 有起來
    > sudo systemctl status isc-dhcp-server
    
  4. 設定 TFTP server

    # /srv/tftp 是 tftpd 的預設 directory
    # 可以在 /etc/default/tftpd-hpa 改
    > sudo vim /etc/default/tftpd-hpa
    
    # 加入下面的內容
    INTERFACESv4="<有線網卡名字>"
    RUN_DAEMON="yes"
    
    > sudo systemctl restart tftpd-hpa
    # 確認 tftp server 有起來
    > sudo systemctl status tftpd-hpa
    
  5. 設定 PXE 檔案 要換 preseed 的話換掉在 append 那行最後面的網址或是改相應的內容, cloud-init 應該也是接在 append 那邊?

    > sudo cp /usr/lib/SYSLINUX.EFI/efi64/syslinux.efi /srv/tftp
    > sudo cp /usr/lib/syslinux/modules/efi64/{vesamenu.c32,ldlinux.e64,libcom32.c32,libutil.c32} /srv/tftp
    > sudo mkdir /srv/tftp/pxelinux.cfg
    
    # 更多 menu 的選項可以參考 [<https://wiki.syslinux.org/wiki/index.php?title=Menu>](<https://wiki.syslinux.org/wiki/index.php?title=Menu>)
    > cat << EOF | sudo tee /srv/tftp/pxelinux.cfg/default > /dev/null
    UI vesamenu.c32
    TIMEOUT 300
    MENU TITLE PXE Boot Menu
    
    LABEL wfos
      MENU DEFAULT
      MENU LABEL PXE WFOS with http
      kernel wfos/vmlinuz
      initrd wfos/initrd
      append iso ip=dhcp url=http://10.217.47.1/wfos.iso automatic-ubiquity url=http://10.217.47.1/preseed/contest.seed --
    EOF
    
    # 把 iso 的檔案抓出來
    > sudo mkdir /srv/tftp/wfos
    > sudo mount -o ro,loop wfos.iso /mnt
    > sudo cp /mnt/casper/{initrd,vmlinuz} /srv/tftp/wfos
    > sudo umount /mnt
    > tree /srv/tftp
    # *應該長這樣
    /srv/tftp/
    ├── ldlinux.e64
    ├── libcom32.c32
    ├── libutil.c32
    ├── pxelinux.cfg
    │   └── default
    ├── syslinux.efi
    ├── vesamenu.c32
    └── wfos
        ├── initrd
        └── vmlinuz*
    
  6. 設定 apache2

    > sudo mount -o ro,loop wfos.iso /mnt
    > sudo cp -r /mnt/preseed /var/www/html
    > sudo umount /mnt
    # 用 hard link 不用 cp 是為了省空間,要 cp 也可以
    > sudo ln wfos.iso /var/www/html/wfos.iso
    > sudo systemctl restart apache2
    # 確認 http server 有起來
    > sudo systemctl status apache2
    # 看一下看不看得到 pressed
    # 瀏覽器中輸入 http://<server_address>/preseed/ 看看不看得到 preseed 的頁面
    
  7. 再 check 一次

    > sudo systemctl status isc-dhcp-server
    > sudo systemctl status tftpd-hpa
    > sudo systemctl status apache2
    > sudo ufw status # 應該要噴 error 說沒有 ufw,有的話 sudo ufw disable
    
  8. Boot from PXE

    1. 按住 F12 就好,進選單選 IPv4
    2. code_udp_sendto: stalling on configure with no mapping: 根據杜老大,這個是網卡還沒 initialize 好,等他就對了
    3. 用 VirtualBox 的 Bridge 接出來超慢,本機架速度沒什麼問題(15 min 左右)
  9. Todo & Notes

    1. preseed 好像不能 disable wifi/bluetooth 和改 boot order,看起來 boot order 要手動改 而且灌完之後他會用黑魔法把 boot option 改成剛灌好的在最先,不知道要怎麼辦
    2. 筆電有插電的話可以用 sudo etherwake -i <server_interface> <laptop_MAC_address> 從 server Wake on LAN,不知道會不會用到?
    3. 這裡 syslinux.efi 還有 ldlinux.e64 用的跟網路上的都不一樣,我們有試過 pxelinux.0bootx64.??? 不能用,貌似這臺筆電只吃 efi(tftpd 可以看到 client reject option,用 wireshark 看也看得到)

不要理也不要刪下面的暫存:


> echo "DEFAULT linux
PROMPT 0
MENU TITLE PXE Boot Menu
TIMEOUT 300
LABEL linux
  MENU LABEL Boot Ubuntu 22.04 Desktop via NFS
  KERNEL vmlinuz
  APPEND initrd=initrd root=/dev/nfs netboot=nfs boot=casper nfsroot=10.217.47.1:/var/nfs/ubuntu ip=dhcp rw automatic-ubiquity url=http://10.217.48.1/preseed/contest.seed
" | sudo tee /var/lib/tftpboot/pxelinux.cfg/default > /dev/null

> sudo cp /var/nfs/ubuntu/casper/vmlinuz /var/lib/tftpboot/
> sudo cp /var/nfs/ubuntu/casper/initrd /var/lib/tftpboot/
> sudo cp -r /var/nfs/ubuntu/preseed /var/www/html
> sudo systemctl restart apache2