Skip to content

Instantly share code, notes, and snippets.

@mildsunrise
Last active March 1, 2024 22:55
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mildsunrise/9613280a61ca64e47ed626e40cd6d076 to your computer and use it in GitHub Desktop.
Save mildsunrise/9613280a61ca64e47ed626e40cd6d076 to your computer and use it in GitHub Desktop.
Boot an Ubuntu ISO through network (with EFI)

Netboot Ubuntu with EFI

This method is not netinst. The ISO is downloaded from a URL into RAM, and mounted. After that, installation proceeds exactly as if it was a pen drive / CDROM, and the network cable can be disconnected if you want.

You do not need internet in either computer, just the ISO file.

We don't touch any system files, just delete $TFTPROOT and dnsmasq.conf when you're done.

Before you begin

Make sure 7z and dnsmasq are installed. Download your Ubuntu ISO somewhere.

You'll also need syslinux and its modules:

apt install syslinux-common
# or
pacman -S syslinux

Steps

  1. Set variables for the following commands (examples shown here):

    INTERFACE=eth0
    ISOPATH=/tmp/ubuntu-20.04.2-desktop-amd64.iso
    TFTPROOT=/tmp/tftp
    cd /tmp
  2. Prepare TFTP root: syslinux + ldlinux module, and the kernel + initrd from the ISO

    mkdir -p $TFTPROOT
    cp /usr/lib/syslinux/efi64/{syslinux.efi,ldlinux.e64} $TFTPROOT
    7z x $ISOPATH casper/{vmlinuz,initrd} -o$TFTPROOT
  3. Create configuration file for syslinux:

    • boot kernel + initrd with the same command line (look at boot/grub/grub.cfg in the ISO file)
    • add ip=dhcp url=<URL> to tell it to download the ISO through HTTP
    mkdir -p $TFTPROOT/pxelinux.cfg
    echo "
    DEFAULT install
    LABEL install
      KERNEL casper/vmlinuz
      INITRD casper/initrd
      APPEND ip=dhcp url=http://192.168.4.1:8111/ubuntu.iso root=/dev/ram0 ramdisk_size=1500000 file=/cdrom/preseed/ubuntu.seed maybe-ubiquity quiet splash
    " > $TFTPROOT/pxelinux.cfg/default
  4. Start HTTP server to provide the ISO file:

    ln -s $ISOPATH $TFTPROOT/ubuntu.iso
    python3 -m http.server 8111 -d $TFTPROOT &
  5. Start DHCP+TFTP server that boots syslinux.efi:

    echo "
       bind-interfaces
       listen-address=192.168.4.1
       dhcp-range=192.168.4.100,192.168.4.200
       dhcp-boot=syslinux.efi
       enable-tftp
       tftp-root=$TFTPROOT
    " > dnsmasq.conf
    
    nmcli dev set $INTERFACE managed no  # <-- if you're using NetworkManager, make sure it won't mess with the interface
    sudo ip address add dev $INTERFACE 192.168.4.1/24
    sudo ip link set dev $INTERFACE up
    sudo dnsmasq -C dnsmasq.conf -l dhcp.leases -d &

Boot the other computer by network (remember to disable Secure Boot first).

Variations

  • I've only tested the Desktop version, but works with server (in fact this is adapted from a Ubuntu Server guide).

  • If you want to use legacy BIOS instead of UEFI, you only need to change the following (more info):

    • /usr/lib/syslinux/bios/{pxelinux.0,ldlinux.c32} instead of /usr/lib/syslinux/efi64/{syslinux.efi,ldlinux.e64}
    • dhcp-boot=pxelinux.0 instead of dhcp-boot=syslinux.efi
  • Ubuntu installers (their initrd) support this mode of installation through the url argument, but I don't know what other distributions support it.

@hajijohn
Copy link

hajijohn commented Mar 1, 2024

Screenshot from 2024-03-02 00-54-46
Screenshot from 2024-03-02 00-54-58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment