From nobody Sat Jan 15 10:51:44 2022 X-Original-To: virtualization@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id F26791958CB4 for ; Sat, 15 Jan 2022 10:51:53 +0000 (UTC) (envelope-from danny@cs.huji.ac.il) Received: from kabab.cs.huji.ac.il (kabab.cs.huji.ac.il [132.65.116.210]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4JbZjh37LVz3pwh for ; Sat, 15 Jan 2022 10:51:52 +0000 (UTC) (envelope-from danny@cs.huji.ac.il) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cs.huji.ac.il; s=57791128; h=References:To:Cc:In-Reply-To:Date:Subject:Mime-Version:Content-Type:Message-Id:From; bh=pFstWcRju4EexXzTnFXhXdLEbFbZkyXlGxVuJCkxN6o=; b=Fdt6Rdsigr8hqD9zjAXm7+U3WfZ4K6asEcOsEoKLT2FjWSwdBtsSU9+BxDFMYhatRmuGRuC3LphujCggjvrO9SecvdwDf2+dqxeFhF9sOMDGJg6pduVWKY/fjswYYTcA9lNNkdvyKrNztVBxefc0KzAStzaeQZYrSWgrBUGdEVl4LD3qUeSuqIvit79BtOeZvBDBepfxtR4R5hv7CYghZh2j3U4Qa0hFSeFhmtRG+9HLpvNLj4iSGXqVMRQ5xMnLe+obCmVZUAGwjhTL3lqyGakrPJbIhI+XlBXzZGK7/MmGWEmDol8E0P+63JijdaRcAK8P7OhdwTf2YqsfGwkm5A==; Received: from imac.bk.cs.huji.ac.il ([132.65.179.42] helo=smtpclient.apple) by kabab.cs.huji.ac.il with esmtp id 1n8geu-0008xH-Ar; Sat, 15 Jan 2022 12:51:44 +0200 From: Daniel Braniss Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_0DF206A3-8765-4967-AFE0-88A7089E02DD" List-Id: Discussion List-Archive: https://lists.freebsd.org/archives/freebsd-virtualization List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-virtualization@freebsd.org X-BeenThere: freebsd-virtualization@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.40.0.1.81\)) Subject: Re: Using bhyve to develop and OS -- tips on how? Date: Sat, 15 Jan 2022 12:51:44 +0200 In-Reply-To: Cc: "freebsd-virtualization@freebsd.org" To: Aryeh Friedman References: X-Mailer: Apple Mail (2.3693.40.0.1.81) X-Rspamd-Queue-Id: 4JbZjh37LVz3pwh X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=cs.huji.ac.il header.s=57791128 header.b=Fdt6Rdsi; dmarc=pass (policy=none) header.from=huji.ac.il; spf=none (mx1.freebsd.org: domain of danny@cs.huji.ac.il has no SPF policy when checking 132.65.116.210) smtp.mailfrom=danny@cs.huji.ac.il X-Spamd-Result: default: False [-2.28 / 15.00]; RCVD_TLS_LAST(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[cs.huji.ac.il:s=57791128]; FREEFALL_USER(0.00)[danny]; FROM_HAS_DN(0.00)[]; R_SPF_NA(0.00)[no SPF record]; MV_CASE(0.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[cs.huji.ac.il:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[huji.ac.il,none]; NEURAL_HAM_SHORT(-0.98)[-0.977]; MLMMJ_DEST(0.00)[virtualization]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; SUBJECT_ENDS_QUESTION(1.00)[]; ASN(0.00)[asn:378, ipnet:132.64.0.0/15, country:IL]; RCVD_COUNT_TWO(0.00)[2]; MID_RHS_MATCH_FROM(0.00)[] X-ThisMailContainsUnwantedMimeParts: N --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 = 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 = 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

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

as the saying = goes: 
'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 
= 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 
 = 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 =  

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--