save
This commit is contained in:
parent
c8b057e6a2
commit
54d4dfcb33
3 changed files with 68 additions and 8 deletions
|
|
@ -62,6 +62,10 @@ module VirtualMachine
|
|||
if options[:detached] == nil
|
||||
options[:detached] = false
|
||||
end
|
||||
|
||||
if options[:tpm] == nil
|
||||
options[:tpm] = false
|
||||
end
|
||||
end
|
||||
|
||||
def self.archive(options)
|
||||
|
|
@ -98,14 +102,16 @@ module VirtualMachine
|
|||
)
|
||||
end
|
||||
|
||||
# vm setup windows --arch arm64 --iso /Users/agurgul/Downloads/win.iso --tpm
|
||||
# vm setup windows --tpm --cdrom /Users/agurgul/Downloads/win.iso
|
||||
def self.setup(options)
|
||||
fill_defaults(options)
|
||||
|
||||
url = distro(options[:name], options[:arch], :install)
|
||||
disk_img_path = root_img_path(options)
|
||||
# puts options
|
||||
# exit -1
|
||||
|
||||
Downloader.get(url) do |path|
|
||||
|
||||
get_cdrom_image(options) do |path|
|
||||
disk_img_path = root_img_path(options)
|
||||
create_disk_image(disk_img_path, 64000)
|
||||
|
||||
Qemu.launch(
|
||||
|
|
@ -114,11 +120,23 @@ module VirtualMachine
|
|||
cpus: [1, System.cpus - 2].max,
|
||||
cdrom: path,
|
||||
detach: options[:detached],
|
||||
display: DisplayMode.window
|
||||
display: DisplayMode.window,
|
||||
tpm: options[:tpm]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_cdrom_image(options)
|
||||
if options[:cdrom] == nil
|
||||
url = distro(options[:name], options[:arch], :install)
|
||||
Downloader.get(url) do |path|
|
||||
yield path
|
||||
end
|
||||
else
|
||||
yield options[:cdrom]
|
||||
end
|
||||
end
|
||||
|
||||
# size in MB
|
||||
# lsof /Users/artur/.cache/dat/vm/debian/arm64/debian/root.img
|
||||
def self.create_disk_image(path, size)
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ module Qemu
|
|||
arch: System::ARCH,
|
||||
cdrom: nil,
|
||||
detach: true,
|
||||
ram: 2048,
|
||||
ram: 2048 * 8,
|
||||
cpus: 1,
|
||||
display: DisplayMode::none
|
||||
}
|
||||
|
|
@ -102,7 +102,9 @@ module Qemu
|
|||
|
||||
if System::OS == :macos && arch == :arm64
|
||||
# args += ["-bios", "/opt/homebrew/share/qemu/edk2-aarch64-code.fd"]
|
||||
# cp /opt/homebrew/share/qemu/edk2-arm-vars.fd ~/edk2-arm-vars.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=1,file=/Users/agurgul/edk2-arm-vars.fd"]
|
||||
|
||||
if opts[:display] == DisplayMode::none
|
||||
port = 2222
|
||||
|
|
@ -156,10 +158,40 @@ module Qemu
|
|||
args += machine_args_for(arch)
|
||||
args += ["-m", opts[:ram].to_s, "-smp", opts[:cpus].to_s]
|
||||
args += ["-name", "FirstVM", "-boot", "order=d"] # boot from CD first
|
||||
args += ["-drive", "file=#{disk_path},if=virtio,cache=writeback,format=raw"]
|
||||
args += ["-drive", "file=#{disk_path},if=virtio,cache=writeback,format=raw,id=nvme0"]
|
||||
#args += ["-device", "nvme,serial=nvme0,drive=nvme0,bootindex=2"]
|
||||
|
||||
if opts[:cdrom] != nil
|
||||
args += ["-cdrom", opts[:cdrom]]
|
||||
#args += ["-cdrom", opts[:cdrom]]
|
||||
|
||||
# args += ["-device", "virtio-scsi-pci,id=scsi"]
|
||||
# args += ["-drive", "if=none,id=cd,format=raw,file=#{opts[:cdrom]},media=cdrom"]
|
||||
# args += ["-device", "scsi-cd,drive=cd,bootindex=1"]
|
||||
|
||||
|
||||
args += ["-drive", "id=cd,format=raw,file=#{opts[:cdrom]},media=cdrom"]
|
||||
args += ["-device", "usb-storage,drive=cd,bootindex=1"]
|
||||
|
||||
args += ["-device", "ramfb"]
|
||||
# args += ["-device", "virtio-gpu-pci"]
|
||||
# args += ["-display", "default,show-cursor=on"]
|
||||
end
|
||||
|
||||
if opts[:tpm]
|
||||
# brew install swtpm
|
||||
# swtpm socket --tpm2 --ctrl type=unixio,path=./tpm/tpm.sock --tpmstate dir=./tpm --daemon
|
||||
|
||||
# args += ["-chardev", "socket,id=chrtpm,path=/Users/agurgul/Downloads/tpm/tpm.sock"]
|
||||
# args += ["-tpmdev", "emulator,id=tpm0,chardev=chrtpm"]
|
||||
# args += ["-device", "tpm-crb-device,tpmdev=tpm0"]
|
||||
|
||||
args += ["-chardev", "socket,id=chrtpm,path=/Users/agurgul/Downloads/tpm/tpm.sock"]
|
||||
args += ["-tpmdev", "emulator,id=tpm0,chardev=chrtpm"]
|
||||
#args += ["-device", "tpm-tis,tpmdev=tpm0"]
|
||||
args += ["-device", "tpm-tis-device,tpmdev=tpm0"]
|
||||
# nic user,ipv6=off,model=rtl8139,mac=84:1b:77:c9:03:a6
|
||||
end
|
||||
|
||||
# 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"]
|
||||
|
|
@ -181,3 +213,5 @@ module Qemu
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue