creating raw images for QEMU

This commit is contained in:
Artur Gurgul 2025-08-11 14:18:59 +02:00
parent 3b9e0a1f33
commit 49cc960703
13 changed files with 164 additions and 17 deletions

View file

@ -1,4 +1,5 @@
require 'downloader'
require 'system'
require_relative 'data/resources/iso-images'
module VirtualMachine
@ -7,10 +8,44 @@ module VirtualMachine
end
def self.setup(options)
if options[:name] == nil
options[:name] = options[:distro]
end
if options[:arch] == nil
options[:arch] = System::ARCH
else
options[:arch] = System.arch_to_symbol(options[:arch])
end
puts options
distro = options[:distro]
arch = :arm64
type = :install
arch = options[:arch]
url = distro(name, arch, type)
Downloader.get(url)
Downloader.get(url) do |path|
disk_img_path = File.join(User.cache_path, "vm", distro.to_s, arch.to_s, options[:name], "root.img")
create_disk_image(disk_img_path, 500)
puts path
puts disk_img_path
end
end
# size in MB
def self.create_disk_image(path, size)
size_in_bytes = 1024 * 1024 * size
# Ensure the directory exists
dir = File.dirname(path)
FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
File.open(path, "wb") do |f|
f.truncate(size_in_bytes)
# f.seek(size_in_bytes - 1)
# f.write("\0")
end
end
end