Add possibility to run without display
This commit is contained in:
parent
73e3f7548b
commit
83a0f81cbe
4 changed files with 51 additions and 20 deletions
1
bin/vm-runner
Executable file
1
bin/vm-runner
Executable file
|
|
@ -0,0 +1 @@
|
||||||
|
[Install Zen on Linux | Flathub](https://flathub.org/apps/app.zen_browser.zen)
|
||||||
|
|
@ -1,6 +1,20 @@
|
||||||
require "fileutils"
|
require "fileutils"
|
||||||
require "ostruct"
|
require "ostruct"
|
||||||
|
|
||||||
|
module DisplayMode
|
||||||
|
def self.none
|
||||||
|
0
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.fullscreen
|
||||||
|
1
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.window
|
||||||
|
2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module Qemu
|
module Qemu
|
||||||
def self.qemu_bin_for(arch)
|
def self.qemu_bin_for(arch)
|
||||||
{
|
{
|
||||||
|
|
@ -69,10 +83,15 @@ module Qemu
|
||||||
detach: true,
|
detach: true,
|
||||||
ram: 2048,
|
ram: 2048,
|
||||||
cpus: 1,
|
cpus: 1,
|
||||||
fullscreen: true
|
display: DisplayMode::none
|
||||||
}
|
}
|
||||||
opts = defaults.merge(options)
|
|
||||||
|
|
||||||
|
# for testing only
|
||||||
|
defaults[:detach] = false
|
||||||
|
defaults[:display] = DisplayMode.window
|
||||||
|
|
||||||
|
opts = defaults.merge(options)
|
||||||
|
puts options
|
||||||
puts opts
|
puts opts
|
||||||
|
|
||||||
qemu = qemu_bin_for(arch)
|
qemu = qemu_bin_for(arch)
|
||||||
|
|
@ -82,8 +101,17 @@ module Qemu
|
||||||
# args += ["-bios", "/opt/homebrew/share/qemu/edk2-aarch64-code.fd"]
|
# 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 += ["-drive", "if=pflash,format=raw,unit=0,readonly=on,file=/opt/homebrew/share/qemu/edk2-aarch64-code.fd"]
|
||||||
|
|
||||||
|
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 += ["-device", "virtio-gpu-device"]
|
#args += ["-device", "virtio-gpu-device"]
|
||||||
if opts[:fullscreen]
|
if opts[:display] == DisplayMode::fullscreen
|
||||||
args += ["-display", "cocoa,full-screen=on"]
|
args += ["-display", "cocoa,full-screen=on"]
|
||||||
else
|
else
|
||||||
args += ["-display", "cocoa"]
|
args += ["-display", "cocoa"]
|
||||||
|
|
@ -96,7 +124,7 @@ module Qemu
|
||||||
args += ["-device", "virtio-keyboard-device"]
|
args += ["-device", "virtio-keyboard-device"]
|
||||||
args += ["-device", "virtio-mouse-device"]
|
args += ["-device", "virtio-mouse-device"]
|
||||||
args += ["-device", "virtio-gpu"]
|
args += ["-device", "virtio-gpu"]
|
||||||
|
end
|
||||||
|
|
||||||
# copy to /Users/artur/.cache/dat/vm/debian/arm64/debian/vars.fd
|
# copy to /Users/artur/.cache/dat/vm/debian/arm64/debian/vars.fd
|
||||||
# /opt/homebrew/share/qemu/edk2-aarch64-vars.fd
|
# /opt/homebrew/share/qemu/edk2-aarch64-vars.fd
|
||||||
|
|
@ -111,19 +139,21 @@ module Qemu
|
||||||
if opts[:cdrom] != nil
|
if opts[:cdrom] != nil
|
||||||
args += ["-cdrom", opts[:cdrom]]
|
args += ["-cdrom", opts[:cdrom]]
|
||||||
end
|
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
|
# optional: uncomment to run headless with VNC on :5901
|
||||||
# args += ["-display", "none", "-vnc", "127.0.0.1:1"]
|
# args += ["-display", "none", "-vnc", "127.0.0.1:1"]
|
||||||
|
|
||||||
cmd = [qemu, *args]
|
cmd = [qemu, *args]
|
||||||
|
|
||||||
puts "Launching: #{cmd.join(' ')}"
|
puts "Launching: #{cmd.join(' ')}"
|
||||||
pid = Process.spawn(*cmd, pgroup: true, out: $stdout, err: $stderr)
|
|
||||||
|
|
||||||
if opts[:detach]
|
if opts[:detach]
|
||||||
|
log = File.open("log.txt", "w")
|
||||||
|
pid = Process.spawn(*cmd, pgroup: false, out: log, err: log)
|
||||||
Process.detach(pid)
|
Process.detach(pid)
|
||||||
puts "QEMU pid=#{pid}"
|
puts "QEMU pid=#{pid}"
|
||||||
else
|
else
|
||||||
|
pid = Process.spawn(*cmd, pgroup: true, out: $stdout, err: $stderr)
|
||||||
Process.wait(pid)
|
Process.wait(pid)
|
||||||
status = $?
|
status = $?
|
||||||
puts "Exit status: #{status.exitstatus}"
|
puts "Exit status: #{status.exitstatus}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue