Application note - UEFI PXE boot to Linux Mint

From fit-PC wiki
Revision as of 12:42, 23 January 2019 by Denis (Talk | contribs) (DHCP server)

Jump to: navigation, search

Overview

In this tutorial you will be able to create PXE server on your PC that allows you to boot multiple distributions directly from ISO image using Ethernet connection only

TFTP server

$ sudo apt install tftpd-hpa
  • Edit configuration file: /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure --ipv4 --verbose"
  • Reload tftpd-hpa service and verify it's running:
$ sudo service tftpd-hpa restart
$ service tftpd-hpa status
● tftpd-hpa.service - LSB: HPA's tftp server
   Loaded: loaded (/etc/init.d/tftpd-hpa; generated)
   Active: active (running) since Wed 2019-01-23 05:35:05 EST; 1min 13s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 2534 ExecStop=/etc/init.d/tftpd-hpa stop (code=exited, status=0/SUCCESS)
  Process: 2539 ExecStart=/etc/init.d/tftpd-hpa start (code=exited, status=0/SUCCESS)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/tftpd-hpa.service
           └─2547 /usr/sbin/in.tftpd --listen --user tftp --address :69 --secure --ipv4 --verbose /var/lib/tftpboot

Jan 23 05:35:05 denis-linux systemd[1]: Starting LSB: HPA's tftp server...
Jan 23 05:35:05 denis-linux tftpd-hpa[2539]:  * Starting HPA's tftpd in.tftpd
Jan 23 05:35:05 denis-linux tftpd-hpa[2539]:    ...done.
Jan 23 05:35:05 denis-linux systemd[1]: Started LSB: HPA's tftp server.
  • Prepare UEFI grub bootloader:
$ sudo cp /usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed /var/lib/tftpboot/grubx64.efi

DHCP server

$ sudo apt install isc-dhcp-server
  • Edit configuration file: /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth1
iface eth1 inet static
    address 10.0.0.1
    netmask 255.255.255.0
    network 10.0.0.0
    broadcast 10.0.0.255
  • Reload networking service and verify it's running:
$ sudo service networking restart
$ service networking status
● networking.service - Raise network interfaces
   Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
   Active: active (exited) since Wed 2019-01-23 06:00:57 EST; 43min ago
     Docs: man:interfaces(5)
  Process: 4835 ExecStop=/sbin/ifdown -a --read-environment --exclude=lo (code=exited, status=0/SUCCESS)
  Process: 4856 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=0/SUCCESS)
  Process: 4851 ExecStartPre=/bin/sh -c [ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifquery --read-environment --list --exclude=lo)" ] && udevadm settle (code=exited, status=0/SUCCESS)
 Main PID: 4856 (code=exited, status=0/SUCCESS)

Jan 23 06:00:57 denis-linux systemd[1]: Starting Raise network interfaces...
Jan 23 06:00:57 denis-linux systemd[1]: Started Raise network interfaces.
  • Edit configuration file: /etc/default/isc-dhcp-server
INTERFACESv4="eth1"
  • Edit configuration file: /etc/dhcp/dhcpd.conf
default-lease-time 600;
max-lease-time 7200;

allow booting;
allow bootp;

subnet 10.0.0.0 netmask 255.255.255.0 {
    range 10.0.0.2 10.0.0.254;
    option subnet-mask 255.255.255.0;
    option domain-name-servers 10.0.0.1;
    option routers 10.0.0.1;
    option broadcast-address 10.0.0.255;
    filename "grubx64.efi";
}
  • Reload isc-dhcp-server service and verify it's running:
$ sudo service isc-dhcp-server restart
$ service isc-dhcp-server status
● isc-dhcp-server.service - ISC DHCP IPv4 server
   Loaded: loaded (/lib/systemd/system/isc-dhcp-server.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2019-01-23 06:01:01 EST; 2s ago
     Docs: man:dhcpd(8)
 Main PID: 4999 (dhcpd)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/isc-dhcp-server.service
           └─4999 dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf

Jan 23 06:01:01 denis-linux dhcpd[4999]: Sending on   LPF/eth1/00:01:c0:1c:a8:11/10.0.0.0/24
Jan 23 06:01:01 denis-linux dhcpd[4999]: 
Jan 23 06:01:01 denis-linux dhcpd[4999]: No subnet declaration for eth0 (192.168.84.51).
Jan 23 06:01:01 denis-linux dhcpd[4999]: ** Ignoring requests on eth0.  If this is not what
Jan 23 06:01:01 denis-linux dhcpd[4999]:    you want, please write a subnet declaration
Jan 23 06:01:01 denis-linux dhcpd[4999]:    in your dhcpd.conf file for the network segment
Jan 23 06:01:01 denis-linux dhcpd[4999]:    to which interface eth0 is attached. **
Jan 23 06:01:01 denis-linux dhcpd[4999]: 
Jan 23 06:01:01 denis-linux dhcpd[4999]: Sending on   Socket/fallback/fallback-net
Jan 23 06:01:01 denis-linux dhcpd[4999]: Server starting service.

ISO images

  • Download the ISO image you want to use and mount it to the TFTP directory:
$ sudo mkdir -p /var/lib/tftpboot/iso/linuxmint-19.1-cinnamon-64bit.iso
$ sudo mount -o loop ~/iso/linuxmint/linuxmint-19.1-cinnamon-64bit.iso /var/lib/tftpboot/iso/linuxmint-19.1-cinnamon-64bit.iso
mount: /var/lib/tftpboot/iso/linuxmint-19.1-cinnamon-64bit.iso: WARNING: device write-protected, mounted read-only.
$ ls /var/lib/tftpboot/iso/linuxmint-19.1-cinnamon-64bit.iso
boot  casper  dists  EFI  isolinux  MD5SUMS  pool  preseed  README.diskdefines

Prepare GRUB

$ sudo mkdir -p /var/lib/tftpboot/grub
  • Edit configuration file: /var/lib/tftpboot/grub/grub.cfg
menuentry "linuxmint-19.1-cinnamon-64bit.iso" {
    linux  iso/linuxmint-19.1-cinnamon-64bit.iso/casper/vmlinuz nfsroot=10.0.0.1:/var/lib/tftpboot/iso/linuxmint-19.1-cinnamon-64bit.iso boot=casper netboot=nfs toram
    initrd iso/linuxmint-19.1-cinnamon-64bit.iso/casper/initrd.lz
}

NFS server

$ sudo apt install nfs-kernel-server
  • Edit configuration file: /etc/exports
/var/lib/tftpboot/iso 10.0.0.0/255.255.0.0(ro,sync,no_subtree_check)
  • Reload nfs-kernel-server service and verify it's running:
$ sudo service nfs-kernel-server restart
$ service nfs-kernel-server status
● nfs-server.service - NFS server and services
   Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor preset: enabled)
   Active: active (exited) since Wed 2019-01-23 07:37:46 EST; 3s ago
  Process: 6314 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)
  Process: 6313 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS)
  Process: 6312 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)
  Process: 6322 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
  Process: 6321 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 6322 (code=exited, status=0/SUCCESS)

Jan 23 07:37:46 denis-linux systemd[1]: Starting NFS server and services...
Jan 23 07:37:46 denis-linux systemd[1]: Started NFS server and services.