Skip to content

Instantly share code, notes, and snippets.

@bobhenkel
Forked from chr4/freebsd-image.md
Created July 19, 2023 03:24
Show Gist options
  • Save bobhenkel/358c43fba8a21b83f9291e36c779c381 to your computer and use it in GitHub Desktop.
Save bobhenkel/358c43fba8a21b83f9291e36c779c381 to your computer and use it in GitHub Desktop.
OpenStack FreeBSD image creation

FreeBSD 12.0 OpenStack image creation

This was adapted from this document

ISO image creation

Download ISO image, then run:

openstack image create --file ~/Downloads/FreeBSD-12.0-RELEASE-amd64-disc1.iso --disk-format iso --container-format bare "FreeBSD-12.0-RELEASE-amd64-disc1.iso"

Set image_id using id of created image.

Installation

# The minimal FreeBSD installation requires around 600MB
openstack volume create --size 1 "FreeBSD-12.0-RELEASE-root"

Set volume_id using id of created volume.

Next, boot the installer:

openstack server create --image=$image_id --key-name $ssh_key --flavor m1.small --network $network_id --block-device-mapping "vdb=$volume_id:::0" "FreeBSD-12.0-RELEASE-install"

Set install_vm_id using id of created VM.

Now go to the OpenStack console for this VM, and run through the installation sequence:

  • Perform standard FreeBSD install
  • Distribution select: No package sets (keep minimal)
  • Partitioning: Auto (ZFS)
  • Partition: Set swap partition to 0, use stripe
  • Root password: toor (temporary)
  • Network configuration: vtnet0, IPv4 DHCP, IPv6 SLAAC, default resolver setup
  • Clock: UTC
  • Timezone: UTC
  • System configuration: sshd, dumpdev
  • System hardening: Clean /tmp, Disable remote syslog, Disable sendmail
  • Add user accounts: None
  • Open shell
    • run shutdown -p now

Now stop and remove the installation VM, retaining the volume:

# Seems pointless if already stopped; can be skipped
openstack server stop $install_vm_id

openstack server remove volume $install_vm_id" "$volume_id

openstack server delete $install_vm_id

Post-installation

  • Make the volume bootable using Horizion UI
  • Start up a new VM using our installation volume using Horizon UI

Configure the console for OpenStack

cat <<EOF >>/boot/loader.conf
console="comconsole,vidconsole"
autoboot_delay="1"
EOF

Install cloud-init

pkg install py26-cloud-init ca_root_nss
echo "cloudinit_enable="YES" >> /etc/rc.conf

Configure dual-stack network with DHCP

Install dual-dhclient

pkg install dual-dhclient

Configure /etc/rc.conf accordingly

dhclient_program="/usr/local/sbin/dual-dhclient"
ifconfig_vtnet0="DHCP"
ifconfig_vtnet0_ipv6="inet6 accept_rtadv"
rtsold_enable="YES"

Clean up

# Remove cloud-init configured settings from rc.conf
grep -v hostname= /etc/rc.conf |grep -v ifconfig_vtnet0= > /x && mv /x /etc/rc.conf
truncate -s0 /etc/resolv.conf

set history = 0
history -c
rm -rf /root/.ssh /root/.history
rm -rf /var/log/*

# Remove SSH keys
rm /etc/sshd/ssh_host*

# Remove temporary root password (only do this once you verified your setup!)
vipw # Exchange the password hash for root with *, analogue to the other system users

# Remove cloud-init configuration
rm -rf /run/cloud-init /var/lib/cloud

# In case you logged in using the default cloud-init user, make sure to remove the user as well
rmuser freebsd

# Shutdown the system
shutdown -p now

Remove the configuration VM:

openstack server delete "$configure_vm_id"

Create OpenStack image

Finally, create an OpenStack image from this volume:

openstack image create --volume $volume_id FreeBSD-12.0-RELEASE

This will be used to create new VMs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment