So, I found a workaround that wasn't as well documented as I had hoped.
Describing it here in case some other hapless sysadmin ever has the same
problem with debian installer not attempting dhcp over an interface other
than eth0 and doesn't know what to do

If preseed.cfg exists in the root of the initrd, debian-installer will
execute any commands listed there before it tries to download the preseed
file listed in the pxeboot config.  So, if that file happens to contain
preseed commands to statically configure an IP address, guess what, it will
do that.
Of course, this means having an IP config pre-generated in the initrd,
right?  You're right back to step 1 with needing to know network
configuration for the host.
Nope
If you execute `dhclient` in the init script, before it executes `busybox
init`, it will broadcast across all configurable network interfaces.  If it
gets a valid response, it will get an IP address.  I mentioned this earlier
as my first attempt at bypassing the netcfg dhcp autoconfig that is the
root of all these problems.  netcfg SO VERY HELPFULLY clears all running IP
configurations when it detects interfaces, whether they be configured via
dhcp or statically assigned with `ip addr add ...`.  What netcfg DOES NOT
clear is the contents of `/var/lib/dhcp.dhclient.leases`, which contains an
interface name, ip address, hostname, gateway, nameservers, domain name,
etc, that the dhcp server responded with.
>From this file, one can parse out information needed for preseed/netcfg
static IP configuration; which can be written as answers in preseed.cfg.

So, I made the following changes to the initrd:

   - add `dhclient -v` early in the init script
   - created a custom program to parse the contents of
   /var/lib/dhcp/dhclient.leases and generate preseed netcfg answers that get
   written to preseed.cfg in the initrd root. It can be written in whatever
   you want, I found it easiest to write it in golang and put the compiled
   binary in the initrd's /bin
   - added a line to init to execute this program immediately after the
   dhcp client finishes
   - removed /media in the initrd

That last step may seem perplexing.  One really helpful behavior I
discovered is that debian-installer will mount /dev/sda1 to /media if it
reads a preseed.cfg file stored in the root of the initrd.  I assume it
does this because why would you want a preseed file on disk, unless you're
on a liveCD, which will probably have more data in /media that is
essential.  This wouldn't be a problem if the partitioner didn't default to
using /dev/sda, because why would anyone anywhere want to install their OS
into the first or only disk present in a system?  So, if /dev/sda1 exists
and has a filesystem, it gets mounted to /media, and no combination of di
late commands or partman options to forcibly unmount stuff seemed to work.
It would always prompt me to unmount the partition before proceeding.
Deleting the /media mountpoint means that it can't mount /dev/sda1 there.
In a netboot initrd, /media is empty anyway.

Reply via email to