qemu启动zfs 映像(未解决)

发布于:2024-05-07 ⋅ 阅读:(23) ⋅ 点赞:(0)

根据FreeBSD的riscv wiki :riscv - FreeBSD Wiki进行 qemu的启动实践,发现例子中的文件无法下载,

fetch https://download.freebsd.org/snapshots/VM-IMAGES/15.0-CURRENT/riscv64/Latest/FreeBSD-15.0-CURRENT-riscv-riscv64.raw.xz

该文件FreeBSD-15.0-CURRENT-riscv-riscv64.raw.xz只有32个字节

在同一目录下,发现有 FreeBSD-15.0-CURRENT-riscv-riscv64-zfs.raw.xz 文件,但是这个文件启动的时候报错

qemu-system-riscv64 -machine virt -m 2048M -smp 2 -nographic -bios /usr/local/share/opensbi/lp64/generic/firmware/fw_jump.elf -kernel /usr/local/share/u-boot/u-boot-qemu-riscv64/u-boot.bin -drive file=FreeBSD-15.0-CURRENT-riscv-riscv64.raw,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -netdev user,id=net0,ipv6=off,hostfwd=tcp::8022-:22 -device virtio-net-device,netdev=net0
 

Device 0: QEMU VirtIO Block Device
            Type: Hard Disk
            Capacity: 10240.0 MB = 10.0 GB (20971520 x 512)
... is now current device
** No partition table - virtio 0 **
Couldn't find partition virtio 0:1
scanning bus for devices...
 

查找资料,发现网上有个关于zfs盘的:

qemu-system-x86_64 -cdrom /path/to/freebsd14.iso -drive if=none,file=freebsd14.zfs,id=hd -device virtio-scsi-device,drive=hd -m 2048 -smp 2 -boot d

This command will install FreeBSD 14.0 on the ZFS-based disk using the provided ISO image. The -cdrom flag specifies the location of the ISO image, while the -drive and -device flags specify the ZFS-based disk and the virtio-scsi device, respectively.

根据这个,改写zfs的:

qemu-system-riscv64 -machine virt -m 2048M -smp 2 -nographic -bios /usr/local/share/opensbi/lp64/generic/firmware/fw_jump.elf -kernel /usr/local/share/u-boot/u-boot-qemu-riscv64/u-boot.bin -drive if=none,file=FreeBSD-15.0-CURRENT-riscv-riscv64.raw,format=raw,id=hd0 -device virtio-scsi-device,drive=hd0 -netdev user,id=net0,ipv6=off,hostfwd=tcp::8022-:22 -device virtio-net-device,netdev=net0

一直报错

qemu-system-riscv64: -device virtio-scsi-device,drive=hd: Property 'virtio-scsi-device.drive' not found
百度说:

解决方法通常包括以下几个步骤:

  1. 确认QEMU版本是否支持VirtIO SCSI设备。

  2. 确认virtio-scsi设备的属性是否正确配置。

  3. 查看QEMU的文档或错误日志,以获取更多关于属性错误的信息。

试试这个:

qemu-system-riscv64 -machine virt -m 2048M -smp 2 -nographic -bios /usr/local/share/opensbi/lp64/generic/firmware/fw_jump.elf -kernel /usr/local/share/u-boot/u-boot-qemu-riscv64/u-boot.bin -drive file=FreeBSD-15.0-CURRENT-riscv-riscv64.raw,format=raw,id=hd0 -device virtio-blk-device,scsi=on,drive=hd0 -netdev user,id=net0,ipv6=off,hostfwd=tcp::8022-:22 -device virtio-net-device,netdev=net0

virtio-blk,scsi=on

还是报错...

参考这个文档:

看看这篇文档:Running ZFS Disk on QEMU with Windows 11 and FreeBSD 14 as Guests

Creating a ZFS-based FreeBSD 14.0 Disk

To create a ZFS-based FreeBSD 14.0 disk, you will need to use the following command in the QEMU shell:

qemu-img create -f zfs freebsd14.zfs 10G

This command will create a new ZFS-based disk with a size of 10GB, which will be named freebsd14.zfs.

Configuring the Hyper-V Hypervisor

Next, you will need to configure the Hyper-V hypervisor to use the new ZFS-based FreeBSD 14.0 disk. To do this, you will need to use the Hyper-V Manager to create a new virtual machine and attach the ZFS-based disk to it.

Installing FreeBSD 14.0 on the ZFS-based Disk

Once the Hyper-V hypervisor has been configured to use the ZFS-based FreeBSD 14.0 disk, you can install FreeBSD 14.0 on the disk using the following command:

qemu-system-x86_64 -cdrom /path/to/freebsd14.iso -drive if=none,file=freebsd14.zfs,id=hd -device virtio-scsi-device,drive=hd -m 2048 -smp 2 -boot d

