Requirements

HW: 2 nic device

OS: Ubuntu server 17.10

apt install bash debootstrap schroot syslinux nfs-kernel-server tftpd-hpa xorriso pigz zfsutils-linux

Optional config

apt install isc-dhcp-server

network config nano /etc/netplan/01-netcfg.yaml

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: no
addresses: [10.1.22.2/24]
gateway4: 192.168.122.1
nameservers:
addresses: [8.8.8.8,8.8.4.4]
ens4:
dhcp4: yes

netplan apply

Build livenet environment

Preparazione dell'ambiente zfs

zpool create livenet /dev/sdb

zfs create livenet/images

zfs create livenet/boot

Download package git clone https://github.com/scipioni/livenet-server.git edit /etc/default/livenet like this

# folder that contains livenet system
BASE=/livenet
IMAGES=${BASE}/images
BOOT=${BASE}/boot

Trivial FTP

edit /etc/default/tftp-hpa

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

mkdir /livenet/boot/pxelinux.cfg
cp -a /usr/lib/syslinux/* /livenet/boot
cp /livenet/boot/modules/efi64/* /livenet/boot

edit /livenet/boot/pxelinux.cfg/default

default menu.c32
prompt 0
#timeout 100
menu title PXE Special Boot Menu
MENU AUTOBOOT Starting Livenet in # seconds
label bootlocal
menu label ^Boot local disk
menu default
localboot 0
label nfs
menu label Ubuntu 18.04 - diskless
kernel /bionic/kernel
append initrd=/bionic/initrd ro livenet_root=10.1.22.2:/zfsp_livenet/images/bionic livenet_profile=default
label nfs
menu label Ubuntu 14.04 - install
kernel /trusty/kernel
append initrd=/trusty/initrd ro livenet_root=10.0.254.240:/images/trusty livenet_profile=default livenet_action=install livenet_action_end=reboot

BUILD IMAGE CLIENT

zfs create livenet/images/bionic debootstrap –arch amd64 bionic /zfsp_livenet/images/bionic/ http://archive.ubuntu.com/ubuntu

cd /livenet/images run ….

R=bionic
cat > ${R}/etc/hosts <<QWK
127.0.0.1 localhost livenet-host
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
QWK
chroot ${R} lsb_release -c | awk '{print $2}' > ${R}/etc/debian_chroot
chroot bionic/
chroot ${R} apt-get -y -q install locales dialog
chroot ${R} locale-gen en_GB.UTF-8
chroot ${R} locale-gen it_IT.UTF-8
chroot ${R} update-locale LANG=it_IT.UTF-8 LANGUAGE=it:en_US:en
echo Europe/Rome > ${R}/etc/timezone
cp ${R}/usr/share/zoneinfo/Europe/Rome ${R}/etc/localtime
cat > ${R}/usr/sbin/policy-rc.d <<QWE
#!/bin/sh
# dpkg/apt not start any daemons when things are installed in the chroot
if [ ! "\\\`cat /etc/hostname\\\`" = "\\\`hostname\\\`" ]; then
exit 101
fi
QWE
chmod +x ${R}/usr/sbin/policy-rc.d

DHCP

Abilitare dhcpd su specifica scheda

Editare la riga in

/etc/default/isc-dhcp-server

INTERFACESv4="ens3"

Configurazione dhcpd

editare il file /etc/dhcp/dhcpd.conf al termine service isc-dhcp-service restart

ddns-update-style none;
authoritative;
option domain-name "livenet";
option domain-name-servers 8.8.8.8;
allow bootp;
allow booting;
option space PXE;
# Code 1: Multicast IP address of bootfile
option PXE.mtftp-ip code 1 = ip-address;
# Code 2: UDP port that client should monitor for MTFTP responses
option PXE.mtftp-cport code 2 = unsigned integer 16;
# Code 3: UDP port that MTFTP servers are using to listen for MTFTP requests
option PXE.mtftp-sport code 3 = unsigned integer 16;
# Code 4: Number of secondes a client must listen for activity before trying
# to start a new MTFTP transfer
option PXE.mtftp-tmout code 4 = unsigned integer 8;
option PXE.mtftp-delay code 5 = unsigned integer 8;
# Code 5: Number of secondes a client must listen before trying to restart
# a MTFTP transfer
option PXE.discovery-control code 6 = unsigned integer 8;
option PXE.discovery-mcast-addr code 7 = ip-address;
set vendor-string = option vendor-class-identifier;
class "PXE" {
match if substring(option vendor-class-identifier, 0, 9) = "PXEClient";
option vendor-class-identifier "PXEClient";
vendor-option-space PXE;
option PXE.mtftp-ip 0.0.0.0;
}
class "Etherboot" {
match if substring(option vendor-class-identifier, 0, 9) = "Etherboot";
option vendor-class-identifier "Etherboot";
vendor-option-space PXE;
option PXE.mtftp-ip 0.0.0.0;
}
class "LIVENET" {
match if (substring(option vendor-class-identifier,0,7) = "LIVENET") or (substring(option vendor-class-identifier,0,9) = "PXEClient") or (substring(option vendor-class-identifier,0,9) = "Etherboot");
log ( info, "Packet from PXE or LIVENET client");
}
shared-network "clients" {
subnet 10.1.22.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
option routers 10.1.22.2;
#default-lease-time 28800;
#max-lease-time 86400;
pool {
# restringe il lease solo alla classe LIVENET
allow members of "LIVENET";
range 10.1.22.10 10.1.22.100;
filename "/pxelinux.0";
next-server 10.1.22.2;
}
}
}