Build a FreeBSD 10.1-release Openstack Image with bsd-cloudinit

Table of Contents

We are going to prepare a FreeBSD image for Openstack deployment. We do this by creating a FreeBSD 10.1-RELEASE instance, installing it and converting it using bsd-cloudinit. We'll use the CloudVPS public Openstack cloud for this. Create an account there and install the Openstack command line tools, like nova, cinder and glance.

When you are going to do stuff with the Openstack command line clients, load this file:

source computerc

That way, your authentication data are loaded and you don't have to give parameters like -os-username and such.

Openstack Overview

Openstack is a datacenter virtualization plaform consisting out of many different tools and services. For this tutorial it is important to know the following ones.

Compute (Nova)

This is the virtualization service. It works with a hypervisor to create and manage virtual machines. You can create a VM based on a specific "Flavour", which is just a definition of specs like disk, cpu and ram.

Block Storage (Cinder)

This is the service which makes block devices (volumes) available to services. A flavour can not be changed, just resized. If you want extra storage you need to create a volume, attach it to the VM and mount it there for use.

Images (Glance)

This is the service which holds all the images. Images can be used to boot a VM from. Images can be prepared with tools like cloud-init to make them behave better in a cloud environment, for example, setting an SSH key or password at boot.

ISO Installation

Booting from an ISO with a disk attached is quite tricky in Openstack. This FreeBSD tutorial can be used for any ISO which needs to be installed. The process is as following:

Boot an instance from an ISO image with an extra volume attached.

Install the software on that volume.

Stop the install VM.

Start a new VM with the volume as root disk. (To test, prepare and configure the installation).

Stop and destory that VM.

Convert the volume to an image.

You then have an image with your own installation available to boot new vm's from.

Lets get started.

Upload the ISO to glance

Start by uploading the FreeBSD 10.1-RELEASE ISO to Openstack using the Glance client:

Note down the ID like usual, in our case: dad95c7d-f921-4e89-8ea7-99e1654d65fe.

Install FreeBSD 10.1

Do a standard install of FreeBSD 10. Use the Openstack console to do that.

These are my simple install settings:

default keymap

hostname: freebsd.public.cloudvps.com

Just lib32 and ports, no doc, games or src

Manual Partition Layout:

vtbd0 GPT

vtbd0p1 64KB freebsd-boot

vtbd0p2 16GB freebsd-ufs mountpoint / (root)

The root partition must be the last partition on the drive so that it can expand at run time to the disk size that your instance type provides. Also note that bsd-cloudinit currently has a hard-coded bug/assumption that this is the second partition.

Root password P@ssw0rd

Network:

adapter: vtnet0

ipv4: dhcp

ipv6: slaac

search: public.cloudvps.com

UTC: no, timezone 8 EUROPE 34 NETHERLANDS

Services at boot:

sshd

ntpd

moused

dumpd

local_unbound

Extra users: no

Exit, open a shell.

Stop the install VM

Shut the instance from FreeBSD using shutdown -p now and after that via nova:

nova stop <install vm id>

Detach the volume:

nova volume-detach <install vm id> <install root volume id>

When the volume is detached you can delete the installation VM. We don't need it anymore:

nova delete <install vm id>

The volume will not be destroyed when the VM is deleted.

Boot a new VM with the volume as root disk

Boot a new instance with the volume freebsd was installed on as the root disk:

Here we use --block-device to specify that the only disk attached to the instance should be the volume source=volume,id=<volume id>. This can also be an image as source. The destination is also a volume, this can also be local.

If you have more block devices specified here you should make sure there is only 1 with the bootindex 0, that is the disk the VM will try to boot from.

Prepare FreeBSD for Cloud Init

If you get a mountroot error from the bootloader, enter the following: ufs:/dev/vtbd0p3.

Change /etc/fstab after the fact, change ada0 to vtbd0 for VirtIO support.

Login Users

By default cloudinit will create a user named freebsd which has sudo privileges without password. However, if you want to enable root login, so not with a freebsd user, you need to add your SSH key, enable root login and add some extra configuration later on for cloud-init.