# -*- mode: ruby -*- # vim: set ft=ruby : # logic: # arch/cpu ################################################### # if # arch = x86_64 # # then: # qe.cpu = "cortex-a76" # if # arch = aarch64 # # then: # qe.cpu = "host" ################################################### # system/accelerator ################################################### # if system = linux # then: # accelerator = 'tcg' # if system = macos # then: # accelerator='hvf' ################################################### module VagrantConfig require 'fileutils' require 'rexml/document' require 'etc' cur_dir = __dir__ vbox_name = 'fedora_42' ssh_port = 3333 cpus = 4 memory = 2048 linux_partitions = '' ########################################################## system ########################################################## linux = `uname -a | grep -i linux` macos = `uname -a | grep -i darwin` if not linux.empty? system = 'linux' end if not macos.empty? system = 'macos' end ############################################################################################################################ ####################################################### architecture ####################################################### x86_64 = `uname -m | grep -i x86_64` aarch64 = `uname -m | grep -i aarch64` if not x86_64.empty? arch = 'x86_64' end if not aarch64.empty? arch = 'aarch64' end ############################################################################################################################ ######################################################## accelerator ####################################################### if system == 'linux' accelerator = 'tcg' elsif system == 'macos' && arch == 'aarch64' accelerator = 'hvg' elsif system == 'macos' && arch == 'x86_64' echo "macos x86_64 is not supported -- primarily because I don't have a macos x86_64 system to test on." echo "if you're willing to test it out -- please hit me up...." exit end ############################################################### linux + macos checks ################################################################################## if system == 'linux' sudo = false accelerator="#{accelerator}" qemu_dir = "#{cur_dir}/support_scripts" partition_msg = 'Running on Linux' ####################### ensure bios files are installed ####################### edk2_aarch64_code = '/usr/share/edk2/aarch64/QEMU_EFI-silent-pflash.raw' edk2_arm_vars = '/usr/share/edk2/aarch64/vars-template-pflash.raw' support_dir = "#{cur_dir}/support_scripts" Dir.mkdir(support_dir) unless File.exist?(support_dir) if not File.exist?("#{support_dir}/edk2-aarch64-code.fd") FileUtils.cp(edk2_aarch64_code, "#{support_dir}/edk2-aarch64-code.fd") end if not File.exist?('#{support_dir}/edk2-arm-vars.fd') FileUtils.cp(edk2_arm_vars, "#{support_dir}/edk2-arm-vars.fd") end ############################################################################### elsif system == 'macos' sudo = true accelerator="#{accelerator}" qemu_dir='/opt/homebrew/share/qemu' linux_disk_count = `ls /dev/disk0s* | grep -E '/dev/disk0s4|/dev/disk0s5|/dev/disk0s6' | wc -l | tr -d ' '` linux_disk_count = linux_disk_count.to_i if linux_disk_count == 3 partition_msg = 'Linux partitions found' linux_partitions = '-drive if=virtio,format=raw,file=/dev/disk0s4 -drive if=virtio,format=raw,file=/dev/disk0s5 -drive if=virtio,format=raw,file=/dev/disk0s6' else partition_msg = 'Linux partitions not found' end else puts 'system not supported' exit 1 end ####################################################################################################################################################################### ################################################################### x86_64 or aarch64 ################################################################################# qemu_plugin_installed = `vagrant plugin list | grep vagrant-qemu` if qemu_plugin_installed.empty? puts 'the vagrant-qemu plugin is not installed' puts 'install it with:' puts 'vagrant plugin install vagrant-qemu' exit 1 end if sudo == true && Etc.getpwuid.uid != 0 puts "You need to run this script as root or sudo when running from macos" exit 1 end Vagrant.configure("2") do |config| #xxx config.ssh.insert_key=true config.vm.boot_timeout = 900 config.ssh.username = 'root' config.ssh.password = 'fedora' config.ssh.keep_alive = true config.vm.box = vbox_name config.vm.synced_folder cur_dir, '/vagrant', disabled: true config.trigger.after :up do |trigger| trigger.run_remote = {inline: "echo #{partition_msg}"} end config.vm.define 'fedora' do |fedora| config.vm.provider "qemu" do |qe| qe.name = 'fedora' qe.qemu_dir = "#{qemu_dir}" qe.arch = 'aarch64' qe.machine = "virt,accel=#{accelerator},highmem=on" qe.smp = cpus qe.memory = memory qe.cpu = "cortex-a76" qe.net_device = "virtio-net-pci" qe.ssh_port = ssh_port # uncomment if you need vnc #qe.extra_netdev_args = "hostfwd=tcp::5900-:5900" qe.extra_qemu_args = "-fsdev local,id=cur_dir_dev,path=#{cur_dir},security_model=mapped-xattr -device virtio-9p-pci,fsdev=cur_dir_dev,mount_tag=local_mnt #{linux_partitions}".split end end end end