Is it possible to add a variable via the boot prompt to the Debian installer, so that variable can be used in a preseed file?
In particular, I'm trying to solve the following problem:
We have a pretty extensive post-install script that is generally downloaded from a server. But now I want to create Packer images and keep the post-install script in version control together with the other Packer files. For accessing the preseed, I can do "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg" in the boot command. But now I want the installer to download the post-install script from that same location.
Currently, the post-install hook looks like this:
d-i preseed/late_command string wget -q -O /tmp/postinstall.sh http://our.public.server/postinstall.jessie.sh ; sh /tmp/postinstall.sh
Ideally, I'd like to do something like:
d-i preseed/late_command string wget -q -O /tmp/postinstall.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/postinstall.jessie.sh ; sh /tmp/postinstall.sh
But of course the Debian installer will not replace those with the required values. So I was thinking that it might be possible to pass environment variable-like variables to the installer that we can use in the preseed file.
Any hints or tips are appreciated!
EDIT: Tried adding the late_command to the boot command, but that didn't get picked up.
EDIT: Tried preseed/run, but it runs in a different environment which does not allow the in-target command.
EDIT: This can be a workaround: How do I pipe commands together in a debian preseed file? But I'd prefer to have the script in a separate file. If it's not possible, it's not possible, though.
It depends on what OS you are using, but the Linux kernel will let you specify environment variables as kernel parameters. The Linux kernel documentation has some good information around it (important paragraph bolded):
Here is my
boot_command
section in myvirtualbox-iso
builder (for Ubuntu 18.04):The
http_proxy
,packer_host
,packer_port
, andhello
parameters are completely optional, and will be converted into environment variables by the kernel.In my
ubuntu.seed
file, I have the following line to print out thehello
environment variable into a file:When I import and start up the OVA, that file will be in my home directory with
world
as its contents.Ok, I solved it myself (with some help from @lieter_). Not too proud of it, but it works:
This does what I need, since we always add a url= to our command line when installing.
While looking to solve much the same issue I learned about some magic that is baked into the
debian-installer
. You can usepreseed_fetch
to pull from the URL if you add a/./
at the point in the URL that you want to set as therootpath
for other commands to perform their relative fetches against.Given a server with a preseed folder and a scripts folder with other files you want to use, if you pass
url=http://{{.HTTPIP}}:{{.HTTPPort}}/http/./preseed/ubuntu.seed
you can then reference other files relative to the root path likepreseed_fetch /scripts/somescript.sh /tmp/somescript.sh
.More information can be found at https://hands.com/d-i/lenny/start.cfg and https://hands.com/d-i/ under the heading "url=magic".