Unattended FreeBSD installation

Eugene Grosbein eugen at grosbein.net
Tue Feb 5 23:35:36 UTC 2019


06.02.2019 6:12, Simon Ser wrote:

> Hi all,
> 
> For the purposes of a CI service [1], I want to write a script that
> generates a fresh qcow2 FreeBSD image. So far I've been using
> bsdinstall(8) and this has been working well when testing locally [2].
> However this doesn't work when run from SSH because bsdinstall(8) uses
> dialog(1), which requires a TTY (or fails).
> 
> I've been wondering: you offer qcow2 images available for download on
> your website, but how are these generated? I don't think I can use these
> directly since I need to enable sshd, but I could probably re-use your
> image generation script.
> 
> If it's not possible to use the same script, do you have suggestions to
> make it work?

In fact, there is absolutely nothing sacral in generating bootable FreeBSD image.

Just create empty directory and use tar to extract two files
from ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/11.2-RELEASE/ there:
kernel.txz, base.txz (and optionally ports.txz). 

Add local files and configs, maybe packages.
chroot(8) is handy if target arch is same as of build box
Don't forget to mount devfs before running commands with chroot: mount -t devfs devfs $mountpoint

Determine total size with "du -s" and create UFS image with makefs(8) using -s flag
to specify size of an image adding some spare space for future use.

Attach generated UFS image using mdconfig to get /dev/md0 and add bootstrap code to the image:
gpart bootcode -b /boot/boot /dev/md0

Finally, wrap generated image into your container of choice (qcow2 or MBR or GPT partitioning etc.)
Maybe you'll need to add primary bootstrap code depending on container type.
That would be "gpart bootcode -b /boot/mbr ..." in face of disk image with MBR partitioning
that also would need extra "gpart set -a active -i 1" call to mark partition bootable.

That's all.


More information about the freebsd-hackers mailing list