vz icon indicating copy to clipboard operation
vz copied to clipboard

Call for ideas vmlinuz and initrd for testing

Open Code-Hex opened this issue 3 years ago • 8 comments

I have a plan to add some test code. But I need to use vmlinuz and initrd to write e2e testing. So I call for ideas what files are should be used (alpine? busybox? etc).

What's want

  • small distribution
  • minimum requirement to check booting

If you have knowledge, please tell me your recommendations. Thanks 🙏

Code-Hex avatar Sep 20 '22 10:09 Code-Hex

I also did a bit of research on this yesterday, and alpine may be the best option. A lot of the small distros I looked at were unmaintained/out of date/not having aarch64 builds/... An alternative could be Fedora CoreOS images which have a nice go API to automatically fetch them/..., but then the kernel/initrd need to be extracted from the image.

$ podman run quay.io/coreos/coreos-installer:release list-stream

https://github.com/containers/gvisor-tap-vsock/blob/main/test/fcos.go https://github.com/containers/gvisor-tap-vsock/blob/5b1aff8ba74374aeb62eaa06faa496faf2c56d74/test/fcos_amd64.go

cfergeau avatar Sep 20 '22 11:09 cfergeau

@cfergeau Thanks. I'm researching other options.

Code-Hex avatar Sep 20 '22 13:09 Code-Hex

I'm trying toybox but I can't boot (maybe this is successful but not shown on the console) on this library but I can be confirmed by qemu.

.PHONY: initrd
initrd:
	curl http://landley.net/toybox/downloads/binaries/mkroot/0.8.8/aarch64.tgz -o aarch64.tgz
	tar -xvzf aarch64.tgz

Use example linux code

$ VMLINUZ_PATH=../../aarch64/linux-kernel INITRD_PATH=../../aarch64/initramfs.cpio.gz ./virtualization

kernel command: "console=ttyAMA0"

Code-Hex avatar Sep 26 '22 17:09 Code-Hex

I'm working on making too tiny Linux for testing them

https://github.com/Code-Hex/puipui-linux

Code-Hex avatar Oct 05 '22 02:10 Code-Hex

I came across https://blog.xpnsec.com/bring-your-own-vm-mac-edition/ which might be similar to what you are looking for.

cfergeau avatar Oct 12 '22 07:10 cfergeau

Maybe dropbear might be needed.

Code-Hex avatar Oct 13 '22 09:10 Code-Hex

qemu-guest-agent could be an alternative to dropbear, it can run commands, read/write files, ... It runs unauthenticated over a vsock connection. It can also run over virtio-serial, but I think https://developer.apple.com/documentation/virtualization/vzvirtioconsoleportconfiguration?language=objc would be needed for that.

cfergeau avatar Oct 13 '22 09:10 cfergeau

List of qemu-ga features: https://www.qemu.org/docs/master/interop/qemu-ga-ref.html

cfergeau avatar Oct 13 '22 09:10 cfergeau

I'm trying qemu-guest-agent to run any command but I don't know how to do it. In my understanding, through ssh if use dropbear but through vsock if qemu-guest-agent. Right?

Code-Hex avatar Oct 16 '22 15:10 Code-Hex

but through vsock if qemu-guest-agent. Right?

Yes, that would happen over vsock. qemu-guest-agent needs to be started with --method=vsock-listen --path=3:1234. Then on the host you use ConnectToPort(1234). You can send qemu-ga commands over the VirtioSocketConnection returned by ConnectToPort. For example

{"execute": "guest-set-time", "arguments":{"time": 1665992533}}"

guest-exec should be able to run commands (but I never tried it)

cfergeau avatar Oct 17 '22 07:10 cfergeau

I'm trying toybox but I can't boot (maybe this is successful but not shown on the console) on this library

If you add this:

diff --git a/example/linux/main.go b/example/linux/main.go
index 4f335bc..2d63449 100644
--- a/example/linux/main.go
+++ b/example/linux/main.go
@@ -185,6 +185,10 @@ func main() {
                                log.Println("stopped successfully")
                                return
                        }
+                       if newState == vz.VirtualMachineStateError {
+                               log.Println("VM is in error state")
+                               return
+                       }
                case err := <-errCh:
                        log.Println("in start:", err)
                }

then trying to start the toybox kernel from http://landley.net/toybox/downloads/binaries/mkroot/0.8.8/aarch64.tgz fails with VM is in error state.

cfergeau avatar Oct 25 '22 11:10 cfergeau