0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PXEBOOTの設定

Last updated at Posted at 2023-10-19

PXEBOOTの手順についての備忘録。

項目
開発機 VMware Workstation v16.2.5
サーバーのOS Debian 12
サーバーのIPアドレス 192.168.1.1
DHCP払出IPアドレス 192.168.1.16~31
ルーターのIPアドレス 192.168.1.254

各設定値は各自の環境に合わせて変更願います。

導入作業

パッケージの導入

sudo apt-get install isc-dhcp-server tftpd-hpa apache2

設定ファイルの編集

/etc/default/isc-dhcp-serverの設定

sudo sed -i.org /etc/default/isc-dhcp-server      \
    -e '/DHCPDv4_CONF/ s/^#//'                    \
    -e '/DHCPDv4_PID/  s/^#//'                    \
    -e '/INTERFACESv4/ s/".*"/"ens160"/'

/etc/default/tftpd-hpaの設定

sudo sed -i.org /etc/default/tftpd-hpa            \
    -e '/TFTP_DIRECTORY/ s%".*"%"/var/lib/tftp"%'

/etc/dhcp/dhcpd.confの設定

sudo cp -p /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.org
cat <<- '_EOT_' | sed 's/^ *//g' | sudo tee "/etc/dhcp/dhcpd.conf"
	option arch code 93 = unsigned integer 16;
	
	subnet 192.168.1.0 netmask 255.255.255.0 {
	 	range 192.168.1.16 192.168.1.31;
	 	option domain-name-servers 192.168.1.1;
	 	option domain-name "workgroup";
	 	option routers 192.168.1.254 ;
	 	option broadcast-address 192.168.1.255;
	 	default-lease-time 3600;
	 	max-lease-time 86400;
	
	#	option time-servers ntp.nict.jp;
	#	option subnet-mask 255.255.255.0;
	#	option netbios-dd-server 192.168.1.1;
	
	 	group {
	 		next-server 192.168.1.1;
	 		if option arch = 00:07 or option arch = 00:09 {
	 			filename "bootnetx64.efi";
	 		} else {
	 			filename "pxelinux.0";
	 		}
	
	#		MAC address: xx:xx:xx:xx:xx:xx
	 		host Client01 { hardware ethernet xx:xx:xx:xx:xx:xx; }
	 		host Client02 { hardware ethernet xx:xx:xx:xx:xx:xx; }
	 		host Client03 { hardware ethernet xx:xx:xx:xx:xx:xx; }
	 	}
	}
_EOT_

ディレクトリーの作成

sudo mkdir -p /var/lib/tftp

PXEBOOTの整備

cd /var/lib/tftp/
sudo curl -L -# -R -S -o "debian_stable_netboot.tar.gz" "https://deb.debian.org/debian/dists/stable/main/installer-amd64/current/images/netboot/netboot.tar.gz"
sudo tar -xzf debian_stable_netboot.tar.gz
sudo rm debian_stable_netboot.tar.gz
sudo ln -s debian-installer/amd64/bootnetx64.efi .
sudo ln -s debian-installer/amd64/grubx64.efi    .
sudo ln -s debian-installer/amd64/grub           .

サービスの再起動

sudo systemctl restart tftpd-hpa.service isc-dhcp-server.service apache2.service
sudo systemctl status  tftpd-hpa.service isc-dhcp-server.service apache2.service

実行例

以下より自動設定ファイルをダウンロードしDebian12を/dev/nvme0n1にインストール
https://github.com/office-itou/Linux/tree/master/pxeboot

設定ファイルの編集

syslinux.cfgの編集

OLD_IFS="${IFS}"
IFS= INS_STR=$(
cat <<- '_EOT_' | sed -e 's/^ //g' | sed -z -e 's/\n/\\n/g' | sed -e 's/\\n$//'
label auto
        menu label ^Automated install
        kernel debian-installer/amd64/linux
        append auto=true url=https://raw.githubusercontent.com/office-itou/Linux/master/pxeboot/preseed/debian/preseed_server.cfg priority=critical vga=788 initrd=debian-installer/amd64/initrd.gz --- quiet
_EOT_
)
IFS="${OLD_IFS}"
sudo sed -i.org debian-installer/amd64/boot-screens/syslinux.cfg\
         -e "/^timeout /a \\${INS_STR}"

grub.cfgの編集

OLD_IFS="${IFS}"
IFS= INS_STR=$(
cat <<- '_EOT_' | sed -e 's/^ //g' | sed -z -e 's/\n/\\n/g' | sed -e 's/\\n$//'
menuentry 'Automated install' {
    set background_color=black
    linux    /debian-installer/amd64/linux auto=true url=https://raw.githubusercontent.com/office-itou/Linux/master/pxeboot/preseed/debian/preseed_server.cfg priority=critical vga=788 --- quiet
    initrd   /debian-installer/amd64/initrd.gz
}
_EOT_
)
IFS="${OLD_IFS}"
sudo sed -i.org debian-installer/amd64/grub/grub.cfg\
         -e "/^play /a \\${INS_STR}"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?