Packer installation: Difference between revisions

From Alpine Linux
(Created page with "== Basic understanding == Alpine Linux installer is just a bunch of shell scripts, see [https://git.alpinelinux.org/alpine-conf/tree/setup-alpine.in setup-alpine.in] in [http...")
 
m (change /dev/vg0/lv_root to /dev/sda3)
 
(3 intermediate revisions by one other user not shown)
Line 10: Line 10:
   "root<enter><wait>",
   "root<enter><wait>",
   "ifconfig eth0 up && udhcpc -i eth0<enter><wait5>",
   "ifconfig eth0 up && udhcpc -i eth0<enter><wait5>",
   "wget http://{{ .HTTPIP }}:{{ .HTTPPort }}/answers<enter><wait>",
   "wget http://<nowiki>{{ .HTTPIP }}:{{ .HTTPPort }}</nowiki>/answers<enter><wait>",
   "setup-alpine -f answers<enter><wait5>",
   "setup-alpine -f answers<enter><wait5>",
   "{{user `ssh_password`}}<enter><wait>",
   "<nowiki>{{user `ssh_password`}}</nowiki><enter><wait>",
   "{{user `ssh_password`}}<enter><wait5>",
   "<nowiki>{{user `ssh_password`}}</nowiki><enter><wait5>",
   "<wait>y<enter><wait10>",
   "<wait>y<enter><wait10>",
   "rc-service sshd stop<enter>",
   "rc-service sshd stop<enter>",
   "mount /dev/vg0/lv_root /mnt<enter>",
   "mount /dev/sda3 /mnt<enter>",
   "echo 'PermitRootLogin yes' >> /mnt/etc/ssh/sshd_config<enter>",
   "echo 'PermitRootLogin yes' >> /mnt/etc/ssh/sshd_config<enter>",
   "umount /mnt<enter>",
   "umount /mnt<enter>",
Line 30: Line 30:
* as 'setup-alpine' script asks to configure root password, it just does that
* as 'setup-alpine' script asks to configure root password, it just does that
* after that, you can run whatever commands you want, but keep in mind that it is still installer media; you can 'reboot' into installed system and run 'provisioners'
* after that, you can run whatever commands you want, but keep in mind that it is still installer media; you can 'reboot' into installed system and run 'provisioners'
The 'answer' file can be something like this:
KEYMAPOPTS="us us"
HOSTNAMEOPTS="-n alpine"
INTERFACESOPTS="auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
"
DNSOPTS="-n 8.8.8.8"
TIMEZONEOPTS="-z UTC"
PROXYOPTS="none"
APKREPOSOPTS="-1"
SSHDOPTS="-c openssh"
NTPOPTS="-c openntpd"
DISKOPTS="-L -m sys /dev/vda"


== packer example provisioners ==
== packer example provisioners ==
Line 37: Line 55:
     "type": "shell",
     "type": "shell",
     "scripts": [
     "scripts": [
       "{{ template_dir }}/../scripts/00_alpinelinux_base.sh",
       "<nowiki>{{ template_dir }}</nowiki>/../scripts/00_alpinelinux_base.sh",
       "{{ template_dir }}/../scripts/99_alpinelinux_base.sh"
       "<nowiki>{{ template_dir }}</nowiki>/../scripts/99_alpinelinux_base.sh"
     ]
     ]
   }
   }
  ],
  ],
[[Category:Installation]]

Latest revision as of 17:15, 17 March 2021

Basic understanding

Alpine Linux installer is just a bunch of shell scripts, see setup-alpine.in in alpine-conf repository. Understanding this is key to success.

packer example boot_command

This is a part of 'boot_command' from QEMU builder:

"boot_command": [
  "root<enter><wait>",
  "ifconfig eth0 up && udhcpc -i eth0<enter><wait5>",
  "wget http://{{ .HTTPIP }}:{{ .HTTPPort }}/answers<enter><wait>",
  "setup-alpine -f answers<enter><wait5>",
  "{{user `ssh_password`}}<enter><wait>",
  "{{user `ssh_password`}}<enter><wait5>",
  "<wait>y<enter><wait10>",
  "rc-service sshd stop<enter>",
  "mount /dev/sda3 /mnt<enter>",
  "echo 'PermitRootLogin yes' >> /mnt/etc/ssh/sshd_config<enter>",
  "umount /mnt<enter>",
  "reboot<enter>"
],

What it does is to mimic a human typing in "console" (VNC). Before running Alpine Linux installer (ie. 'setup-alpine') it does:

  • logins in as 'root' (installation media doesn't require password)
  • configures first network interfaces via DHCP
  • gets 'answers' file from 'packer' built-in HTTP server to be able to start automated installation
  • runs Alpine Linux 'setup-alpine' installer script with 'answers' file
  • as 'setup-alpine' script asks to configure root password, it just does that
  • after that, you can run whatever commands you want, but keep in mind that it is still installer media; you can 'reboot' into installed system and run 'provisioners'

The 'answer' file can be something like this:

KEYMAPOPTS="us us"
HOSTNAMEOPTS="-n alpine"
INTERFACESOPTS="auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
"
DNSOPTS="-n 8.8.8.8"
TIMEZONEOPTS="-z UTC"
PROXYOPTS="none"
APKREPOSOPTS="-1"
SSHDOPTS="-c openssh"
NTPOPTS="-c openntpd"
DISKOPTS="-L -m sys /dev/vda"

packer example provisioners

"provisioners": [
  {
    "type": "shell",
    "scripts": [
      "{{ template_dir }}/../scripts/00_alpinelinux_base.sh",
      "{{ template_dir }}/../scripts/99_alpinelinux_base.sh"
    ]
  }
],