diff --git a/bin/vm b/bin/vm index 657bb10..ebd2c02 100755 --- a/bin/vm +++ b/bin/vm @@ -70,4 +70,4 @@ when :attach puts "if not paramteres attaches to last used" else puts "Error not found #{options.type}" -end \ No newline at end of file +end diff --git a/bin/vm-runner b/bin/vm-runner new file mode 100755 index 0000000..8569ad3 --- /dev/null +++ b/bin/vm-runner @@ -0,0 +1 @@ +[Install Zen on Linux | Flathub](https://flathub.org/apps/app.zen_browser.zen) \ No newline at end of file diff --git a/lib/virtual-machine.rb b/lib/virtual-machine.rb index 27abeb7..436cfcc 100644 --- a/lib/virtual-machine.rb +++ b/lib/virtual-machine.rb @@ -129,4 +129,4 @@ module VirtualMachine # f.write("\0") end end -end \ No newline at end of file +end diff --git a/lib/vm/qemu.rb b/lib/vm/qemu.rb index 9e1d9c7..fdc050b 100644 --- a/lib/vm/qemu.rb +++ b/lib/vm/qemu.rb @@ -1,6 +1,20 @@ require "fileutils" require "ostruct" +module DisplayMode + def self.none + 0 + end + + def self.fullscreen + 1 + end + + def self.window + 2 + end +end + module Qemu def self.qemu_bin_for(arch) { @@ -69,10 +83,15 @@ module Qemu detach: true, ram: 2048, cpus: 1, - fullscreen: true + display: DisplayMode::none } + + # for testing only + defaults[:detach] = false + defaults[:display] = DisplayMode.window + opts = defaults.merge(options) - + puts options puts opts qemu = qemu_bin_for(arch) @@ -82,22 +101,31 @@ module Qemu # args += ["-bios", "/opt/homebrew/share/qemu/edk2-aarch64-code.fd"] args += ["-drive", "if=pflash,format=raw,unit=0,readonly=on,file=/opt/homebrew/share/qemu/edk2-aarch64-code.fd"] - #args += ["-device", "virtio-gpu-device"] - if opts[:fullscreen] - args += ["-display", "cocoa,full-screen=on"] + if opts[:display] == DisplayMode::none + port = 2222 + args += ['-nographic'] + args += ['-netdev', "user,id=net0,hostfwd=tcp:127.0.0.1:#{port}-:22"] + #args += ['-device', 'e1000,netdev=net0'] + args += ['-device', 'virtio-net-pci,netdev=net0'] + puts "ssh -p #{port} user@localhost" + else - args += ["-display", "cocoa"] + #args += ["-device", "virtio-gpu-device"] + if opts[:display] == DisplayMode::fullscreen + args += ["-display", "cocoa,full-screen=on"] + else + args += ["-display", "cocoa"] + end + + args += ["-device", "qemu-xhci,id=xhci"] + args += ["-device", "usb-kbd"] + args += ["-device", "usb-tablet"] + + args += ["-device", "virtio-keyboard-device"] + args += ["-device", "virtio-mouse-device"] + args += ["-device", "virtio-gpu"] end - args += ["-device", "qemu-xhci,id=xhci"] - args += ["-device", "usb-kbd"] - args += ["-device", "usb-tablet"] - - args += ["-device", "virtio-keyboard-device"] - args += ["-device", "virtio-mouse-device"] - args += ["-device", "virtio-gpu"] - - # copy to /Users/artur/.cache/dat/vm/debian/arm64/debian/vars.fd # /opt/homebrew/share/qemu/edk2-aarch64-vars.fd # args += ["-drive", "if=pflash,format=raw,unit=1,file=/Users/artur/.cache/dat/vm/debian/arm64/debian/vars.fd"] @@ -111,22 +139,24 @@ module Qemu if opts[:cdrom] != nil args += ["-cdrom", opts[:cdrom]] end - args += ["-device", "virtio-net,netdev=n0", "-netdev", "user,id=n0"] # user-mode NAT +# args += ["-device", "virtio-net,netdev=n0", "-netdev", "user,id=n0"] # user-mode NAT # optional: uncomment to run headless with VNC on :5901 # args += ["-display", "none", "-vnc", "127.0.0.1:1"] cmd = [qemu, *args] puts "Launching: #{cmd.join(' ')}" - pid = Process.spawn(*cmd, pgroup: true, out: $stdout, err: $stderr) if opts[:detach] + log = File.open("log.txt", "w") + pid = Process.spawn(*cmd, pgroup: false, out: log, err: log) Process.detach(pid) puts "QEMU pid=#{pid}" else + pid = Process.spawn(*cmd, pgroup: true, out: $stdout, err: $stderr) Process.wait(pid) status = $? puts "Exit status: #{status.exitstatus}" end end -end \ No newline at end of file +end