CBSD管理QEMU仿真虚拟机
first QEMU VM
使用 cbsd qconstruct-tui创建
cbsd qconstruct-tuino such qemu-system-x86_64, please install qemu and re-run: cbsd initenv
Please follow https://www.bsdstore.ru/en/cbsd_qemu_quickstart.html instruction to setup FreeBSD host.
按照提示,需要qemu-system-x86_64 ,因此需要安装qemu并重新初始化
安装qemu
pkg install -y qemu
cbsd初始化
cbsd initenv
cbsd initenv
-------[CBSD v.14.1.1]-------This is install/upgrade scripts for CBSD.Don't forget to backup.
-----------------------------
Do you want prepare or upgrade hier environment for CBSD now?
[yes(1) or no(0)]
1
>>> Installing or upgrading
[Stage 0: upgrading and migration data from 14.1.1 to 14.1.1]
pre-initenv-backup in progress ( can be disabled via ~cbsd/etc/initenv.conf; see ~cbsd/etc/defaults/initenv.conf ): initenv_backup_bases=3* pre-initenv-backup: [1/6] exprort/backup settings for: ub22* pre-initenv-backup: [2/6] exprort/backup settings for: ubjail1* pre-initenv-backup: [3/6] exprort/backup settings for: ubjail2* pre-initenv-backup: [4/6] exprort/backup settings for: riscv* pre-initenv-backup: [5/6] exprort/backup settings for: ub12* pre-initenv-backup: [6/6] exprort/backup settings for: windows2
[Stage 1: account & dir hier]* Check hier and permission...cmdboot: no such optional executable: xl, xen_feat disabled
[Stage 2: build tools]
[Stage 3: local settings]
[Stage 4: update default skel resolv.conf]
[Stage 5: refreshing inventory]
[Stage 6: authentication keys]
[Stage 7: nodes]
[Stage 8: modules]
[Stage 9: cleanup]* Remove obsolete files...
[Stage X: upgrading]
>>> Done
创建QEMU仿真
如果创建riscv仿真,还需要安装opensbi和u-boot-qemu-riscv64
pkg install -y opensbi u-boot-qemu-riscv64
开始cbsd引导
cbsd qconstruct-tui
选择和设置 'arch', 'vm_os_type', 'vm_os_profile' , 'jname' ,然后按'GO'即可.
设置Linux riscv仿真(没成功)
arch选riscv, vm_os_type选Linux
'vm_os_profile'里面若是空的,先clean,再update。但是update的时候报错make 128,大约是用户权限有问题。
按照提示,执行
git config --global --add safe.directory /usr/jails/etc
再update,就ok了。顶多有时候github会抽风。
update没有成功,所以cbsd设置qemu下的Linux riscv仿真没成功。
设置FreeBSD riscv仿真
arch选riscv, vm_os_type选FreeBSD
'vm_os_profile'里面刚开始只有一项vm-freebsd-FreeBSD-riscv64-14.1.conf,感觉还缺14.2
理论上应该能通过cbsd更新配置文件,但是可能github在抽风,于是手工到github下载所有的配置文件:
git clone https://github.com/cbsd/cbsd-vmprofiles
下载到~/github/cbsd-vmprofiles 目录,然后将该目录的cbsd-vmprofiles/vm-freebsd-FreeBSD-riscv64-14.2.conf文件cp到/usr/jails/etc/defaults 目录。
root@fb5:/usr/jails/etc/defaults # cp ~/github/cbsd-vmprofiles/vm-freebsd-FreeBSD-riscv64-14.2.conf .
这样'vm_os_profile'里面就可以选择vm-freebsd-FreeBSD-riscv64-14.2.conf了,创建虚拟机叫qf1 ,全部设置完成后,选go!
创建完成,cbsd qls看一下
cbsd qls
JNAME JID VM_RAM VM_CURMEM VM_CPUS PCPU VM_OS_TYPE IP4_ADDR STATUS VNC
qf1 0 2048 0 4 0 freebsd DHCP Off 127.0.0.1:0
启动
cbds qstart qf1
结果下载iso很慢。
找到配置文件:/usr/jails/etc/vm-freebsd-FreeBSD-riscv64-14.2.conf
这是默认的配置文件,如果已经生成了虚拟机,那么会在虚拟机的目录里,比如:
虚拟机qf1的配置文件在:/usr/jails/vm/qf1/etc/vm-freebsd-FreeBSD-riscv64-14.2.conf
修改
cbsd_iso_mirrors="https://mirror2.convectix.com/iso/ https://mirror.convectix.com/iso/ https://clonos.ca.ircdriven.net/iso/ https://clonos.us.ircdriven.net/iso/ https://plug-mirror.rcac.purdue.edu/cbsd-iso/"
加入Index of /freebsd/releases/ISO-IMAGES/14.2/
https://mirrors.ustc.edu.cn/freebsd/
cbsd_iso_mirrors="https://mirror2.convectix.com/iso/ https://mirror.convectix.com/iso/ https://clonos.ca.ircdriven.net/iso/ https://clonos.us.ircdriven.net/iso/ https://plug-mirror.rcac.purdue.edu/cbsd-iso/ https://mirrors.ustc.edu.cn/freebsd/"
最终是加了中科大和南京大学,并把官方的https://download.freebsd.org/ftp/releases/VM-IMAGES/14.2-RELEASE/riscv64/Latest/那个去掉
cbsd_iso_mirrors="https://test.nju.edu.cn/freebsd/ https://mirrors.ustc.edu.cn/freebsd/ https://mirror2.convectix.com/iso/ https://mirror.convectix.com/iso/ https://clonos.ca.ircdriven.net/iso/ https://clonos.us.ircdriven.net/iso/ https://plug-mirror.rcac.purdue.edu/cbsd-iso/"
还是太慢,中科大的也慢,大约只有500k/s
找到问题了,原来是镜像普渡大学罗森高级计算中心的镜像站https://plug-mirror.rcac.purdue.edu/里只有14.1的镜像,没有14.2的镜像,导致要么到freebsd官网下载,贼慢。要么到普渡大学,找不到文件.......
删除了qf2,再重新创建
cbsd qconstruct-tui
这回选了14.1版本,
启动:
cbsd qstart qf2
这回至少成功了。总体而言,如果想使用cbsd镜像站里现成的系统,还是比较方便的。
总结
cbsd系统里的仿真有多种,如同样是对riscv 仿真,一种是jail仿真,一种是qemu仿真。相对来说,jail仿真更加简单方便。不过这次实践,主要是进行了qemu的riscv FreeBSD仿真。
不管是jail还是qemu,都可以直接进行riscv的虚拟机系统仿真,但是操作比较繁琐,使用了cbsd管理系统后,操作简单方便很多!cbsd就是辅助简化操作的!