This command will install FreeBSD 14.0 on the ZFS-based disk using the provided ISO image. The -cdrom flag specifies the location of the ISO image, while the -drive and -device flags specify the ZFS-based disk and the virtio-scsi device, respectively.

Using the ZFS-based FreeBSD 14.0 Disk

Once FreeBSD 14.0 has been installed on the ZFS-based disk, you can use it as you would any other FreeBSD disk. This includes creating and managing ZFS file systems, as well as installing and running applications on the disk.

  • In this article, we have discussed the process of creating and running a ZFS-based FreeBSD 14.0 disk on QEMU in Windows 11 using the Hyper-V hypervisor.
  • We have covered the key concepts and provided detailed context on the topic, including subtitles, paragraphs, and code blocks as needed.
  • We have also provided a summary of the steps involved in creating and using the ZFS-based FreeBSD 14.0 disk.

参考这个

qemu-system-riscv64 -machine virt -smp 2 -m 2048 -nographic \
    -bios /usr/local/share/opensbi/lp64/generic/firmware/fw_jump.elf \
    -kernel /usr/local/share/u-boot/u-boot-qemu-riscv64/u-boot.bin \
    -drive file=/path/to/riscv.img,format=raw,id=hd0 \
    -device virtio-blk-device,drive=hd0
qemu-system-riscv64 -machine virt -smp 2 -m 2048 -nographic \
    -bios /usr/local/share/opensbi/lp64/generic/firmware/fw_jump.elf \
    -kernel /usr/local/share/u-boot/u-boot-qemu-riscv64/u-boot.bin \
    -drive file=FreeBSD-15.0-CURRENT-riscv-riscv64-zfs.raw,format=raw,id=hd0 \
    -device virtio-blk-device,drive=hd0

启动后报错:

32-083c-11ef-8a1b-0cc47ad8b808,0x21043a,0xa00000)
Setting currdev to disk0p3:
ERROR: cannot open /boot/lua/loader.lua: no such file or directory.
 

仔细看里面的内容,识别出来三块盘:

   Load Device: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000001000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,8500000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,1600850000000000)/HD(1,GPT,b2307226-083c-11ef-8a1b-0cc47ad8b808,0x22,0x10418)
Trying ESP: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000001000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,8500000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,1600850000000000)/HD(1,GPT,b2307226-083c-11ef-8a1b-0cc47ad8b808,0x22,0x10418)
Setting currdev to disk0p1:
Trying: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000001000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,8500000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,1600850000000000)/HD(2,GPT,b230722e-083c-11ef-8a1b-0cc47ad8b808,0x1043a,0x200000)
Setting currdev to disk0p2:
Trying: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000001000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,8500000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,1600850000000000)/HD(3,GPT,b2307232-083c-11ef-8a1b-0cc47ad8b808,0x21043a,0xa00000)
Setting currdev to disk0p3:
ERROR: cannot open /boot/lua/loader.lua: no such file or directory.
 

map-vdisk FreeBSD-15.0-CURRENT-riscv-riscv64-zfs.raw
 

使用lsdev命令看到盘了:

lsdev
disk devices:
    disk0:    20971520 X 512 blocks
      disk0p1: EFI
      disk0p2: FreeBSD swap
      disk0p3: FreeBSD ZFS
http: (unknown)
net devices:
 

该怎么挂载呢? chatgpt说:

es, you can operate and mount disk devices in the QEMU command line. In the provided example, the disk devices are listed as follows:

  • disk0: This is the main disk device with a size of 20971520 x 512 blocks.
    • disk0p1: This is the EFI partition.
    • disk0p2: This is the FreeBSD swap partition.
    • disk0p3: This is the FreeBSD ZFS partition.

To mount a disk device in QEMU, you can use the -drive option followed by the appropriate parameters. For example, to mount the disk0p3 partition, you can use the following command:CopyCopy

qemu-system-x86_64 -drive file=disk0p3,format=raw
Copy

This command tells QEMU to use the disk0p3 partition as a disk image file in raw format.Copy

Please note that the above command is just an example, and you may need to adjust it based on your specific setup and requirements. Additionally, ensure that you have the necessary permissions to access the disk devices and that your system's version of QEMU supports ZFS.

Let me know if you need further assistance!

发现还是不行,chatgpt并没有理解,我讲的是映像是zfs格式的,不是当前系统。

真不明白,别人就没碰到过zfs系统的吗? 

还是说别人都很顺利? 

未完待续

调试

执行qemu命令报错

qemu-system-riscv64: drive=hd0: drive with bus=0, unit=0 (index=0) exists
 

原来qemu的-device后面的内容,不能有空格,如:

-device virtio-scsi-device, drive=hd0 -netdev user,id=net0,ipv6=off,hostfwd=tcp::8022-:22 

这其中device, drive之间有个空格,就会报错