From 91a36e03a84b944eb6512fb7fe5ee72dbd822c22 Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Sun, 17 Aug 2025 17:21:38 +0200 Subject: [PATCH] add option to detache the VM from CLI --- bin/vm | 4 ++++ lib/virtual-machine.rb | 9 +++++++-- lib/vm/qemu.rb | 21 +++++++++++++++++++-- recipes/qemu/macos.yml | 28 ++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 recipes/qemu/macos.yml diff --git a/bin/vm b/bin/vm index ebd2c02..609384e 100755 --- a/bin/vm +++ b/bin/vm @@ -22,6 +22,10 @@ OptionParser.new do |opt| opt.on('--name NAME', 'Virtaul Machine name') do |name| options.name = name end + + opt.on('--detached') do + options.detached = true + end # --port (ssh port) # --attached (do not leave the shell process) # new from copy diff --git a/lib/virtual-machine.rb b/lib/virtual-machine.rb index 436cfcc..ccb8606 100644 --- a/lib/virtual-machine.rb +++ b/lib/virtual-machine.rb @@ -58,6 +58,10 @@ module VirtualMachine else options[:arch] = System.arch_to_symbol(options[:arch]) end + + if options[:detached] == nil + options[:detached] = false + end end def self.archive(options) @@ -90,7 +94,7 @@ module VirtualMachine options[:arch], disk_img_path, cpus: [1, System.cpus - 2].max, - detach: true + detach: options[:detached] ) end @@ -109,7 +113,8 @@ module VirtualMachine disk_img_path, cpus: [1, System.cpus - 2].max, cdrom: path, - detach: true + detach: options[:detached], + display: DisplayMode.window ) end end diff --git a/lib/vm/qemu.rb b/lib/vm/qemu.rb index fdc050b..cad148a 100644 --- a/lib/vm/qemu.rb +++ b/lib/vm/qemu.rb @@ -88,7 +88,7 @@ module Qemu # for testing only defaults[:detach] = false - defaults[:display] = DisplayMode.window + defaults[:display] = DisplayMode.fullscreen opts = defaults.merge(options) puts options @@ -112,7 +112,17 @@ module Qemu else #args += ["-device", "virtio-gpu-device"] if opts[:display] == DisplayMode::fullscreen - args += ["-display", "cocoa,full-screen=on"] + #args += ["-display", "cocoa,full-screen=on"] + + # attempts: + #args += ["-display", "cocoa,full-screen=on,retina=on"] + # brew install gtk+3 sdl2 + # args += ["-display", "sdl,gl=on,full-screen=on"] + args += ["-device", "virtio-gpu-gl-pci"] + args += ["-display", "sdl,gl=on,full-screen=on"] + #args += ["-display", "gtk,gl=on,full-screen=on"] + #args += ["-display", "cocoa,full-screen=on"] + #args += ["-display", "cocoa,gl=es,full-screen=on"] else args += ["-display", "cocoa"] end @@ -124,6 +134,13 @@ module Qemu args += ["-device", "virtio-keyboard-device"] args += ["-device", "virtio-mouse-device"] args += ["-device", "virtio-gpu"] + + + #args += ['-nic', 'user,model=virtio-net-pci'] + args += ["-device", "virtio-net,netdev=n0", "-netdev", "user,id=n0"] + # macOS vmnet (shares Mac’s LAN) + # -netdev vmnet-shared,id=n1 \ + # -device virtio-net-pci,netdev=n1 end # copy to /Users/artur/.cache/dat/vm/debian/arm64/debian/vars.fd diff --git a/recipes/qemu/macos.yml b/recipes/qemu/macos.yml new file mode 100644 index 0000000..4a902dd --- /dev/null +++ b/recipes/qemu/macos.yml @@ -0,0 +1,28 @@ +packages: + - meson + - ninja + - pkg-config + - glib + - pixman + - sdl2 + - libepoxy + - libslirp + - gettext + + +# pkg-config --modversion sdl2 # should print a version +# pkg-config --modversion epoxy # should print a version + +repository: + url: https://gitlab.com/qemu-project/qemu.git + branch: v10.0.3 + +steps: + - mkdir build + - cd build + - | + ../configure \ + --enable-sdl \ + --enable-opengl \ + --target-list=aarch64-softmmu,x86_64-softmmu \ + --prefix="$HOME/.local/qemu-sdl" \ No newline at end of file