Skip to content

Commit

Permalink
Add rosetta support for Linux guest VMs. (#42)
Browse files Browse the repository at this point in the history
This requires tart 0.3.5.
  • Loading branch information
jonnybbb authored Jan 21, 2023
1 parent 0d1776f commit ed599a5
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions builder/tart/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Config struct {
VMName string `mapstructure:"vm_name" required:"true"`
VMBaseName string `mapstructure:"vm_base_name" required:"true"`
Recovery bool `mapstructure:"recovery" required:"false"`
Rosetta string `mapstructure:"rosetta" required:"false"`
CpuCount uint8 `mapstructure:"cpu_count" required:"false"`
MemoryGb uint16 `mapstructure:"memory_gb" required:"false"`
Display string `mapstructure:"display" required:"false"`
Expand Down
2 changes: 2 additions & 0 deletions builder/tart/builder.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions builder/tart/step_create_linux_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (s *stepCreateLinuxVM) Run(ctx context.Context, state multistep.StateBag) m
ui.Say("Creating virtual machine...")

createArguments := []string{
"create", "--linux",
"create", "--linux",
}

if config.DiskSizeGb > 0 {
Expand Down Expand Up @@ -60,12 +60,15 @@ func (s *stepCreateLinuxVM) RunInstaller(ctx context.Context, state multistep.St
ui := state.Get("ui").(packersdk.Ui)

ui.Say("Starting the virtual machine for installation...")
runArgs := []string{"run", config.VMName, }
runArgs := []string{"run", config.VMName}
if config.Headless {
runArgs = append(runArgs, "--no-graphics")
} else {
runArgs = append(runArgs, "--graphics")
}
if config.Rosetta != "" {
runArgs = append(runArgs, fmt.Sprintf("--rosetta=%s", config.Rosetta))
}
if !config.DisableVNC {
runArgs = append(runArgs, "--vnc-experimental")
}
Expand Down
1 change: 1 addition & 0 deletions docs/builders/tart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Below we'll go through available options of this Packer plugin
- `ssh_username` (string) - Username to use for the communication over SSH to run provision steps.
- `ssh_password` (string) - Password to use for the communication over SSH to run provision steps.
- `headless` (boolean) - Whether to show graphics interface of a VM. Useful for debugging `boot_command`.
- `rosetta` (string) - Whether to enable Rosetta support of a Linux guest VM. Useful for running non arm64 programs in the guest VM. A common used value is `rosetta`. For further details and explanation run `tart run --help`
- `boot_command` (array of strings) - This is an array of commands to type when the virtual machine is first booted. The goal of these commands should be to type just enough to initialize the operating system installer.

### Example Usage
Expand Down
8 changes: 8 additions & 0 deletions example/install_rosetta.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh -x

sudo mkdir /var/run/rosetta
sudo mount -t virtiofs rosetta /var/run/rosetta
sudo /usr/sbin/update-binfmts --install rosetta /var/run/rosetta/rosetta \
--magic "\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00" \
--mask "\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff" \
--credentials yes --preserve no --fix-binary yes
34 changes: 34 additions & 0 deletions example/ubuntu-22.04-rosetta.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
packer {
required_plugins {
tart = {
version = ">= 0.6.2"
source = "github.com/cirruslabs/tart"
}
}
}

source "tart-cli" "tart" {
vm_base_name = "ubuntu-22.04-vanilla"
vm_name = "ubuntu-22.04-rosetta"
headless = true
disable_vnc = true
rosetta = "rosetta"
ssh_password = "ubuntu"
ssh_username = "ubuntu"
ssh_timeout = "120s"
}

build {
sources = ["source.tart-cli.tart"]

provisioner "shell" {
inline = [
"sudo apt update && sudo apt-get install -y binfmt-support",
]
}

provisioner "shell" {
script = "install_rosetta.sh"
remote_path = "/tmp/install_rosetta.sh"
}
}
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var (
// Version is the main version number that is being run at the moment.
Version = "0.3.0"
Version = "0.6.2"

// VersionPrerelease is A pre-release marker for the Version. If this is ""
// (empty string) then it means that it is a final release. Otherwise, this
Expand Down

0 comments on commit ed599a5

Please sign in to comment.