Re: Using bhyve to develop and OS -- tips on how?

From: Daniel Braniss <danny_at_cs.huji.ac.il>
Date: Sat, 15 Jan 2022 10:51:44 UTC

> On 15 Jan 2022, at 11:29, Aryeh Friedman <aryeh.friedman@gmail.com> wrote:
> 
> I want to develop a OS completely from scratch, i.e. starting with the first instruction encountered after POST and everything above it (mostly for fun).
> 
> I want to use bhyve to do this any tips on how to get started (I have found a few tutorials on how to do the asm part of a MBR but that's about as far as I have gotten).
> 
> -- 
> Aryeh M. Friedman, Lead Developer, http://www.PetiteCloud.org <http://www.petitecloud.org/>

as the saying goes: 
	'there are many ways to skin a cat’
so this is what I did (still fresh since it was done only some weeks ago)

I’m using vm-bhyve, so you will need sysutils/vm-bhyve and probably sysutils/bhyve-firmware

step 0:
	decide where you want vm to store it’s stuff, I’m using a ZFS volume 
		zfs create h/vm
		echo vm_dir=zfs:h/vm >> /etc/rc.conf

    vm init

	cp -p /usr/local/share/examples/vm-bhyve/* /h/vm/.templates/
    not really needed but you get some ideas.

    this is needed if we want to do 'service vm start’:
		echo vm_enable>>/etc/rc.conf

step 1:
	if you will need networking:
	vm switch create public (or any other name)
	vm switch add public some-network-interface
	eg: vm switch add public bge0

step 2:  if client is not diskless, it will need a disk, again I opted for a ZFS volume
	zfs create -sV 4G h/root.bhv0
	gpart create -s GPT  /dev/zvol/h/root.bhv0
	gpart add -t efi -s 64M -l efi /dev/zvol/h/root.bhv0
		note: tried to make it smaller but got into trouble with news_msdosfs
	gpart add -t freebsd-ups -l root.bhv0 /dev/zvol/h/root.bhv0
	mount -t msdosfs /dev/gpt/efi /mnt
	mkdir -p /mnt/EFI/BOOT
	cp -p /boot/loader.efi /mnt/EFI/BOOT/BOOTx64.efi

step 3:
	vm create bhv0

	now cd to  vm_dir and edit bhv0/bhv0.conf 
 	this is my file:
	loader=“bhyveload"
	uefi=“yes"
	cpu=2
	memory=32G
	network0_type="virtio-net”
	network0_switch=“system"
	disk0_type="virtio-blk”
	disk0_name="/dev/zvol/h/bhv-09”
	disk0_dev=“custom"
	uuid="8a9b6432-6a08-11ec-87fb-b49691970814"
	network0_mac="58:9c:fc:0f:b0:d4”	 

you can now try and boot - at least UEFI part should work since there is no root partition yet.
	vm start bhv0
you can get the console with ‘vm console bhv0’, and check the logs in bhv0/vm-bhyve.log


all this should get you started, good luck

	danny