본문 바로가기

OS

[Ubuntu] PXE + UEFI autoinstall 설정

DHCP Server 구성

isc-dhcp-server 설치

sudo apt install isc-dhcp-server -y

dhcp config setting

/etc/dhcp/dhcpd.conf 다음과 같이 수정

option domain-name-servers 8.8.8.8,8.8.4.4;
default-lease-time 7200;
max-lease-time 14400; <----- here
authoritative;

subnet 20.20.20.0 netmask 255.255.255.0 {
	option routers 20.20.20.1;
	option subnet-mask 255.255.255.0;
	option domain-name-servers 8.8.8.8;
	range 20.20.20.10 20.20.20.220;
	filename "grubx64.efi"
}

TFTP 구성

TFTP 서버 설치

sudo apt intsall -y tftp-hpa tftpd-hpa

TFTP config setting

file directory 만들기

sudo mkdir -p /tftp/grub
sudo mkdir -p /tftp/boot

/etc/default/tftpd-hpa 다음과 같이 수정

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftp"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure"

Boot loader 및 Installer 추출

ubuntu server iso file download (desktop version은 지원 안합니다.)

wget -o ubuntu22.04.iso <https://releases.ubuntu.com/22.04.2/ubuntu-22.04.2-live-server-amd64.iso?_ga=2.236140417.1499299718.1680513014-1608121830.1666670766>

installer 추출

mkdir mnt
sudo mount -o loop ubuntu22.04.iso mnt
sudo cp mnt/casper/initrd /tftp/boot
sudo cp mnt/casper/vmlinuz /tftp/boot
sudo cp mnt/boot/grup/grub.cfg /tftp/grup/grup.cfg
sudo umount mnt
cd <your workspace>
apt-get download shim-signed
dpkg -x <%name of deb package%> shim
apt-get download grub-efi-amd64-signed
dpkg -x <%name of deb package%> grub
sudo cp <your workspace>/grub/x86_64-efi-signed/grubnetx64.efi.signed  /tftp/grubx64.efi

/tftp/grub/grub.cfg 수정

set timeout=60
menuentry 'Ubuntu 22.04' {
	set gfxpayload=keep
	linux boot/casper/vmlinuz ip=dhcp url=https://<your file server url>/ubuntu22.04.iso autoinstall cloud-config-url=https://<your file server url>/latest.yaml root=/dev/ram0 ramdisk_size=1500000 ---
        initrd boot/casper/initrd
}

 

File server (AWS S3 + cloudfront 사용)에 다음과 같이 업로드

https://<yourfileserver url>/autoinstall.yaml

#cloud-config
autoinstall:
  # version is an Autoinstall required field.
  version: 1
  timezone: 'Asia/Seoul'
  locale: 'Asia/Seoul'
  # This adds the default ubuntu-desktop packages to the system.
  # Any desired additional packages may also be listed here.
  packages:
    - ubuntu-desktop

  # This adds the default snaps found on a 22.04 Ubuntu Desktop system.
  # Any desired additional snaps may also be listed here.
  snaps:
    - name: gnome-3-38-2004
    - name: gtk-common-themes

  # User creation can occur in one of 3 ways:
  # 1. Create a user using this `identity` section.
  # 2. Create users as documented in cloud-init inside the user-data section,
  #    which means this single-user identity section may be removed.
  # 3. Prompt for user configuration on first boot.  Remove this identity
  #    section and see the "Installation without a default user" section.
  identity:
    username: flody
    # A password hasih is needed. `mkpasswd --method=SHA-512` can help.
    # mkpasswd can be found in the package 'whois'
    password: $6$dUlF8PA4rmPYGwW4$aRxWVOAN2z.p.9AxpSBEC/pxuCUIu032vYmEJKGEmuhuKfAGEAV4wsrXAlLbXkdEsCdA3ie.ANKdlxi9TTREX/
    hostname: tmp_host_name
    realname: flody

  # Subiquity will, by default, configure a partition layout using LVM.
  # The 'direct' layout method shown here will produce a non-LVM result.
  storage:
    layout:
      name: direct

  # Ubuntu Desktop uses the hwe flavor kernel by default.
  early-commands:
    - echo 'linux-generic-hwe-22.04' > /run/kernel-meta-package

  # The live-server ISO does not contain some of the required packages,
  # such as ubuntu-desktop or the hwe kernel (or most of their depdendencies).
  # The system being installed will need some sort of apt access.
  # proxy: <http://192.168.0.1:3142>

  late-commands:
    # Enable the boot splash
    - >-
      curtin in-target --
      sed -i /etc/default/grub -e
      's/GRUB_CMDLINE_LINUX_DEFAULT=".*/GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"/'
    - curtin in-target -- update-grub

    # Let NetworkManager handle network
    - rm /target/etc/netplan/00-installer-config*yaml
    - >-
      printf "network:\\n  version: 2\\n  renderer: NetworkManager"
      > /target/etc/netplan/01-network-manager-all.yaml

    # Remove default filesystem and related tools not used with the suggested
    # 'direct' storage layout.  These may yet be required if different
    # partitioning schemes are used.
    - >-
      curtin in-target -- apt-get remove -y
      btrfs-progs cryptsetup* lvm2 xfsprogs

    # Remove other packages present by default in Ubuntu Server but not
    # normally present in Ubuntu Desktop.
    - >-
      curtin in-target -- apt-get remove -y
      ubuntu-server ubuntu-server-minimal
      binutils byobu dmeventd finalrd gawk
      kpartx mdadm ncurses-term needrestart open-iscsi
      sg3-utils ssh-import-id sssd thin-provisioning-tools
      sosreport screen open-vm-tools motd-news-config lxd-agent-loader
      landscape-common fonts-ubuntu-console ethtool brltty
    # Keep cloud-init, as it performs some of the installation on first boot.
    - curtin in-target -- apt-get install -y cloud-init net-tools curl terminator

    # Finally, remove things only installed as dependencies of other things
    # we have already removed.
    - curtin in-target -- apt-get autoremove -y
  # Additional cloud-init configuration affecting the target
  # system can be supplied underneath a user-data section inside of
  # autoinstall.
 # user-data:
 #   runcmd:
 #     - 

 

 

'OS' 카테고리의 다른 글

메모리 관리 1 (전공 내용 정리)  (0) 2021.03.09
[Device] Device이름 설정  (0) 2021.02.18