-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement Request: CPU architecture aware box handling #12610
Comments
Yes, I need this feature as well. |
@jcsalem Mind sharing how you did this? I'm running into the same issue. |
@brycekahle Since the Vagrantfile is just a Ruby script, you just need to switch on architecture to set the box name. The pre-requisite is of course that you create differently named boxes for each architecture. Like # one alternative: `uname -m`
architecture = do_something_to_get_some_architecture_abbreviation()
Vagrant.configure("2") do |config|
config.vm.box = "@brycekahle/ubuntu-focal-#{architecture}"
# the rest
# ...
end All that is left is then to implement |
@fatso83 Yeah, the challenge is vagrant still runs under Rosetta, so using builtins often return the wrong result. I ended up reading the |
@brycekahle Mind posting your workaround? Thank you! |
@fatso83 I tried to do this in my Vagrant.configure('2') do |config|
arch = `arch`
config.vm.box = if arch == 'arm64'
'whichever/ubuntu-server-20.04-arm64'
else if arch == 'i386'
'whichever/ubuntu-server-20.04-i386'
end
...
end But it turns out that since If anyone has a workaround, please let me know. |
I haven't had time to test this yet, but I believe |
@glynnforrest That seems very promising as it seems to align well with this accepted answer that lists a small C snippet one could use, which checks just that. EDIT P.S. At first I was a bit at a loss on how this could work, since no
P.P.S. Why do you need to pass
|
(For context: I both use vagrant as a developer, and build various boxes) As much as there are workarounds with naming, I think the original request still has a lot of merit. We define the provider for a box (rather than having say The arch suffix thing is already kind of common (i.e. the |
Seems like On my Intel box running Big Sur:
On my M1 box running Monterey:
|
So this is what I ended up with in my # Tells us if the host system is an Apple Silicon Mac running Rosetta
def running_rosetta()
!`sysctl -in sysctl.proc_translated`.strip().to_i.zero?
end
Vagrant.configure('2') do |config|
arch = `arch`.strip()
if arch == 'arm64' || (arch == 'i386' && running_rosetta())
config.vm.box = 'bytesguy/ubuntu-server-20.04-arm64'
config.vm.box_version = '1.0.0'
else
puts "This appears to be an Intel machine! ... Not supported just yet."
exit
end
...
end It seems to work fine! On my M1 Mac (running Monterey) the proper box is selected, and on an Intel Mac (running Big Sur) This unblocks me for now while I work on the M1 version of the VM, and eventually I'll develop the Intel version as well. Thanks everyone! Edit: I added a check for |
@fredngo Excellent work! I've extended it and simplified. # Tells us if the host system is an Apple Silicon Mac running Rosetta
def is_arm64()
`uname -m` == "arm64" || `/usr/bin/arch -64 sh -c "sysctl -in sysctl.proc_translated"`.strip() == "0"
end
Vagrant.configure('2') do |config|
if is_arm64()
config.vm.box = 'bytesguy/ubuntu-server-20.04-arm64'
config.vm.box_version = '1.0.0'
elsif `uname -m` == "x86_64"
config.vm.box = 'bento/ubuntu-20.04'
end
...
end Unit testing below. on m1 mac within rosetta:
on x86 mac returns no output:
edit: zero? caused x86 empty return string value to false positive report integer 0. Just compare the string. |
I'm the guy making the Roboxes. Those are the generic base boxes on Vagrant Clould. At the moment we're only building x64 boxes (plus a handful of x32 boxes). But will (hiopefully) be changing soon. I'm still waiting on the hardware to arrive, but if everything goes according to plan, we'll also be generating a64 versions of our most popular boxes by the end of the year. The build server we hope to get will be running Linux, so at least initially, we'll only be generating a64 boxes for the libvirt provider. For the VWare and VirtualBox providers, we'll need to wait until VMWare/Oracle add support for a64 Linux hosts. As of now, those vendors only offer a64 release for MacOS (and it's M1/M2 chips). As of now,m we have our Windows, and MacOS build robots all have Intel chips. So I don't expect a64 versions for those providers for awhile. The status update above was just the preface to my feature request. When the a64 boxes start arriving, I would like to be able to upload them to our existing box repos, so they can appear be hosted alongside their x64 counterparts. What I'm trying to say is that a64/x64 boxes for a given provider should be able to coexisting the same way VMware and libvirt versions of boxes coexist today. When a user requests a given box, they presented with a list to pick from, showing all of the different providers available. CPU arches should work the same way.. If the user picks libvirt, they would see a list of different arches availabe for that provider, and get to pick. Presumably a global config flag could be used to configure the default behavior, like so! If Of course arch should also support specific arch values, like When set to use to a specific arch, Vagrant would only continue if a given repo+arch match is available. Otherwise the request should fail. A commnd line flag, In the nice to have category, it should be possible to specific array of arches when setting the global default. When setup this way, Vagrant should use the first arch value in the array to match what a repo provides. This would allow someone to prefer a64, then a32, and finally x64. But such a setup would still reject x32, r64 (RISC-V) and p64 /p64le (OpenPower) boxes (for example). Note, the The final configuration to discuss is what happens when the arch config value is set is explicitly set to |
I submitted early. For If no boxes are available in the same arch family, then Vagrant should present a list of options that are available, (with a possible warning as someone else suggested), and allow the user to pick.... Would anyone else like to offer thoguhts on how this should work? Personally, I believe this issue is critical and time sensitve. Vagrant and Vagrtant Cloud both need to be improved so they can handle different CPU arches logically, or we will end up with a mess of technical debt. If we can't store a64 and x64 boxes in the same Vagrant Cloud repo, like we currently do with different providers, then alt arch boxes will end up in distinct repos. For the Roboxes project, I went with a different org for the x32 boxes, so I could use consistent repo names for both x32 and x64. This may not sound like much, but this critically means users won't be able to use/distribute a common Vagrantfile that will work, unmodified, regardless opf the CPU arch. |
Hi everyone, Thanks for all the information and suggestions provided in here! I am currently working on identifying all the changes required to make this work while also preventing those changes from breaking existing Vagrant releases. |
Yes, please :-) I'm working on Windows and MacOS M1 on the same projects and it's problematic 8-) |
Is your feature request related to a problem? Please describe.
A lot of developers are now on ARM architectures. Even if they should be able to to get VMWare Fusion playing nicely with Vagrant, the issue of finding boxes that runs on the right provider is left missing. You cannot filter boxes on Vagrant Cloud by architecture, nor will you get a good error message if one does not run on your provider due to architecture mismatch.
Describe the solution you'd like
Two things:
architecture
field for new boxes and let users filter onamd64
(x86
?),arm64
, etc. (from a list of enums) when searching for images.bionic64
in your Vagrantfile, and that box does not exist for your architecture, you should be told through an error message.Describe alternatives you've considered
Clear documentation mentioning the architecture issues.
Additional context
The text was updated successfully, but these errors were encountered: