Score:0

Advices on automating installation for Debian 11

cn flag

I'm currently trying to automate Debian 11 template creation through Packer for Nutanix environment and need some advices about preseeding/automating Debian installation.

First of all, after reading this bible https://www.debian.org/releases/stable/amd64/apbs02.fr.html I went into using preseed.cfg file. I started with the preseed.cfg file provided by Debian then adapt some stuff to fit my needs. Finally, I validate the syntax using debconf-set-selections -c preseed.cfg command => everything is fine.

Now, i saw there's 3 differents ways to use preseed.cfg :

  • through initrd : seems quite difficult to me and didn't find an easy tutorial/documentation
  • through network : not an option at this moment due to some firewall restriction
  • through file : seems the easiest and best option at the moment

When Packer starts the VM creation, it loads debian ISO as a CD-ROM in 1st position, and an empty virtual disk in the second position. I tell packer to load my preseed.cfg scripts as a cd-rom, so from an hypervisor perspective, a second cd-rom drive is mounted in the 3rd position.

BUT, in this case, VM boot on ISO (cd-rom 1st position), it doesn't mount the second cd-rom drive that have the preseed.cfg file and i can't access it unless I go to the debian console then mount the 2nd drive.

I saw a forum about uploading preseed.cfg into my original debian.iso folder and modifying the /isolinux/txt.cfg file like this (and then recreates the iso with OSCDIMG) :

label install
    menu label ^Install
    kernel /install.amd/vmlinuz
    append vga=788 initrd=/install.amd/initrd.gz preseed/file=/cdrom/preseed/preseed.cfg --- quiet

My question is : is it fair to act like this ? is there something i missed or something easier to make it work easily ?

EDIT : i tried the initrd method, the only remaining thing is that i have to manually select Automated Install. How to get rid of this action ?

EDIT2: 02-01-2023

  • i tried 2 more different things, 1st having this line in isolinux/txt.cfg append auto=true priority=critical vga=788 initrd=/install.amd/initrd.gz preseed/file=/cdrom/preseed.cfg --- quiet => NOK, it still boot on boot menu (but ok if i select automated install manually, so it means preseed.cfg works pretty well)
  • and 2nd, test with prompt 1 timeout 1 in isolinux.cfg => goes directly to select language manually...

EDIT3: 03-01-2023 here's the preseed.cfg i use :

# SETUP AUTO MODE
d-i auto-install/enable boolean true
d-i debconf/priority select critical
# LANGUAGE & KEYMAP
d-i debian-installer/locale string fr_FR
d-i keyboard-configuration/xkb-keymap select fr(latin9)
# NETWORK
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string template-debian-11-x64
d-i netcfg/get_domain string my_domain.net
d-i netcfg/hostname string template-debian-11-x64
# MIRRORS
d-i mirror/http/hostname string  http://deb.debian.org/debian/ 
d-i mirror/http/hostname string http://security.debian.org/debian-security 
# ACCOUNTS
d-i passwd/root-password password mypassword!
d-i passwd/root-password-again password mypassword!
d-i passwd/user-fullname string user
d-i passwd/username string user
d-i passwd/user-password password mypassword!
d-i passwd/user-password-again password mypassword!
d-i passwd/user-uid string 1010
d-i passwd/user-default-groups string si audio cdrom video
# LVM PART
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string lvm
d-i partman-auto-lvm/guided_size string 95%
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto/choose_recipe select multi
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
#APT
d-i apt-setup/cdrom/set-first boolean false
tasksel tasksel/first multiselect standard, ssh-server
# GRUB
d-i grub-installer/bootdev string /dev/sda
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
#FINAL
d-i finish-install/reboot_in_progress note

Thanks a lot

Gael

Score:1
to flag

