FreeBSD installation on Proxmox hypervisor using Hashicorp Packer. This template has cloud-init support.
- Proxmox VE hypervisor - where the template will be stored in.
- Hashicorp Packer.
- xorriso - because it will be necessary to use
additional_iso_files
.
- Clone this repository:
$ git clone https://github.com/maykopetersen/freebsd-proxmox-packer.git
- Install all the missing plugins required in a Packer config:
$ cd freebsd-proxmox-packer
$ packer init .
- Change the variable's values (see more in the next topics).
- Build the template:
$ packer build .
The most important values that you MUST change are:
proxmox_api_url
: refers toproxmox_url
argument fromProxmox ISO
. You can remove this argument and usePROXMOX_URL
environment variable.node
: refers tonode
argument.zfs_pool
: refers tostorage_pool
andcloud_init_storage_pool
arguments. Usually islocal-lvm
.network_bridge
: refers tonetwork_adapters{bridge}
argument.network_vlan
: refers tonetwork_adapters{vlan_tag}
argument. The network vlan tag.network_mac_address
: refers tonetwork_adapters{mac_address}
argument. If your DHCP server assigns addresses based on MAC address, you must configure this argument.network_static {}
map: This map containsIP
,netmask
andgw
if you use static address. If you use DHCP, these values must be""
. Thedns_server_ip
is thenameserver
value in/etc/resolv.conf
; thesrc_domains
is thesearch
value in/etc/resolv.conf
(both are necessary to installqemu-guest-agent
package).optional(_type_)
doesn't work in Packer like Terraform. Because of this, these arguments MUST exist.
users {}
map: Map with users and their passwords.
You must change all values in this file.
proxmox_user
: The user with access to create templates in your Proxmox cluster. You can remove this argument and usePROXMOX_USERNAME
environment variable.
Important
The user must have the following privileges:
- SDN.Use
- VM.Allocate
- VM.Audit
- VM.Config.CDROM
- VM.Config.CPU
- VM.Config.Cloudinit
- VM.Config.Disk
- VM.Config.HWType
- VM.Config.Memory
- VM.Config.Network
- VM.Config.Options
- VM.Console
- VM.Monitor
- VM.PowerMgmt
- Datastore.AllocateSpace
- Datastore.AllocateTemplate
- Datastore.Audit
- Datastore.Allocate
proxmox_pass
: User's pass fromproxmox_user
. You can remove this argument and usePROXMOX_PASSWORD
environment variable.root_inicial_pass
: The initial root pass used by Packer to SSH the FreeBSD.root_pass
: The root pass stored in final VM template.
As these arguments are local variables, they can be defined by vault functions.
- Clone the template to a VM using Proxmox UI.
- Configure Cloud-init options, putting your public key in
SSH Public Key
field. - Do other configurations (HD, RAM, CPUs, Network devices, etc).
- Start your VM.
- Access your VM from your machine:
$ ssh -i <your-private-key-file> freebsd@<VM_IP>
- Become
root
:
freebsd@machine:~ % sudo su -
root@machine:~ #
It's important to install the agent in the early process because if it is disabled, you will see the following error in a build debug process:
[DEBUG] Error getting SSH address: 500 QEMU guest agent is not running
Packer needs to know the VM's IP address to connect it using SSH. Packer does this using qemu-guest-agent
.
If you don't want to install any package or if you don't want to bootstrap pkg
from a remote repository in the bsdinstaller
process, you must configure ssh_host
in source
block with a fixed IP (defined by var.network_static
) used by this template.
You can't use the bootonly
FreeBSD image in Packer like you could do with a Debian netinstall
image, for example. This occurs because FreeBSD first needs to install the OS base before performing any operation. The bootonly
image doesn't contain the OS base, so you have to go online and download it. Since the DNS configuration is done AFTER the OS base has been installed, it is impossible to resolve any external names. Even if you put the IP in the BSDINSTALL_DISTSITE
field as instructed in the bsdinstall
manual and get an IP from your DHCP server with internet access, it won't work.
Simplified BSD License. Copyright (c) 2024-2024, Mayko Petersen [email protected].
Tsiry Sandratraina |
---|
help me with some ideas from this repository.