Building bhyve Images using makefs and mkimg
Posted: October 29, 2014 at 8:57 PM
Recently Neel Natu committed work to enable bhyve to run on AMD processors. My main development machine is an AMD A10-5700, so the commit enables me to use bhyve for testing.
EDIT: Anish Gupta did the work that Neel Natu committed. Thanks Anish!
I had previously built images using makefs
and mkimg
for a CF card for
use in another machine, so being able to build images to use with bhyve
makes sense.
First, you need to make sure that you have a complete source check out along with a completed buildworld and buildkernel. Then follow these steps:
- Install world and distribution into a temporary directory using the
NO_ROOT
option:
This preps everything with the defaults as necessary.make installworld DESTDIR=<tmpdir> -DDB_FROM_SRC -DNO_ROOT make distribution DESTDIR=<tmpdir> -DDB_FROM_SRC -DNO_ROOT
- Install a kernel either into a different directory (I do this) or into the same directory above:
make installkernel DESTDIR=<tmpkerndir> -DNO_ROOT KERNCONF=<conf>
- Make a directory with your custom configuration files. The basics
are
/etc/rc.conf
and/etc/fstab
and you might want/firstboot
on there too. You will also need aMETALOG
file which contains the permissions for the files. This is just a standardmtree
file, so you could usemtree
to generate this instead of creating it by hand. The file contents are below. - Build the ufs image using the
makeroot.sh
script in the src tree attools/tools/makeroot/makeroot.sh
:/usr/src/tools/tools/makeroot/makeroot.sh -e <custdir>/METALOG -e <tmpkerndir>/METALOG -p <tmpdir>/etc/master.passwd -s 2g ufs.img root
- Build the disc image:
mkimg -s gpt -b <tmpdir>/boot/pmbr -p freebsd-boot:=<tmpdir>/boot/gptboot -p freebsd-swap::1G -p freebsd-ufs:=ufs.img -o disc.img
- Run the image:
sh /usr/share/examples/bhyve/vmrun.sh -d disc.img vm0
There you have it. Besides running the image, all the other steps can be done as a normal user w/o root access.
EDIT: You also might want to include an /entropy
file (populated with 4k
from /dev/random
) in your custom directory so that the image has a good
seed for entropy at first boot for things such as sshd key generation.
File contents:
-
/etc/fstab
:
/dev/vtbd0p3 / ufs rw 1 1
-
Custom
METALOG
:
#mtree 2.0 ./etc/rc.conf type=file uname=root gname=wheel mode=0644 ./etc/fstab type=file uname=root gname=wheel mode=0644 ./firstboot type=file uname=root gname=wheel mode=0644