DHCP race with interface configuration during automated installation

Jul 2, 2024
5
1
3
Hello,

I'm trying to set up an automated installation of VE with the answer file coming from HTTP. My main problem right now is that the installer is not having a lot of success getting an address from DHCP to download the answer file; in at least eight out of ten attempts it times out before getting an offer.

My switch tells me that is because the link goes down right before the installer starts sending DHCPDISCOVERs. The installer is very impatient; it only waits a total of ten seconds or so to get a response. That is not always (in fact, only rarely) long enough because the link is never up for the first round of DHCPDISCOVERs, and dhclient appears to send them in random order, so even if it sends another one on the correct interface (sometimes it does not) that has to happen late enough for the link to have come up.

According to the switch, the port is up and forwarding from POST until _just_ before the DHCP client gets to work, so this is not a switch/network problem but the installer's startup procedure reinitializing (or whatever) the interface at the worst possible moment. STP is also not part of the problem.

Is there a way to convince the installer (i.e. dhclient) to wait longer, or leave the interfaces alone? This machine used to have ten network interfaces, and then it worked perhaps a quarter of the time. Now it has six and the success rate seems to have gone down, probably because dhclient spends even less total time on fewer interfaces.

Thanks for any hints.
 
Even when Proxmox gets a DHCP assigned address, it will not use DHCP (out of the box) after installation. I think you're better off assigning it a static IP address. Or do you setup DHCP refresh yourself after installation?

EDIT: I misunderstood, sorry.
 
Last edited:
This is not about using DHCP to get an address for production use of the installed VE. The automated installer itself needs an IP address so it can get the answer file, and it uses DHCP for that.
 
Found it, but cannot fix it.

I have no idea how to keep the booting installer from briefly shutting down the interface, but my estimate of ten seconds wait time in dhclient was spot on. That value is configured in /etc/dhcp/dhclient.conf, wrapped in pve-installer.squashfs, in the ISO image. So I extracted the squashfs, increased the timeout, regenerated the squashfs, and updated it inside the ISO in the same way that proxmox-auto-install-assistant injects the configuration.

The resulting ISO, alas, does not boot, and I don't know what I did wrong; I'm not really a Linux person.

Proxmox bug: https://bugzilla.proxmox.com/show_bug.cgi?id=5583
 
  • Like
Reactions: leesteken
I was able to fix this by updating the ISO. Here are the steps I followed:
Massive shoutouts to @Remi-DM and @ValerioBob from this thread: https://forum.proxmox.com/threads/create-custom-pve-iso-from-original-pve-iso.123606/

Once the ISO is downloaded perform the following steps:
Bash:
sudo apt install mkisofs squashfs-tools 
sudo su - 

#location where the original iso of proxmox is
cd /root/pxmx

#copy into proxmox.mbr the mbr from original iso (first 512byte)
dd if=proxmox-ve_8.2-1.iso bs=512 count=1 of=proxmox.mbr

mkdir /tmp/prox
cd /tmp/prox
mount -t iso9660 -o loop /root/pxmx/proxmox-ve_8.2-1.iso /mnt/
cd /mnt
tar cf - -C /mnt . | tar xfp - -C /tmp/prox

# Until here everything is fine but when I edit pve-installer.squashfs the modification are not saved and when I boot I don't see them
# To fix that I edited pve-base.squashfs instead of pve-installer.squashfs:

cd /tmp/prox
unsquashfs pve-installer.squashfs

#Here I edited the files
vi squashfs-root/etc/dhcp/dhclient.conf

# Update the timeout to 60, save the file and quit

#Then I squashed it back

rm pve-installer.squashfs
mksquashfs squashfs-root/ pve-installer.squashfs
# Don't forget to remove squashfs-root
rm -rf squashfs-root/

cd /root/pxmx

xorriso -as mkisofs \
-o repacked.iso \
-r -V 'PVE' \
--modification-date=2024042411311000 \
-isohybrid-mbr /root/pxmx/proxmox.mbr \
-partition_offset 16 \
--protective-msdos-label \
-appended_part_as_gpt \
-efi-boot-part --efi-boot-image \
-c '/boot/boot.cat' \
-b '/boot/grub/i386-pc/eltorito.img' \
-no-emul-boot -boot-load-size 4 -boot-info-table --grub2-boot-info \
-eltorito-alt-boot \
-e '/efi.img' -no-emul-boot \
/tmp/prox

