PXE Network BootでUbuntu Serverを自動インストールする
中古でSupermicroのマザーボード「X9SCM-F」を購入しました。PXE Network BootでUbuntuの自動インストールを行いました。その時の手順をまとめました。
準備
TFTPサーバーとHTTPサーバー、DNSサーバーをインストールします。
apt install -y tftpd-hpa apache2 dnsmasq
Ubuntu 18.0.4 Serverのイメージをダウンロードします。
wget http://cdimage.ubuntu.com/releases/bionic/release/ubuntu-18.04.4-server-amd64.iso
ダウンロードしたイメージをマウントします。
mount -o loop,ro ubuntu-18.04.4-server-amd64.iso /mnt/
TFTPサーバーの構築
pxelinuxを使用してPXEブートできるのですが、設定がわからないので、isoイメージの中にあるnetbootをTFTPサーバーのルートディレクトリにコピーして使用します。
cp -Rfv /mnt/install/netboot/* /var/lib/tftpboot/
TFTPサーバーにコピーしたnetbootのメニューを編集します。
vi /var/lib/tftpboot/boot/ubuntu-installer/amd64/boot-screens/txt.cfg
変更前
label install
menu label ^Install
menu default
kernel ubuntu-installer/amd64/linux
append vga=788 initrd=ubuntu-installer/amd64/initrd.gz --- quiet
label cli
menu label ^Command-line install
kernel ubuntu-installer/amd64/linux
append tasks=standard pkgsel/language-pack-patterns= pkgsel/install-language-support=false vga=788 initrd=ubuntu-installer/amd64/initrd.gz --- quiet
txt.cfgの6行目を変更します。urlにpreseedのファイルを指定して自動インストールできます。
default install
label install
menu label ^Install
menu default
kernel ubuntu-installer/amd64/linux
append locale=en_US.UTF-8 keymap=jp interface=eno1 hostname={ホスト名} domain={ドメイン名} url=http://{HTTPサーバーのIP}/ubuntu/bionic/preseed/local-sources.seed vga=788 initrd=ubuntu-installer/amd64/initrd.gz --- quiet
label cli
menu label ^Command-line install
kernel ubuntu-installer/amd64/linux
append tasks=standard pkgsel/language-pack-patterns= pkgsel/install-language-support=false vga=788 initrd=ubuntu-installer/amd64/initrd.gz --- quiet
HTTPサーバーの構築
isoイメージの中身をすべてHTTPサーバーのディレクトリにコピーします。
mkdir -p /var/www/html/ubuntu/bionic
cp -Rfv /mnt/* /var/www/html/ubuntu/bionic
HTTPサーバーにコピーしたisoイメージの中に、いくつかpreseedが用意されています。今回は新規にpreseedファイルを作成します。
vi /var/www/html/ubuntu/bionic/preseed/local-sources.seed
d-i mirror/country string manual
d-i mirror/http/hostname string jp.archive.ubuntu.com
d-i mirror/http/directory string /ubuntu
d-i mirror/http/proxy string
d-i passwd/user-fullname string Ubuntu
d-i passwd/username string ubuntu
d-i passwd/user-password password ubuntu
d-i passwd/user-password-again password ubuntu
d-i user-setup/allow-password-weak boolean true
d-i clock-setup/utc boolean true
d-i time/zone string Asia/Tokyo
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto-lvm/guided_size string max
d-i partman/choose_partition select finish
d-i partman/confirm_nooverwrite boolean true
d-i live-installer/net-image string http://{HTTPサーバーのIP}/ubuntu/bionic/install/filesystem.squashfs
tasksel tasksel/first multiselect server, openssh-server
d-i pkgsel/update-policy select none
d-i grub-installer/only_debian boolean true
d-i finish-install/reboot_in_progress note
DNSサーバーの構築
DNSサーバーにPXEブートするTFTPサーバーを設定します。
vi /etc/dnsmasq.d/tftp.conf
Supermicroの「X9SCM-F」は、USBブートの時はUEFIブートができるのですが、ネットワークブートの時はUEFIブートできませんでした。ネットワークブートでUTFIブートできるマザーボードの場合は2,3行目を有効したらUTFIブートできるはずです。(未検証)
pxe-service=tag:vmbr0,x86PC,"Boot BIOS PXE",boot/pxelinux.0,{TFTPサーバーのIP}
#pxe-service=tag:vmbr0,BC_EFI,"Boot UEFI PXE-BC",grub/grubx64.efi,{TFTPサーバーのIP}
#pxe-service=tag:vmbr0,X86-64_EFI,"Boot UEFI PXE-64",grub/grubx64.efi,{TFTPサーバーのIP}
参考文献
- 初めてのPXEブート - astamuse Lab
- Configuring PXE Network Boot Server on Ubuntu 18.04 LTS – Linux Hint
- 既存のDHCPサーバが存在する場合でもPXE Bootをする(dnsmasqを使ったProxy DHCPの設定) - Dig that groovy!
- How to Install Ubuntu via PXE Server Using Local DVD Sources
- pxe boot - dnsmasq proxyDHCP PXEおよびEFI“start_image()が無効なパラメーターを返しました” - プログラミングQ&A - BugInfo
- B.2. Using preseeding
- PXEboot - Chaperone