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