github.com/hashicorp/packer@v1.14.3/website/content/guides/automatic-operating-system-installs/preseed_ubuntu.mdx (about)

     1  ---
     2  page_title: Unattended Debian/Ubuntu Installation
     3  description: |-
     4    Learn how to use a preseed file to automatically answer installation
     5    questions and enable Packer to connect to your Debian instance.
     6  ---
     7  
     8  # Unattended Installation for Debian
     9  
    10  Unattended Debian/Ubuntu installation is done via "preseed" files
    11  
    12  These files are generally named "preseed.cfg". They are not
    13  Packer-specific tools, though we do make use of them.
    14  
    15  If, after following this guide, you're still having issues getting a preseed
    16  file working, We recommend you read the official documentation on
    17  [preseed files](https://wiki.debian.org/DebianInstaller/Preseed).
    18  
    19  The guide here is hopefully enough to get you started, but isn't a replacement
    20  for the official documentation.
    21  
    22  ## When To Use a Preseed File
    23  
    24  If you are installing the operating system from a mounted iso as part of
    25  your Packer build, you will need to use a preseed file. For example, you're
    26  building an image from scratch using the [vmware-iso](/packer/plugins/builders/vmware/iso),
    27  [virtualbox-iso](/packer/plugins/builders/virtualbox/iso), or
    28  [hyperv-iso](/packer/plugins/builders/hyperv/iso) builders.
    29  
    30  If you are not installing the operating system, you won't need to provide a
    31  preseed file. If you are using a pre-built image in a cloud, you don't need to
    32  worry about preseed files.
    33  
    34  ## How to make a Preseed File
    35  
    36  You can either start from an example preseed file from a known repo (take a look
    37  at the examples links below), or you can start with the official [example
    38  preseed](https://www.debian.org/releases/stable/example-preseed.txt), and
    39  comment or uncomment the options as you need them.
    40  
    41  ## Where to put the preseed file
    42  
    43  The `-iso` builders mentioned above all have an `http_dir` or an `http_content`
    44  option. Any file inside of your `http_dir` or `http_content` will be served on a
    45  local fileserver for your virtual machine to be able to access. One very common
    46  use for this directory is to use it to provide your preseed file.
    47  
    48  You then reference the file using a `boot_command` to kick off the installation.
    49  In the example below, the `preseed/url` command line option is being
    50  used in the `/install/vmlinuz command`. The `{{ .HTTPIP }}` and
    51  `{{ .HTTPPort }}` options are special Packer template options that will get set
    52  by Packer to point to the HTTP server we create, so that your boot command can
    53  access it. For an example of a working boot_command, refer to the Examples section
    54  below. For more information on how boot_command works, refer to the
    55  boot_command section of the docs for whatever builder you are using.
    56  
    57  ## What does Packer _need_ the preseed file to do?
    58  
    59  Packer needs the preseed file to handle any questions that would normally be
    60  answered interactively during a Debian installation.
    61  
    62  If you want to be able to use provisioners, the preseed file must also install
    63  SSH so that Packer can connect to the instance.
    64  
    65  ## Examples
    66  
    67  A very minimal example of a preseed file can be found below. Much of this was
    68  copied from the official example-preseed shared above. Notice that we are
    69  installing ssh via `d-i pkgsel/include string openssh-server` and configuring
    70  a username so that Packer will be able to connect.
    71  
    72  You need to make sure that your mirror settings are properly configured for your
    73  specific distribution of Debian.
    74  
    75  ```shell
    76  # Preseeding only locale sets language, country and locale.
    77  d-i debian-installer/locale string en_US
    78  
    79  # Keyboard selection.
    80  d-i console-setup/ask_detect boolean false
    81  d-i keyboard-configuration/xkb-keymap select us
    82  
    83  choose-mirror-bin mirror/http/proxy string
    84  
    85  ### Clock and time zone setup
    86  d-i clock-setup/utc boolean true
    87  d-i time/zone string UTC
    88  
    89  # Avoid that last message about the install being complete.
    90  d-i finish-install/reboot_in_progress note
    91  
    92  # This is fairly safe to set, it makes grub install automatically to the MBR
    93  # if no other operating system is detected on the machine.
    94  d-i grub-installer/only_debian boolean true
    95  
    96  # This one makes grub-installer install to the MBR if it also finds some other
    97  # OS, which is less safe as it might not be able to boot that other OS.
    98  d-i grub-installer/with_other_os boolean true
    99  
   100  ### Mirror settings
   101  # If you select ftp, the mirror/country string does not need to be set.
   102  d-i mirror/country string manual
   103  d-i mirror/http/directory string /ubuntu/
   104  d-i mirror/http/hostname string archive.ubuntu.com
   105  d-i mirror/http/proxy string
   106  
   107  ### Partitioning
   108  d-i partman-auto/method string lvm
   109  
   110  # This makes partman automatically partition without confirmation.
   111  d-i partman-md/confirm boolean true
   112  d-i partman-partitioning/confirm_write_new_label boolean true
   113  d-i partman/choose_partition select finish
   114  d-i partman/confirm boolean true
   115  d-i partman/confirm_nooverwrite boolean true
   116  
   117  ### Account setup
   118  d-i passwd/user-fullname string vagrant
   119  d-i passwd/user-uid string 1000
   120  d-i passwd/user-password password vagrant
   121  d-i passwd/user-password-again password vagrant
   122  d-i passwd/username string vagrant
   123  
   124  # The installer will warn about weak passwords. If you are sure you know
   125  # what you're doing and want to override it, uncomment this.
   126  d-i user-setup/allow-password-weak boolean true
   127  d-i user-setup/encrypt-home boolean false
   128  
   129  ### Package selection
   130  tasksel tasksel/first standard
   131  d-i pkgsel/include string openssh-server build-essential
   132  d-i pkgsel/install-language-support boolean false
   133  
   134  # disable automatic package updates
   135  d-i pkgsel/update-policy select none
   136  d-i pkgsel/upgrade select full-upgrade
   137  ```
   138  
   139  Here's an example of the vmware-iso builder being used to call this preseed.
   140  In this case, it is assumed that the file is saved as preseed.cfg inside of a
   141  directory called "http", and Packer is being called from the directory
   142  containing the "http" directory.
   143  
   144  ```hcl
   145    "builders": [
   146      {
   147        "boot_command": [
   148          "<esc><wait>",
   149          "<esc><wait>",
   150          "<enter><wait>",
   151          "/install/vmlinuz<wait>",
   152          " initrd=/install/initrd.gz",
   153          " auto-install/enable=true",
   154          " debconf/priority=critical",
   155          " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed_2.cfg<wait>",
   156          " -- <wait>",
   157          "<enter><wait>"
   158        ],
   159        "boot_wait": "10s",
   160        "guest_os_type": "ubuntu-64",
   161        "http_directory": "http",
   162        "iso_checksum": "file:///Users/mmarsh/dev/repro_cases/packer_cache/shasums.txt",
   163        "iso_url": "http://old-releases.ubuntu.com/releases/14.04.1/ubuntu-14.04.1-server-amd64.iso",
   164        "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now",
   165        "ssh_password": "vagrant",
   166        "ssh_username": "vagrant",
   167        "ssh_wait_timeout": "10000s",
   168        "tools_upload_flavor": "linux",
   169        "type": "vmware-iso"
   170      }
   171    ],
   172  ```
   173  
   174  For more functional examples of a Debian preseeded installation, you can refer to the Chef-maintained [bento](https://github.com/chef/bento#using-packer) box [preseed](https://github.com/chef/bento/blob/6fe9fa20d1f37e916a7babdee87c89ba38ce54a4/packer_templates/http/debian/preseed.cfg),
   175  the Ubuntu [autoinstall config](https://github.com/chef/bento/blob/6fe9fa20d1f37e916a7babdee87c89ba38ce54a4/packer_templates/http/ubuntu/user-data), their [builders](https://github.com/chef/bento/blob/6fe9fa20d1f37e916a7babdee87c89ba38ce54a4/packer_templates/pkr-builder.pkr.hcl).