Can Packer be used to install and provision a bare metal server? Packer provides webserver with repository packages and preseed/kickstart and can run some other provision softwares(ansible,puppet, chef, etc). Could it be used to install bare metal servers? If yes, how should a packer .json look like?
Ny way to provision bare-metal with Packer
packer
Related Solutions
EBS is using networked storage for your EC2 instance's root device, it's easy to spin up an instance and create an AMI using EBS because the volume is already available outside your instance. EBS also allows for a larger root device -- greater than 8GB.
Instance-store (or ephemeral) root devices are somewhat more resilient as they don't rely on a network connection but they are harder to create AMIs for: you must load keys onto the packer-launched machine, bundle the root device, upload it to S3 and then create an AMI using the S3 bucket. Instance-store root devices are usually around 8GB which can be a drawback as well.
I like sticking with instance-store EC2 Instance as a personal preference -- anecdotally the times I've been bit by EC2 being down it was largely due to EBS issues.
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):
The argument list
The kernel command line is parsed into a list of strings (boot arguments) separated by spaces. Most of the boot arguments have the form:
name[=value_1][,value_2]...[,value_10]
where 'name' is a unique keyword that is used to identify what part of the kernel the associated values (if any) are to be given to. Note the limit of 10 is real, as the present code handles only 10 comma separated parameters per keyword. (However, you can reuse the same keyword with up to an additional 10 parameters in unusually complicated situations, > assuming the setup function supports it.)
Most of the sorting is coded in the kernel source file init/main.c. First, the kernel checks to see if the argument is any of the special arguments 'root=', 'nfsroot=', 'nfsaddrs=', 'ro', 'rw', 'debug' or 'init'. The meaning of these special arguments is described below.
Then it walks a list of setup functions to see if the specified argument string (such as 'foo') has been associated with a setup function ('foo_setup()') for a particular device or part of the kernel. If you passed the kernel the line foo=3,4,5,6 then the kernel would search the bootsetups array to see if 'foo' was registered. If it was, then it would call the setup function associated with 'foo' (foo_setup()) and hand it the arguments 3, 4, 5, and 6 as given on the kernel command line.
Anything of the form 'foo=bar' that is not accepted as a setup function as described above is then interpreted as an environment variable to be set.
A (useless?) example would be to use 'TERM=vt100' as a boot argument.Any remaining arguments that were not picked up by the kernel and were not interpreted as environment variables are then passed onto PID 1, which is usually the init(1) program. The most common argument that is passed to the init process is the word 'single' which instructs it to boot the computer in single user mode, and not launch all the usual daemons. Check the manual page for the version of init(1) installed on your system to see what arguments it accepts.
Here is my boot_command
section in my virtualbox-iso
builder (for Ubuntu 18.04):
boot_command:
- '<esc><esc><enter><wait>'
- '/install/vmlinuz noapic fb=false '
- 'auto=true '
- 'hostname={{.Name}} '
- 'url=http://{{.HTTPIP}}:{{.HTTPPort}}/ubuntu.seed '
- 'initrd=/install/initrd.gz '
- 'http_proxy={{user `http_proxy`}} '
- 'packer_host={{.HTTPIP}} '
- 'packer_port={{.HTTPPort}} '
- 'hello=world '
- 'quiet --- <enter>'
The http_proxy
, packer_host
, packer_port
, and hello
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 the hello
environment variable into a file:
d-i preseed/late_command string echo $hello > /target/home/packer/hello
When I import and start up the OVA, that file will be in my home directory with world
as its contents.
Best Answer
I had a similar question. I found this issue thread on using Packer with PXE boot.
https://github.com/hashicorp/packer/issues/955
From the thread, Vasiliy Tolstov commented:
[It's] very simple: install all needed stuff inside a VM (for Debian live-boot, for fedora/centos Dracut with the ability to boot from the net). after [building] that [with] packer run the following script (example for Debian):
and in packer download artifacts from vm: