Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 15 Jan 2022 12:51:44 +0200
From:      Daniel Braniss <danny@cs.huji.ac.il>
To:        Aryeh Friedman <aryeh.friedman@gmail.com>
Cc:        "freebsd-virtualization@freebsd.org" <virtualization@freebsd.org>
Subject:   Re: Using bhyve to develop and OS -- tips on how?
Message-ID:  <F487D0D2-F240-4EC4-B531-71EAE01198EF@cs.huji.ac.il>
In-Reply-To: <CAGBxaXmJYkiAP99RvjMkyOUqz9=BzNOTjTiQgf7EppRw2KfmHQ@mail.gmail.com>
References:  <CAGBxaXmJYkiAP99RvjMkyOUqz9=BzNOTjTiQgf7EppRw2KfmHQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--Apple-Mail=_0DF206A3-8765-4967-AFE0-88A7089E02DD
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8



> On 15 Jan 2022, at 11:29, Aryeh Friedman <aryeh.friedman@gmail.com> =
wrote:
>=20
> 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).
>=20
> 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).
>=20
> --=20
> Aryeh M. Friedman, Lead Developer, http://www.PetiteCloud.org =
<http://www.petitecloud.org/>;

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

I=E2=80=99m 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=E2=80=99s stuff, I=E2=80=99m =
using a ZFS volume=20
		zfs create h/vm
		echo vm_dir=3Dzfs: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=E2=80=99:
		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=20
 	this is my file:
	loader=3D=E2=80=9Cbhyveload"
	uefi=3D=E2=80=9Cyes"
	cpu=3D2
	memory=3D32G
	network0_type=3D"virtio-net=E2=80=9D
	network0_switch=3D=E2=80=9Csystem"
	disk0_type=3D"virtio-blk=E2=80=9D
	disk0_name=3D"/dev/zvol/h/bhv-09=E2=80=9D
	disk0_dev=3D=E2=80=9Ccustom"
	uuid=3D"8a9b6432-6a08-11ec-87fb-b49691970814"
	network0_mac=3D"58:9c:fc:0f:b0:d4=E2=80=9D	=20

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 =E2=80=98vm console bhv0=E2=80=99, and =
check the logs in bhv0/vm-bhyve.log


all this should get you started, good luck

	danny



--Apple-Mail=_0DF206A3-8765-4967-AFE0-88A7089E02DD
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3Dutf-8"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;" class=3D""><br =
class=3D""><div><br class=3D""><blockquote type=3D"cite" class=3D""><div =
class=3D"">On 15 Jan 2022, at 11:29, Aryeh Friedman &lt;<a =
href=3D"mailto:aryeh.friedman@gmail.com" =
class=3D"">aryeh.friedman@gmail.com</a>&gt; wrote:</div><br =
class=3D"Apple-interchange-newline"><div class=3D""><div dir=3D"ltr" =
class=3D""><div class=3D"">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).</div><div class=3D""><br =
class=3D""></div><div class=3D"">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).<br =
class=3D""></div><div class=3D""><div class=3D""><br class=3D"">-- <br =
class=3D""><div dir=3D"ltr" class=3D"gmail_signature" =
data-smartmail=3D"gmail_signature"><div dir=3D"ltr" class=3D"">Aryeh M. =
Friedman, Lead Developer, <a href=3D"http://www.petitecloud.org/" =
target=3D"_blank" class=3D"">http://www.PetiteCloud.org</a><br =
class=3D""></div></div></div></div></div>
</div></blockquote></div><br class=3D""><div class=3D"">as the saying =
goes:&nbsp;</div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>'there are many ways to skin a =
cat=E2=80=99</div><div class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); color: rgb(0, 0, 0);" class=3D"">so this is what I did (still fresh =
since it was done only some weeks ago)</span></div><div class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=3D""><br =
class=3D""></span></div><div class=3D"">I=E2=80=99m using vm-bhyve, so =
you will need sysutils/vm-bhyve and probably =
sysutils/bhyve-firmware</div><div class=3D""><br class=3D""></div><div =
class=3D"">step 0:</div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>decide where you want vm to store =
it=E2=80=99s stuff, I=E2=80=99m using a ZFS volume&nbsp;</div><div =
class=3D""><span class=3D"Apple-tab-span" style=3D"white-space:pre">		=
</span>zfs create h/vm</div><div class=3D""><span class=3D"Apple-tab-span"=
 style=3D"white-space: pre;">		</span><span style=3D"caret-color:=
 rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; =
font-size: 12px;" class=3D"">echo vm_dir=3Dzfs:h/vm &gt;&gt; =
/etc/rc.conf</span></div><div class=3D""><span style=3D"caret-color: =
rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; =
font-size: 12px;" class=3D""><br class=3D""></span></div><span =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px;" class=3D"">&nbsp; &nbsp; vm =
init</span><div class=3D""><br style=3D"caret-color: rgb(0, 0, 0); =
color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px;" =
class=3D""><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space: pre;">	</span><span style=3D"caret-color: =
rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; =
font-size: 12px;" class=3D"">cp -p /usr/local/share/examples/vm-bhyve/* =
/h/vm/.templates/</span></div><div class=3D""><font color=3D"#000000" =
face=3D"Menlo-Regular" class=3D""><span style=3D"font-size: 12px;" =
class=3D"">&nbsp; &nbsp; not&nbsp;really needed but you get some =
ideas.</span></font></div><div class=3D""><span style=3D"caret-color: =
rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; =
font-size: 12px;" class=3D""><br class=3D""></span></div><span =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px;" class=3D"">&nbsp; &nbsp; this is needed =
if we want to do 'service vm start</span><font color=3D"#000000" =
face=3D"Menlo-Regular" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-size: 12px;" class=3D"">=E2=80=99:</span></font><br =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px;" class=3D""><span class=3D"Apple-tab-span"=
 style=3D"white-space:pre">		</span><span style=3D"caret-color:=
 rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; =
font-size: 12px;" class=3D"">echo =
vm_enable&gt;&gt;/etc/rc.conf</span></div><div class=3D""><font =
color=3D"#000000" face=3D"Menlo-Regular" class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); font-size: 12px;" class=3D""><br =
class=3D""></span></font></div><div class=3D""><font color=3D"#000000" =
face=3D"Menlo-Regular" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-size: 12px;" class=3D"">step 1:</span></font></div><div =
class=3D""><font color=3D"#000000" face=3D"Menlo-Regular" class=3D""><span=
 style=3D"caret-color: rgb(0, 0, 0); font-size: 12px;" class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>if you =
will need networking:</span></font></div><div class=3D""><font =
color=3D"#000000" face=3D"Menlo-Regular" class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); font-size: 12px;" class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>vm switch =
create public (or any other name)</span></font></div><div class=3D""><font=
 color=3D"#000000" face=3D"Menlo-Regular" class=3D""><span =
class=3D"Apple-tab-span" style=3D"caret-color: rgb(0, 0, 0); font-size: =
12px; white-space: pre;">	</span><span style=3D"font-size: 12px;" =
class=3D"">vm switch add =
public&nbsp;some-network-interface</span></font></div><div =
class=3D""><font color=3D"#000000" face=3D"Menlo-Regular" class=3D""><span=
 style=3D"font-size: 12px;" class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>eg: vm</span></font><span =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px;" class=3D"">&nbsp;switch add public =
bge0</span></div><div class=3D""><font color=3D"#000000" =
face=3D"Menlo-Regular" class=3D""><span style=3D"font-size: 12px;" =
class=3D""><br class=3D""></span></font><div class=3D"">step 2: &nbsp;if =
client is not diskless, it will need a disk, again I opted for a ZFS =
volume</div></div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>zfs create -sV 4G =
h/root.bhv0</div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>gpart create -s GPT =
&nbsp;/dev/zvol/h/root.bhv0</div><div class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>gpart add =
-t efi -s 64M -l efi /dev/zvol/h/root.bhv0</div><div class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">		=
</span>note: tried to make it smaller but got into trouble with =
news_msdosfs</div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>gpart add -t freebsd-ups -l =
root.bhv0 /dev/zvol/h/root.bhv0</div><div class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>mount -t =
msdosfs /dev/gpt/efi /mnt</div><div class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>mkdir -p =
/mnt/EFI/BOOT</div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>cp -p /boot/loader.efi =
/mnt/EFI/BOOT/BOOTx64.efi</div><div class=3D""><br class=3D""></div><div =
class=3D"">step 3:</div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>vm create bhv0</div><div =
class=3D""><br class=3D""></div><div class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>now cd to =
&nbsp;vm_dir&nbsp;and edit bhv0/bhv0.conf&nbsp;</div><div =
class=3D"">&nbsp;<span class=3D"Apple-tab-span" style=3D"white-space:pre">=
	</span>this is my file:</div><span class=3D"Apple-tab-span" =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px; white-space: pre;">	</span><font =
color=3D"#000000" face=3D"Menlo-Regular" class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); font-size: 12px;" =
class=3D"">loader=3D=E2=80=9Cbhyveload"</span></font><br =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px;" class=3D""><span class=3D"Apple-tab-span"=
 style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px; white-space: pre;">	</span><font =
color=3D"#000000" face=3D"Menlo-Regular" class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); font-size: 12px;" =
class=3D"">uefi=3D=E2=80=9Cyes"</span></font><br style=3D"caret-color: =
rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; =
font-size: 12px;" class=3D""><span style=3D"caret-color: rgb(0, 0, 0); =
color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px;" =
class=3D""><span class=3D"Apple-tab-span" style=3D"white-space:pre">	=
</span>cpu=3D2</span><br style=3D"caret-color: rgb(0, 0, 0); color: =
rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px;" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, =
0); font-family: Menlo-Regular; font-size: 12px;" class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	=
</span>memory=3D32G</span><br style=3D"caret-color: rgb(0, 0, 0); color: =
rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px;" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, =
0); font-family: Menlo-Regular; font-size: 12px;" class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	=
</span>network0_type=3D"virtio-net</span><font color=3D"#000000" =
face=3D"Menlo-Regular" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-size: 12px;" class=3D"">=E2=80=9D</span></font><br =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px;" class=3D""><span class=3D"Apple-tab-span"=
 style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px; white-space: pre;">	</span><font =
color=3D"#000000" face=3D"Menlo-Regular" class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); font-size: 12px;" =
class=3D"">network0_switch=3D=E2=80=9Csystem"</span></font><br =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px;" class=3D""><span style=3D"caret-color: =
rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; =
font-size: 12px;" class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	=
</span>disk0_type=3D"virtio-blk</span><font color=3D"#000000" =
face=3D"Menlo-Regular" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-size: 12px;" class=3D"">=E2=80=9D</span></font><br =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px;" class=3D""><span style=3D"caret-color: =
rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; =
font-size: 12px;" class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	=
</span>disk0_name=3D"/dev/zvol/h/bhv-09</span><font color=3D"#000000" =
face=3D"Menlo-Regular" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-size: 12px;" class=3D"">=E2=80=9D</span></font><br =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px;" class=3D""><span class=3D"Apple-tab-span"=
 style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px; white-space: pre;">	</span><font =
color=3D"#000000" face=3D"Menlo-Regular" class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); font-size: 12px;" =
class=3D"">disk0_dev=3D=E2=80=9Ccustom"</span></font><br =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px;" class=3D""><span style=3D"caret-color: =
rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; =
font-size: 12px;" class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	=
</span>uuid=3D"8a9b6432-6a08-11ec-87fb-b49691970814"</span><br =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px;" class=3D""><div class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 12px;" class=3D""><span class=3D"Apple-tab-span"=
 style=3D"white-space:pre">	=
</span>network0_mac=3D"58:9c:fc:0f:b0:d4</span><font color=3D"#000000" =
face=3D"Menlo-Regular" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-size: 12px;" class=3D"">=E2=80=9D</span></font><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	=
</span>&nbsp;</div><div class=3D""><br class=3D""></div><div =
class=3D"">you can now try and boot - at least UEFI part should work =
since there is no root partition yet.</div><div class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>vm start =
bhv0</div><div class=3D"">you can get the console with =E2=80=98vm =
console bhv0=E2=80=99, and check the logs in bhv0/vm-bhyve.log</div><div =
class=3D""><br class=3D""></div><div class=3D""><br class=3D""></div><div =
class=3D"">all this should get you started, good luck</div><div =
class=3D""><br class=3D""></div><div class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	=
</span>danny</div><div class=3D""><br class=3D""></div><div class=3D""><br=
 class=3D""></div></body></html>=

--Apple-Mail=_0DF206A3-8765-4967-AFE0-88A7089E02DD--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?F487D0D2-F240-4EC4-B531-71EAE01198EF>