PXE boot in Ubuntu installazione

pxe_boot_garanet
Basato su una Macchina Virtual con Virtualbox, prepariamo un Server Ubuntu 16.04 come PXE server, NTP server, DHCP server.

Router: 192.168.0.1/24
Virtualbox : Ver. 5.0.26
Virtualbox-Network: in Bridge mode to 192.168.0.0/24
Boot from iso : http://www.ubuntu.com/download/server/thank-you?version=16.04.1&architecture=amd64
Server Specs: 1Gb Ram/ 8Gb HDD
OS: Ubuntu 16.04 64 bit
Server Name: pxe.local
Server IP: 192.168.0.100/24

Effettuato l’installazione standard e configurato la scheda di rete e installato il pacchetto opens-ssh, si procede con la connessione SSH sul Server.
Si eseguono i seguenti comandi, inserendo quando richiesto, la password per i privilegi sudores.

#:~$ sudo apt-get update
#:~$ sudo apt-get upgrade
#:~$ sudo apt-get install -y bind9 isc-dhcp-server open-vm-tools tftpd-hpa ntp ntpdate
#:~$ sudo ntpdate -u 0.ubuntu.pool.ntp.org

Si controlla la configurazione di rete del server con IP statico.

#:~$ sudo vi /etc/network/interfaces

Che dovrebbe risultare come segue:

auto enp0s3
iface enp0s3 inet static
address 192.168.0.100
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 8.8.8.8

Si configura il file host

#:~$ sudo echo "192.168.0.100 pxe pxe.local" >> /etc/hosts

Si configura il servizio tftpd-hpa

#:~$ sudo su -c 'cat < /etc/default/tftpd-hpa
RUN_DAEMON="yes"
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftpboot"
OPTIONS="-l -s /tftpboot"
TFTP_ADDRESS="[::]:69"
TFTP_OPTIONS="--secure"
EOF
'
#:~$ sudo mkdir -p /tftpboot/preseed
#:~$ sudo chmod -R 777 /tftpboot
#:~$ sudo systemctl enable tftpd-hpa
#:~$ sudo systemctl restart tftpd-hpa

Si configura il servizio DHCP server

#:~$ sudo su -c 'cat < /etc/dhcp/dhcpd.conf
allow booting;
allow bootp;
authorative;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.150 192.168.0.253;
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.0.254;
option domain-name-servers 8.8.8.8, 192.168.0.44;
option domain-name "local";
filename "pxelinux.0";
}
EOF
'
#:~$ sudo systemctl enable isc-dhcp-server
#:~$ sudo systemctl restart isc-dhcp-server

Si scarica l’immagine NetBoot per Ubuntu e si copiano i files necessari.

#:~$ wget http://archive.ubuntu.com/ubuntu/ubuntu/dists/xenial/main/installer-amd64/current/images/netboot/
netboot.tar.gz -O ubuntu-16.04-netboot.tar.gz
#:~$ mkdir ubuntu-16.04-netboot
#:~$ tar zxf ubuntu-16.04-netboot.tar.gz -C ubuntu-16.04-netboot
#:~$ sudo cp -a ubuntu-16.04-netboot/ubuntu-installer /tftpboot
#:~$ sudo cp ubuntu-16.04-netboot/ubuntu-installer/amd64/pxelinux.0 /tftpboot/
#:~$ sudo cp ubuntu-16.04-netboot/ubuntu-installer/amd64/boot-screens/ldlinux.c32 /tftpboot/
#:~$ sudo mkdir /tftpboot/boot-screens
#:~$ sudo cp ubuntu-16.04-netboot/ubuntu-installer/amd64/boot-screens/libcom32.c32 /tftpboot/boot-screens
#:~$ sudo cp ubuntu-16.04-netboot/ubuntu-installer/amd64/boot-screens/libutil.c32 /tftpboot/boot-screens
#:~$ sudo cp ubuntu-16.04-netboot/ubuntu-installer/amd64/boot-screens/vesamenu.c32 /tftpboot/boot-screens
#:~$ sudo mkdir /tftpboot/pxelinux.cfg
#:~$ cd /tftpboot/pxelinux.cfg
#:~$ sudo ln -s ../boot-screens/syslinux.cfg default

Si configura il file Syslinux.cfg

#:~$ sudo su -c "cat < /tftpboot/boot-screens/syslinux.cfg
path boot-screens
include boot-screens/menu.cfg
default boot-screens/vesamenu.c32
prompt 0
timeout 100
EOF
"

Si configura il Boot Menu

#:~$ sudo su -c "cat < /tftpboot/boot-screens/menu.cfg
menu hshift 13
menu width 49
menu margin 8
menu tabmsg
menu title Installer boot menu
label auto-ubuntu-16.04
menu label ^Ubuntu 16.04 automated install
kernel ubuntu-installer/amd64/linux
append auto=true priority=critical vga=788 initrd=ubuntu-installer/amd64/initrd.gz preseed/
url=tftp://192.168.0.44/preseed/Ubuntu16.cfg preseed/interactive=false
menu begin ubuntu-16.04
menu title Ubuntu 16.04
label mainmenu
menu label ^Back..
menu exit
include ubuntu-installer/amd64/boot-screens/menu.cfg
menu end
EOF
"

Si configura il file Preseed con un editor (nano / vim / vi)

#:~$ sudo vi /tftpboot/preseed/Ubuntu16.cfg

Si copia ed incolla il seguente testo, modificando

d-i debian-installer/locale string en_US
d-i debian-installer/language string en
d-i debian-installer/country string NL
d-i keyboard-configuration/xkb-keymap select us

d-i passwd/user-fullname string
d-i passwd/username string ubuntu
d-i passwd/root-password password ubuntu
d-i passwd/root-password-again password 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 netcfg/choose_interface select auto
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain

d-i mirror/country string manual
d-i mirror/http/hostname string http://en.archive.ubuntu.com
d-i mirror/http/directory string /ubuntu
d-i mirror/http/proxy string

d-i clock-setup/utc boolean true
d-i clock-setup/ntp boolean true
d-i time/zone string Europe/Amsterdam

d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto-lvm/guided_size string max
d-i partman-auto/choose_recipe select multi
d-i partman/default_filesystem string ext4
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true

d-i grub-installer/grub2_instead_of_grub_legacy boolean true
d-i grub-installer/only_debian boolean true
d-i grub-installer/bootdev string /dev/[sv]da

d-i pkgsel/update-policy select none
d-i pkgsel/include string unity ubuntu-desktop openssh-server
d-i pkgsel/updatedb boolean true
d-i base-installer/kernel/override-image string linux-server
tasksel tasksel/first multiselect standard
d-i pkgsel/include string lsb-release openssh-server screen sysstat wget ldap-utils docker.io
popularity-contest popularity-contest/participate boolean false
d-i finish-install/reboot_in_progress note
d-i apt-setup/services-select multiselect security
d-i apt-setup/security_host string security.ubuntu.com
d-i apt-setup/security_path string /ubuntu

d-i preseed/late_command string \
in-target /bin/bash -c 'echo -e "192.168.0.100 pxe pxe.local" >> /etc/hosts'

d-i preseed/early_command string /bin/killall.sh; /bin/netcfg
d-i finish-install/reboot_in_progress note

Adesso si possono avviare le macchine virtuali clients per l’installazione automatica via PXE boot.




PXE boot in Ubuntu installazione ultima modifica: 2016-10-08T17:43:45+00:00 da Gabriele Gatto