Re: booting linux on bhyve

From: Mario Marietto <marietto2008_at_gmail.com>
Date: Wed, 24 May 2023 20:40:25 UTC
I've fixed the bug. This line :

if ! printf '%s\n' "${vncs}" | grep "${session}"; then

becomes like this :

if ! printf '%s\n' "${vncs}" | grep "${session#vm}"; then

and more vms can boot at the same time.

On Wed, May 24, 2023 at 3:27 PM Mario Marietto <marietto2008@gmail.com>
wrote:

> I've created a script like the one below. Actually I use the same pattern
> for every VM I want to use. Every VM has its own number associated. What
> changes from one to another is only this line :
>
> -s
> 1,virtio-blk,/mnt/zroot2/zroot2/bhyve/img/Linux/ubuntu2210.img,bootindex=1 \
>
> That's the name and the location of the raw file. Inside the script I have
> added a mechanism to kill a ghosted vm if it does not find the associated
> viewer window active. That's because I don't find it useful to use a
> ghosted vm. Yes,it is faster,but It causes also troubles in my case. In
> addition the script automatically attaches and detaches the pci address
> tied to my gpu,because I want to pass through my RTX 2080 ti within a Linux
> VM. There is a bug that I want to fix : if I want to boot more than one
> VM,the first one will be killed. Shouldn't be too hard to fix it,anyway.
>
> #!/bin/sh
>
> setxkbmap it
> bhyvectl --vm=vm0:19 --destroy
> vms="$(ls /dev/vmm/*)"
> vncs="$(ps ax | awk '/vncviewer [0]/{print $6}')"
> echo $vms
> echo $vncs
>
> if ! pciconf -l pci0:2:0:0 | grep -q "^ppt"; then
> echo "rtx 2080ti slot 2/0/0 is not attached to ppt,attaching..."
> kldload nvidia-modeset
> devctl detach pci0:2:0:0
> devctl set driver pci0:2:0:0 ppt
> else
> echo "rtx 2080ti slot 2/0/0 is already attached to ppt"
> fi
>
> if ! pciconf -l pci0:2:0:1 | grep -q "^ppt"; then
> echo "rtx 2080ti slot 2/0/1 is not attached to ppt,attaching..."
> devctl detach pci0:2:0:1
> devctl set driver pci0:2:0:1 ppt
> else
> echo "rtx 2080ti slot 2/0/1 is already attached to ppt"
> fi
>
> if ! pciconf -l pci0:2:0:2 | grep -q "^ppt"; then
> echo "rtx 2080ti slot 2/0/2 is not attached to ppt,attaching..."
> devctl detach pci0:2:0:2
> devctl set driver pci0:2:0:2 ppt
> else
> echo "rtx 2080ti slot 2/0/2 is already attached to ppt"
> fi
>
> if ! pciconf -l pci0:2:0:3 | grep -q "^ppt"; then
> echo "rtx 2080ti slot 2/0/3 is not attached to ppt,attaching..."
> #devctl detach pci0:2:0:3
> devctl set driver pci0:2:0:3 ppt
> else
> echo "rtx 2080ti slot 2/0/3 is already attached to ppt"
> fi
>
> echo "rtx 2080ti is fully attached to ppt"
>
> for vm in $vms; do
>                 session="${vm##*/}"
>                 echo "bhyve session = $session"
>                 echo "vnc session = $vncs"
>                                 if ! printf '%s\n' "${vncs}" | grep
> "${session}"; then
>                                 printf 'VNC session not found,destroying
> ghost vms\n'
>                                 bhyvectl --vm=$session --destroy
>
>                 else
>                                 printf 'Found VNC session %s\n'
> "${session},no ghost vms found,not destroying them"
>                 fi
> done
>
> vmdisk0=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
> (NM13N4CZ)/ && d{print d}'`
> echo "Seagate M3 Portable 1.8 TB ; $vmdisk0"
>
> vmdisk1=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
> (2022285F1175)/ && d{print d}'`
> echo "CT1000P1SSD8 ; $vmdisk1"
>
> vmdisk2=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
> (2015020204055E)/ && d{print d}'`
> echo "TOSHIBA External USB 3.0 1.8 TB ; $vmdisk2"
>
> vmdisk3=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
> (20130506005976F)/ && d{print d}'`
> echo "TOSHIBA External USB 3.0 932G ; $vmdisk3"
>
> vmdisk4=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
> (BE0191500218)/ && d{print d}'`
> echo "G-DRIVE USB ; $vmdisk4"
>
> vmdisk5=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
> (38434B4237354B45)/ && d{print d}'`
> echo "Elements 25A3 ; $vmdisk5"
>
> vmdisk6=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
> (WD-WCAV2X597309)/ && d{print d}'`
> echo "WDC WD3200AAJS-00L7A0-298 GB ; $vmdisk6"
>
> vmdisk7=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
> (0774911DDC4200A6)/ && d{print d}'`
> echo "SanDisk Cruzer-15GB ; $vmdisk7"
>
> vmdisk8=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
> (60A44C4138D8F311190A0149)/ && d{print d}'`
> echo "Kingston DataTraveler 2.0 ; $vmdisk8"
>
> vmdisk9=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
> (20140100006C)/ && d{print d}'`
> echo "Corsair Force 3 SSD ; $vmdisk9"
>
> vmdisk10=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
> (1924E20B2AE5)/ && d{print d}'`
> echo "CT500MX500SSD4 ; $vmdisk10"
>
> vmdisk11=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
> (575845583038524844323238)/ && d{print d}'`
> echo "WD-2500BMV ; $vmdisk11"
>
> vmdisk12=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
> (57442D575845323039544433303334)/ && d{print d}'`
> echo "WD-3200BMV ; $vmdisk12"
>
> vmdisk13=`geom disk list | awk '/^Geom name: /{d=$NF} /^ *ident:
> (S3Z2NB0KB99028V)/ && d{print d}'`
> echo "Samsung SSD 860 EVO 500GB ; $vmdisk13"
>
> pkexec zpool import -f -R /mnt/zroot2 zroot2
>
> bhyve -S -c sockets=2,cores=2,threads=2 -m 8G -w -H -A \
> -s 0,hostbridge \
> -s
> 1,virtio-blk,/mnt/zroot2/zroot2/bhyve/img/Linux/ubuntu2210.img,bootindex=1 \
> -s 2,nvme,/dev/nvd0 \
> -s 4,virtio-blk,/dev/$vmdisk11 \
> -s 5,virtio-blk,/dev/$vmdisk12 \
> -s 6,virtio-blk,/dev/$vmdisk13 \
> -s 8,passthru,5/0/0 \
> -s 13,virtio-net,tap19 \
> -s 14,virtio-9p,sharename=/ \
> -s 29,fbuf,tcp=0.0.0.0:5919,w=1600,h=950,wait \
> -s 30,xhci,tablet \
> -s 31,lpc \
> -l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_CODE.fd \
> vm0:19 < /dev/null & sleep 2 && vncviewer 0:19
>
>
> On Wed, May 24, 2023 at 3:10 PM Aryeh Friedman <aryeh.friedman@gmail.com>
> wrote:
>
>> On Wed, May 24, 2023 at 8:33 AM Mario Marietto <marietto2008@gmail.com>
>> wrote:
>> >
>> > I do it automatically using only some scripts. I don't like to use
>> wrappers.
>>
>> Do you have the scripts... btw I finally gave up on getting GPT
>> (actually more accurately Hugging Face Transformers) to run on FreeBSD
>> and I did get them to work on this linsucks machine with the only snag
>> benign it won't automatically boot... now that I have a better idea of
>> what the whole working setup looks like I might try it again on
>> FreeBSD when I get some free time.
>>
>> >
>> > On Wed, May 24, 2023 at 1:28 PM Aryeh Friedman <
>> aryeh.friedman@gmail.com> wrote:
>> >>
>> >> I have it so I can get to a uefi shell prompt and manually boot but I
>> >> am still missing how to make this all automatic
>> >>
>> >> --
>> >> Aryeh M. Friedman, Lead Developer, http://www.PetiteCloud.org
>> >>
>> >
>> >
>> > --
>> > Mario.
>>
>>
>>
>> --
>> Aryeh M. Friedman, Lead Developer, http://www.PetiteCloud.org
>>
>
>
> --
> Mario.
>


-- 
Mario.