Regarding your first question, I don't think there's any easier way to enable automated install for debian installer in terms of passing the preseed file to it. Mounting a second image could be a good idea for your specific need, but AFAIK debian installer does not respect a second media for its preseed and there are no workarounds that I know of (FYI, ubuntu's subiquity installer does support such input).

To achieve a "no-hands" install, I'll explain 2 things that should be taken care of.

Debian installer config (preseed)

To make the debian installer go fully automatic, you'll need this in your preseed file:

d-i debconf/priority select critical

This will simply tell debian installer not to ask questions it can find an answer to. In addition to that, you need to enable the auto mode with d-i auto-install/enable boolean true, but ignore this for now (I'll talk about auto mode in the next part). From auto mode doc:

The auto kernel parameter is an alias for auto-install/enable and setting it to true delays the locale and keyboard questions until after there has been a chance to preseed them, while priority is an alias for debconf/priority and setting it to critical stops any questions with a lower priority from being asked.

P.S. You can pass some the question/answers as kernel parameters with key=value format, where key is an alias. That requires changing boot parameters. See the full list: aliases useful with preseeding

Bootloader config

In addition to installer configuration, we need to make some changes to the bootloader too. For isolinux bootloader to work in an unattended install scenario, I make these 2 changes to its config files inside the iso:

  1. Set auto mode via a kernel parameter.
  2. Tell isolinux auto-select the default entry in the menu.

First change is done by adding auto=true to the append line of the default menu entry. For debian 11, I found "Graphical install" to be the default entry. Since the config for this entry is read from isolinux/gtk.cfg, this change should be applied in that file. e.g. you can change your example bootloader config append line to "append auto=true vga=...".

Second goal is achieved by changing timeout 0 to timeout 1 in isolinux/isolinux.cfg (see this).

Note 1: The auto=true kernel parameter is the alias for d-i auto-install/enable boolean true preseed config. It turned out that it should be enabled by kernel parameters for some reasons. Putting its equivalent in preseed file still ends up in language selection prompt waiting for user's input (maybe by the time that the preseed file is read by debian installer it's too late to enable the auto mode?).

Note 2: You don't need prompt 1 in isolinux config. It will probably do the opposite of what you want, which is preventing automatic selection of default entry (see the last line of this section).

Note 3: Changing bootloader config requires modifications in iso contents (and thus an iso rebuild).

Note 4: The isolinux bootloader is commonly used for BIOS (legacy) systems. In UEFI systems, you need to configure GRUB instead.

inframan avatar
cn flag
Hi ! Have a look to my EDIT2 part in the original post, tried some stuff you mentionned but it fails again.
Georgee avatar
to flag
@motorbass I just added bootloader config to my answer. From my previous experience on isolinux, going directly to language menu means there was something wrong in its config files (some sort of syntax error, a typo, etc.). So I suggest you double-check the syntax when you finished editing them. Good luck!
inframan avatar
cn flag
Thanks for advising. Btw i've just add the preseed.cfg in my original post. About your #2 , i use isolinux (so legacy) cause my Nutanix doesn't support UEFI for Debian at the moment. I add preseed.cfg into initrd then proceed to the 1. and 2. as you mentionned and also append auto=true and priority=critical to my bootloader but itstill brings me into select a language prompt. that's weird...
Georgee avatar
to flag
@motorbass Looks like I was missing something about the auto mode, which caused that weird behavior. Updated the answer accordingly. To summarize, the "auto=true" must be passed as a kernel parameter (put in "append" line). I ran a test and had no problems so I guess that was the missing part. I've also looked at your preseed config and found no problems with it. It should work fine.
inframan avatar
cn flag
Still go to langage selection.. I think i really missed something. If i sum up : i add preseed.cfg to initrd, then modify isolinux.cfg timeout from 0 to 1, then add default install into txt.cfg and my append line look like : append auto=true vga=788 initrd=/install.amd/initrd.gz --- quiet
inframan avatar
cn flag
Huum i figure out something great. If I only add preseed.cfg to initrd then boot on graphical menu and select automatic install, it works. but if i do the same, then change timeout from 0 to 1 then it goes directly to select a langage menu.
Georgee avatar
to flag
@motorbass I did my tests by putting the pressed file directly in the root of iso and used "preseed/file=/cdrom/preseed.cfg". I have not used initrd at all. Do you modify the initrd image? Can you point me to any kind of source/document that you followed for your initrd approach so I can test that too?
Georgee avatar
to flag
@motorbass Another thing I noticed: You should add both "preseed/file=..." and "auto=true" to your append line. Note that "txt.cfg" is for text mode install, and "gtk.cfg" is responsible for graphical install. Edit the append line in both if you want to be sure, but for me the graphical install was the default selection and editing "gtk.cfg" was enough.
inframan avatar
cn flag
About the initrd method here it is : https://wiki.debian.org/DebianInstaller/Preseed/EditIso - i'm having a new test about gtk.cfg as you mentionned. let you know
inframan avatar
cn flag
by modifying gtk.cfg (+timeout from 0 to 1 + preseed into initrd) it goes directly to download debconf preconfiguration file, so i'll have another try (hope the good one) by adding file:/cdrom/preseed.cfg in the append line and copy the preseed at the / of my iso.
inframan avatar
cn flag
it works so smoothly ! a huge huge huge huge thank you !!!!!!! ( by reading all the comments , i'd say my biggest error was to modify txt.cfg instead of gtk.cfg. but that's why it works once in the past, because by disablign vesamenu it goes to txt mode, so txt.cfg was loaded and it works)
Georgee avatar
to flag
@motorbass Hope it works. About the initrd method: since you are booting a modified iso anyway, you might as well just put the preseed in there directly. No need to touch the initrd. It just makes things complicated for you. Modifying initrd is useful for situations where you are passing kernel and initrd images separately to your target machine (which doesn't seem to be the case here).
Georgee avatar
to flag
@motorbass That's great! Yeah I kinda got confused myself. Got some of the configurations mixed up. But I'm glad it worked out at the end ;)
Score:1
za flag

Use a boot_command in Packer, which will send keypresses to the VM and, basically, type things into it. What it'll "type" is up to you. This goes to the packer file (I named it base.pkr.hcl):

...
variable "preseed_file" {
  type    = string
  default = "base.preseed"
}
...
source "qemu" "qemu" {
  ...
  boot_command = [
    "<wait><wait><wait><esc><wait><wait><wait>",
    "/install.amd/vmlinuz ",
    "initrd=/install.amd/initrd.gz ",
    "auto=true ",
    "debian-installer/locale=ru_RU.UTF-8 ",
    "keyboard-configuration/xkb-keymap=ru ",
    "keyboard-configuration/optionscode=grp:caps_toggle,lv3:ralt_switch,compose:rctrl,grp_led:scroll ",
    "url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",
    "hostname=${var.vm_name} ",
    "domain=${var.domain} ",
    "interface=auto ",
    "vga=788 noprompt quiet --<enter>"
  ]
  http_content         = { "/preseed.cfg" = templatefile(var.preseed_file, { var = var }) }
  ...
}
...

This way, packer will both serve the preseed file to the VM via HTTP and effectively override the boot options that are built into ISO with ones that you supply within packer file. No need to do any changes to ISO.


I am using Qemu; this is a copy of what I end up with when I did that half of a year ago. It looks like Nutanix builder doesn't have this boot_command; however, you can try to build the system using e.g. Qemu or Virtualbox and then use it with Nutanix. I just don't know.

inframan avatar
cn flag
Hi. Actually the nutanix builder doesn't have it as you mention too. I think the best at the moment should be to prepare the iso with a preseed file inside, then just launch/use it through nutanix provider. I newly edit my original post (edit 2) if you got any other idea :)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.