この手順は現在 (22.04.3) では使用できません。 新しい手順はこちらを参照して下さい。
Contents
概要
Ubuntuの自動インストール用にPXEサーバーを構築します。UEFIのみを対象としています。
参考情報
まとまった情報がなく、下記のいくつかの情報を参考にしつつ整理しました。
https://ubuntu.com/server/docs/install/netboot-amd64(重要)
https://satishdotpatel.github.io/ubuntu-20-04-autoinstall-pxe
https://www.koeki-prj.org/~akito/it/system/ubuntu-efi-network.html
https://askubuntu.com/questions/1235723/automated-20-04-server-installation-using-pxe-and-live-server-image
https://ubuntu.com/server/docs/install/netboot-arm64(重要)
https://www.golinuxcloud.com/uefi-pxe-boot-server-ubuntu-20-04-cloud-init/(重要)
前提条件
OS
Ubuntu 20.04を使用します。
DHCP/TFTPサーバー
こちらを参考にDHCP/TFTPサーバー(Dnsmasq)構築します。
HTTPサーバー
こちらを参考にHTTPサーバーを構築します。
ファイルの配置
PXEブートに必要なファイルを配置します。
Setting up the files for UEFI booting
myadmin@ubuntu:~$ apt download shim-signed myadmin@ubuntu:~$ dpkg-deb --fsys-tarfile shim-signed*deb | sudo sh -c "tar x ./usr/lib/shim/shimx64.efi.signed -O > /srv/tftp/bootx64.efi" myadmin@ubuntu:~$ apt download grub-efi-amd64-signed myadmin@ubuntu:~$ dpkg-deb --fsys-tarfile grub-efi-amd64-signed*deb | sudo sh -c "tar x ./usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed -O > /srv/tftp/grubx64.efi" myadmin@ubuntu:~$ apt download grub-common myadmin@ubuntu:~$ dpkg-deb --fsys-tarfile grub-common*deb | sudo sh -c "tar x ./usr/share/grub/unicode.pf2 -O > /srv/tftp/unicode.pf2"
ISOイメージの配置
isoディレクトリを作成し、ISOイメージを配置します。
myadmin@ubuntu:~$ sudo mkdir /var/www/html/iso myadmin@ubuntu:~$ ls -l /var/www/html/iso/ubuntu-20.04.4-live-server-amd64.iso
vmlinuz, initrd, grub.cfg
ISOイメージをマウントします。
myadmin@ubuntu:~$ sudo mount /var/www/html/iso/ubuntu-20.04.4-live-server-amd64.iso /mnt
必要なディレクトリを作成します。
myadmin@ubuntu:~$ sudo mkdir /srv/tftp/grub /srv/tftp/casper
必要なファイルををTFTPのルートディレクトリにコピーします。grub.cfgは書き換える為、サンプルとしてコピーしています。
myadmin@ubuntu:~$ sudo cp /mnt/boot/grub/grub.cfg /srv/tftp/grub/grub.cfg.sample myadmin@ubuntu:~$ sudo cp /mnt/casper/{vmlinuz,initrd} /srv/tftp/casper
ISOイメージのマウントを解除します。
myadmin@ubuntu:~$ sudo umount /mnt
autoinstall
autoinstallのテンプレートとして、インストール後に作成されるvar/log/installer/autoinstall-user-dataを利用できます。
myadmin@ubuntu:~$ cat /var/log/installer/autoinstall-user-data
autoinstall用のファイルを配置するディレクトリを作成します。
myadmin@ubuntu:~$ sudo mkdir /var/www/html/autoinstall
meta-dataを作成します。空ファイルとなります。
myadmin@ubuntu:~$ sudo touch /var/www/html/autoinstall/meta-data
user-dataに記載するパスワードを生成します。
myadmin@ubuntu:~$ openssl passwd -6 -salt $(openssl rand -hex 8) password
$6$bf432b7f0f910a84$kUTIwE5afiOUkL3gabGF/WQnb9GdaMypSa5mJrWUelK41Xa2L/xNl4kbB91KWwaYvv7/Q/pQ8pjCu2COip5DJ0
autoinstall-user-dataをベースにuser-dataを作成します。パーティションサイズ、LVMのボリューム名だけ変更しています。
myadmin@ubuntu:~$ sudo tee /var/www/html/autoinstall/user-data <<EOF
#cloud-config
autoinstall:
apt:
disable_components: []
geoip: false
preserve_sources_list: false
primary:
- arches:
- amd64
- i386
uri: http://jp.archive.ubuntu.com/ubuntu
- arches:
- default
uri: http://ports.ubuntu.com/ubuntu-ports
identity:
hostname: ubuntu
password: $6$bf432b7f0f910a84$kUTIwE5afiOUkL3gabGF/WQnb9GdaMypSa5mJrWUelK41Xa2L/xNl4kbB91KWwaYvv7/Q/pQ8pjCu2COip5DJ0
realname: myadmin
username: myadmin
kernel:
package: linux-generic
keyboard:
layout: jp
toggle: null
variant: ''
locale: en_US.UTF-8
network:
ethernets:
ens33:
dhcp4: true
version: 2
ssh:
allow-pw: true
authorized-keys: []
install-server: true
storage:
config:
- ptable: gpt
path: /dev/sda
wipe: superblock
preserve: false
name: ''
grub_device: false
type: disk
id: disk-sda
- device: disk-sda
size: 1G
wipe: superblock
flag: boot
number: 1
preserve: false
grub_device: true
type: partition
id: partition-0
- fstype: fat32
volume: partition-0
preserve: false
type: format
id: format-0
- device: disk-sda
size: 1.5G
wipe: superblock
flag: ''
number: 2
preserve: false
type: partition
id: partition-1
- fstype: ext4
volume: partition-1
preserve: false
type: format
id: format-1
- device: disk-sda
size: -1
wipe: superblock
flag: ''
number: 3
preserve: false
type: partition
id: partition-2
- name: vg0
devices:
- partition-2
preserve: false
type: lvm_volgroup
id: lvm_volgroup-0
- name: root
volgroup: lvm_volgroup-0
size: -1
wipe: superblock
preserve: false
type: lvm_partition
id: lvm_partition-0
- fstype: ext4
volume: lvm_partition-0
preserve: false
type: format
id: format-2
- path: /
device: format-2
type: mount
id: mount-2
- path: /boot
device: format-1
type: mount
id: mount-1
- path: /boot/efi
device: format-0
type: mount
id: mount-0
updates: security
version: 1
EOF
grub.cfg
grub.cfg.sampleをベースにgrub.cfgを作成します。
myadmin@ubuntu:~$ sudo tee /srv/tftp/grub/grub.cfg <<EOF
if loadfont /boot/grub/font.pf2 ; then
set gfxmode=auto
insmod efi_gop
insmod efi_uga
insmod gfxterm
terminal_output gfxterm
fi
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
set timeout=5
menuentry "Install Ubuntu Server" {
set gfxpayload=keep
linux /casper/vmlinuz ip=dhcp url=http://192.168.71.161/iso/ubuntu-20.04.4-live-server-amd64.iso autoinstall ds="nocloud-net;s=http://192.168.71.161/autoinstall/" cloud-config-url=/dev/null
initrd /casper/initrd
}
grub_platform
if [ "$grub_platform" = "efi" ]; then
menuentry 'Boot from next volume' {
exit 1
}
menuentry 'UEFI Firmware Settings' {
fwsetup
}
fi
submenu 'Boot and Install with the HWE kernel' {
menuentry "Install Ubuntu Server" {
set gfxpayload=keep
linux /casper/hwe-vmlinuz quiet ---
initrd /casper/hwe-initrd
}
}
EOF
自動ネットワークインストールの確認
ここまででPXEブートを用いた自動ネットワークインストールが可能な状態となります。PXEブート可能なPC/VM等を使用して確認しましょう。