Giter Club home page Giter Club logo

hcloud-freebsd's Introduction

hcloud-freebsd

Hetzner Cloud auto-provisioning for FreeBSD

Introduction

This repository enables auto-provisioning of FreeBSD instances on Hetzner Cloud.

Currently only Linux auto-provisioning is enabled by default however by initially manually configuring a FreeBSD instance and adding the hcloud utility and rc.d script included in this repository, it is possible to create a snapshot which can be used as a base instance and supports the normal auto-configuration functions available either in the cloud console or via the api/cli tools.

Note that currently FreeBSD 12.X doesn't boot on CPX (AMD/EPYC) instances - only CP (XEON). FreeBSD 13.X DOES boot however.

Installation

OS Installation

To install FreeBSD 13 on ARM64 machines (cax__) see README-ARM64.md.

Note: This isnt necessary for FreeBSD 14 (ISO is available from ISO menu and normal installation works fine)

Automated installation of FreeBSD instances is not currently available for Hetzner Cloud, however it is possible to manually configure an instance as follows:

  • Create a VM instance using the cloud console. Pick a server type that matches the one you want to provision as a template (usually the smallest SSD type - currently CX11 - as you can resize instances upwards). The base image doesn't matter at this stage.

  • When the server has booted select the instance in the cloud console and attach a FreeBSD ISO image (select ISO Images and search for an appropriate FreeBSD instance). The script will also support HardenedBSD however you will need to ask support to make the ISO available.

  • From the cloud console open the device console (>_) and reboot server.

  • The FreeBSD installer should now start and you can install FreeBSD as normal. See the FreeBSD handbook for details. The recommended options for installation are:

    • Appropriate keymap/hostname
    • Default install components (kernel-dbg/lib32)
    • Configure networking (vtnet0/IPv4/DHCP) - don't worry about configuring IPv6 at the moment (will be configured for cloned instances through cloud-config)
    • Select distrobution mirror - default is fine (ftp://ftp.freebsd.org)
    • Select Auto (UFS) partition type, Entire Disk, GPT, and accept default partitions (it is also possible to use ZFS if prefered - though UFS might be more suitable for low-memory instances).
    • (Distribution files should now install)
    • Set root password (this is only needed for initial configuration - password login will be disabled for instances)
    • Select appropriate Time Zone and Date/Time
    • Select default services (at least sshd)
    • Chose security hardening options (I usually select all of these)
    • Do not add users to the system unless you specifically want these as part of the base image
    • Exit installer making shre you select Yes to drop to shell to complete configuration
  • From the installation shell follow the instructions in config.sh (either manually or by downloading the script):

  • The instance will power off at the end of the installation

  • From the Hetzner cloud console

    • Unmount ISO
    • From Snapshots menu Take Snapshot
    • When the snapshot has been created you can now use this as a template to start new cloud instances

Creating Instances

  • To create a new instance click on Add Server as normal and select the appropriate snapshot from the Images / Snapshots tab (you can also view the the snapshot page and create a new server from there).

  • Select the options as normal on the Add Server page. These will be picked up by the rc/hcloud script on firstboot and the server configured.

  • The script supports auto-configuration of the following settings:

    • hostname
    • network interfaces (iprimary interface IPv4 and IPv6 addresses, additional private interfaces will be autodetected and configured to run DHCP)
    • ssh keys will be added to root user
    • userdata script will be run. Note that the userdata script will be written to disk and run directly so must be a valid script for the target system - in particular you will almost certainly just want to use a plain /bin/sh script (first line should be #!/bin/sh). Multipart files and cloud-config (#cloud-config) data are not supported (GZ compressed files are supported).
  • Note that additional volumes are not auto-configured but will be automatically detected by the kernel (/dev/da[123...]) so could be configured/mounted using the user-data script.

  • If needed it is possible to grow the FS for larger instances automatically via the userdata script. It should also be possible to use rc.d/growfs (needs growfs_enable=YES in rc.conf and the root partition to be the last partition) although I haven't tested this.

  • Alternatively it is posisble to use the additional space to add an additional FS (eg. for ZFS) from the userdata script. You can check if the image has been installed onto a larger sized instance by running gpart show da0 | grep -qs CORRUPT and then gpart recover / gpart add etc.

  • A copy of the cloud configuration parameters (split by section), the user-data script, and an installation log are saved in the /var/hcloud directory.

  • The rc(8) system will automatically delete the /firstboot flag after the first-boot so the script will only run once.

  • It is also possible to configure new instances via the API or hcloud utility - eg:

    • hcloud server create --image <imageid> --name <name> --user-data-from-file <userdata> --ssh-key <keyname> --type <type> --location <location>

Maintaining Images

  • To maintain images (run freebsd-update/update pkgs etc) a couple of example scripts are provides in the /util directory.

    • update.sh will automatically run basic OS/pkg updates on the image and then resave (deleting original)

    • patch.sh will do the same but first launch a single use sshd instance on port 9022 to allow interactive configuration

    • (Note that in both cases the imageid will change)

hcloud-freebsd's People

Contributors

paulc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hcloud-freebsd's Issues

HardenedBSD support

I've recently played around with the ideas in this repo and made some templates; I've also successfully created a HardenedBSD-based template, and since HBSD is 99% FreeBSD, it would be a very minor change to add support for it.

The only required change would be in config.sh, where the lines:

freebsd-update fetch --not-running-from-cron | cat
freebsd-update install --not-running-from-cron || echo "No updates available"

would be replaced with:

# hardenedbsd support
if which hbsd-update; then
    hbsd-update
else
    freebsd-update fetch --not-running-from-cron | cat
    freebsd-update install --not-running-from-cron || echo "No updates available"
fi

I would open a PR directly, but first I wanted to ask here how you would like to merge this into the README - just applying the same changes as in config.sh or differently?

(I also plan to play with some different BSDs, I already have ISOs for Dragonfly and NetBSD added, and probably OpenBSD at some point; but other than maybe Dragonfly, these are probably too different from FreeBSD to be included here, so I would probably create a new repo or a hard fork for those.)

Edit: Ah, and I am aware that everyone who wants to use this for hbsd will currently need to ask support to include the ISO. Don't know if that's good, but don't know what to do about it either. That means this should probably also be mentioned in the README.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.