# clear up your files
rm -rf /tmp/prox

# The new iso is repacked.iso
 
THanks @stacks13, i used your blueprint, to set up a little script to do the work:

Bash:
#!bin/bash
# REQUIRED once: apt install mkisofs squashfs-tools
rm repacked.iso
#copy into proxmox.mbr the mbr from original iso (first 512byte)
dd if=$1 bs=512 count=1 of=/tmp/proxmox.mbr

#  create temp folders
mkdir /tmp/pve_iso
mkdir /tmp/pve_iso_tmp
mkdir /tmp/pve_squash/

# mount iso (iso name and path is given with parameter to script)

mount -t iso9660 -o loop $1 /tmp/pve_iso_tmp
tar cf - -C /tmp/pve_iso_tmp . | tar xfp - -C /tmp/pve_iso
umount /tmp/pve_iso_tmp
# extract squashfs
unsquashfs -d /tmp/pve_squash/ /tmp/pve_iso/pve-installer.squashfs

# replace timeout
# Update the timeout to 60
sed -i -e 's/timeout 10;/timeout 60;/g' /tmp/pve_squash/etc/dhcp/dhclient.conf
echo "new dhclient.conf:\
";
cat /tmp/pve_squash/etc/dhcp/dhclient.conf
# exit 0;
#Then I squashed it back
rm /tmp/pve_iso/pve-installer.squashfs
mksquashfs /tmp/pve_squash/ /tmp/pve_iso/pve-installer.squashfs


xorriso -as mkisofs \
-o repacked.iso \
-r -V 'PVE' \
-isohybrid-mbr /tmp/proxmox.mbr \
-partition_offset 16 \
--protective-msdos-label \
/tmp/pve_iso

Thank you all!!
# # clear up your files
rm -rf /tmp/pve_*
rm /tmp/proxmox.mbr


# The new iso is repacked.iso

so u can just copy the code to a mod_dhcpd.sh file
chmod +x mod_dhcpd.sh
and then run it on your iso:
mod_dhcpd.sh <PATH-TO_PVE-ISO>
so someithing like:
./mod_dhcp.sh ./proxmox-ve_8.3-1-auto-from-http-url.iso
 

Attachments

I'm trying to use these scripts in a Docker container, and was running into issues with it requiring root access. I was able to get it working using `osirrox` instead of `mount` and using `fakeroot` to allow the squashfs tools to unpack / edit a filesystem that is supposed to have root access.

Bash:
#!/bin/bash
# This script is used to modify the Proxmox installer to increase the DHCP timeout
# Before running this script, you need to install the dependencies as follows:
#    apt-get install proxmox-auto-install-assistant mkisofs squashfs-tools xorriso fakeroot
#
# Usage: ./mod-dhcp.sh /path/to/proxmox.iso /path/to/output.iso

# create a temporary file
TEMP_FILE=$(mktemp).iso

#copy into proxmox.mbr the mbr from original iso (first 512byte)
dd if=$1 bs=512 count=1 of=/tmp/proxmox.mbr

#  create temp folders
mkdir /tmp/pve_iso
mkdir /tmp/pve_squash/

# mount iso (iso name and path is given with parameter to script)

osirrox -indev $1 extract / /tmp/pve_iso_tmp
tar cf - -C /tmp/pve_iso_tmp . | tar xfp - -C /tmp/pve_iso
# extract squashfs
fakeroot -- bash -c "
unsquashfs -d /tmp/pve_squash/ /tmp/pve_iso/pve-installer.squashfs
sed -i -e 's/timeout 10;/timeout 60;/g' /tmp/pve_squash/etc/dhcp/dhclient.conf
echo \"new dhclient.conf:\"
echo \"\"
cat /tmp/pve_squash/etc/dhcp/dhclient.conf
rm /tmp/pve_iso/pve-installer.squashfs
mksquashfs /tmp/pve_squash/ /tmp/pve_iso/pve-installer.squashfs"

xorriso -as mkisofs \
-o "$TEMP_FILE" \
-r -V 'PVE' \
-isohybrid-mbr /tmp/proxmox.mbr \
-partition_offset 16 \
--protective-msdos-label \
/tmp/pve_iso

echo "Copying the modified iso from temp location to $2"
cp "$TEMP_FILE" "$2"

# # clear up your files
rm -rf /tmp/pve_*
rm /tmp/proxmox.mbr
rm "$TEMP_FILE"