Skip to content
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

VirtFS: Add default synced_folder implementation for UTM #17

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
# MacOS
.DS_Store

# Test Vagrantfiles
vagrant_play/
# Test plugin, Vagrantfile
vagrant_test/
115 changes: 71 additions & 44 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ GIT
PATH
remote: .
specs:
vagrant_utm (0.1.2.beta)
vagrant_utm (0.1.3.beta)

GEM
remote: https://rubygems.org/
Expand All @@ -42,25 +42,31 @@ GEM
base64 (0.2.0)
bcrypt_pbkdf (1.1.1)
bcrypt_pbkdf (1.1.1-arm64-darwin)
bigdecimal (3.1.8)
bigdecimal (3.1.9)
builder (3.3.0)
childprocess (4.1.0)
concurrent-ruby (1.3.3)
date (3.3.4)
concurrent-ruby (1.3.5)
date (3.4.1)
diff-lcs (1.5.1)
ed25519 (1.3.0)
erubi (1.13.0)
excon (0.111.0)
ffi (1.17.0)
ffi (1.17.0-aarch64-linux-gnu)
ffi (1.17.0-aarch64-linux-musl)
ffi (1.17.0-arm-linux-gnu)
ffi (1.17.0-arm-linux-musl)
ffi (1.17.0-arm64-darwin)
google-protobuf (3.25.3)
google-protobuf (3.25.3-aarch64-linux)
google-protobuf (3.25.3-arm64-darwin)
googleapis-common-protos-types (1.15.0)
erubi (1.13.1)
excon (1.2.3)
faraday (2.12.2)
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-net_http (3.4.0)
net-http (>= 0.5.0)
ffi (1.17.1)
ffi (1.17.1-aarch64-linux-gnu)
ffi (1.17.1-aarch64-linux-musl)
ffi (1.17.1-arm-linux-gnu)
ffi (1.17.1-arm-linux-musl)
ffi (1.17.1-arm64-darwin)
google-protobuf (3.25.5)
google-protobuf (3.25.5-aarch64-linux)
google-protobuf (3.25.5-arm64-darwin)
googleapis-common-protos-types (1.18.0)
google-protobuf (>= 3.18, < 5.a)
grpc (1.56.2)
google-protobuf (~> 3.23)
Expand All @@ -71,52 +77,68 @@ GEM
builder (>= 2.1.2)
rexml (~> 3.0)
hashicorp-checkpoint (0.1.5)
hashie (5.0.0)
httpclient (2.8.3)
i18n (1.14.5)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
ipaddr (1.2.6)
json (2.9.0)
ipaddr (1.2.7)
json (2.9.1)
jwt (2.10.1)
base64
language_server-protocol (3.17.0.3)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
little-plugger (1.1.4)
log4r (1.1.10)
logger (1.6.5)
logging (2.4.0)
little-plugger (~> 1.1)
multi_json (~> 1.14)
mime-types (3.5.2)
mime-types (3.6.0)
logger
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0702)
mime-types-data (3.2025.0107)
multi_json (1.15.0)
net-ftp (0.3.7)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
net-ftp (0.3.8)
net-protocol
time
net-http (0.6.0)
uri
net-protocol (0.2.2)
timeout
net-scp (4.0.0)
net-ssh (>= 2.6.5, < 8.0.0)
net-sftp (4.0.0)
net-ssh (>= 5.0.0, < 8.0.0)
net-ssh (7.2.3)
nori (2.7.0)
net-ssh (7.3.0)
nori (2.7.1)
bigdecimal
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
jwt (>= 1.0, < 3.0)
multi_xml (~> 0.5)
rack (>= 1.2, < 4)
snaky_hash (~> 2.0)
version_gem (~> 1.1)
pairing_heap (3.1.0)
parallel (1.26.3)
parser (3.3.6.0)
parser (3.3.7.0)
ast (~> 2.4.1)
racc
racc (1.8.1)
rack (3.1.8)
rainbow (3.1.1)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rb-kqueue (0.2.8)
ffi (>= 0.5.0)
regexp_parser (2.9.3)
rexml (3.2.9)
strscan
regexp_parser (2.10.0)
rexml (3.4.0)
rgl (0.5.10)
pairing_heap (>= 0.3.0)
rexml (~> 3.2, >= 3.2.4)
Expand All @@ -125,16 +147,16 @@ GEM
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-core (3.13.2)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.1)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.69.1)
rspec-support (3.13.2)
rubocop (1.70.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand All @@ -144,33 +166,38 @@ GEM
rubocop-ast (>= 1.36.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.36.2)
rubocop-ast (1.37.0)
parser (>= 3.3.1.0)
ruby-progressbar (1.13.0)
rubyntlm (0.6.5)
base64
rubyzip (2.3.2)
snaky_hash (2.0.1)
hashie
version_gem (~> 1.1, >= 1.1.1)
stream (0.5.5)
strscan (3.1.0)
time (0.3.0)
time (0.4.1)
date
timeout (0.4.1)
unicode-display_width (3.1.2)
timeout (0.4.3)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
vagrant_cloud (3.1.1)
excon (~> 0.73)
log4r (~> 1.1.10)
rexml (~> 3.2.5)
uri (1.0.2)
vagrant_cloud (3.1.2)
excon (~> 1.0)
log4r (~> 1.1)
oauth2 (~> 2.0)
rexml (~> 3.3)
version_gem (1.1.4)
wdm (0.1.1)
winrm (2.3.8)
winrm (2.3.9)
builder (>= 2.1.2)
erubi (~> 1.8)
gssapi (~> 1.2)
gyoku (~> 1.0)
httpclient (~> 2.2, >= 2.2.0.2)
logging (>= 1.6.1, < 3.0)
nori (~> 2.0)
nori (~> 2.0, >= 2.7.1)
rexml (~> 3.0)
rubyntlm (~> 0.6.0, >= 0.6.3)
winrm-elevated (1.2.3)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ vagrant plugin install vagrant_utm

```ruby
Vagrant.configure("2") do |config|
config.vm.box = "utm/debian11"
config.vm.box = "utm/bookworm"
end
```

Expand Down
13 changes: 7 additions & 6 deletions docs/boxes/creating_utm_box.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,18 @@ Check the [UTM Guide on Guest Support](https://docs.getutm.app/guest-support/gue

By satisfying the [general guidance on creating vagrant boxes](https://developer.hashicorp.com/vagrant/docs/boxes/base) and the above [Virtual Machine](#virtual-machine) requirements you can use your VM with Vagrant UTM plugin.

Apart from manually building the boxes, you can also use the semi-automated way of building these boxes using [packer plugin for UTM](https://github.com/naveenrajm7/packer-plugin-utm).
Apart from manually building the boxes, you can also use the automated (almost) way of building these boxes using [packer plugin for UTM](https://github.com/naveenrajm7/packer-plugin-utm).
The packer plugin has the following components:
1. Builder
1. UTM - Use existing utm file
2. ISO - Start from scratch using ISO files
1. UTM - Use existing utm file
2. ISO - Start from scratch using ISO files
3. CLOUD - Use existing qcow2 cloud images
2. Post-processor
1. ZIP - Package UTM VM into zip file
2. Vagrant - Package UTM VM into vagrant box.
1. ZIP - Package UTM VM into zip file
2. Vagrant - Package UTM VM into vagrant box.


Checkout [UTM Box Guide](https://github.com/naveenrajm7/utm-box/blob/main/HowToBuild/DebianUTM.md) to know how to build Box using packer.
Checkout [UTM Box Packer recipe](https://github.com/naveenrajm7/utm-box?tab=readme-ov-file#building-boxes) to know how to build Box using packer.

## Using your own UTM VMs

Expand Down
15 changes: 10 additions & 5 deletions docs/boxes/utm_box_gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@ nav_order: 1
To work with Vagrant, a base VM (box) must have
[certain features](https://developer.hashicorp.com/vagrant/docs/boxes/base), like an ssh user for vagrant to connect.

To help you get started with Vagrant UTM provider, a couple of pre-built VMs that work with Vagrant and are published in [HCP Vagrant registry](https://portal.cloud.hashicorp.com/vagrant/discover/utm).
To help you get started with Vagrant UTM provider, some pre-built VMs that work with Vagrant are published in [HCP Vagrant registry](https://portal.cloud.hashicorp.com/vagrant/discover/utm).

{: .important}
All the VMs provided are built from [UTM Gallery VMs](https://mac.getutm.app/gallery/) or ISO in an (semi) automated way using [packer plugin for UTM][packer plugin for UTM]. Please see the [UTM Box Guide][UTM Box Guide] on how these UTM Vagrant boxes were built using packer.
All the VMs provided are built from Cloud Images or ISO files in an (semi) automated way using [packer plugin for UTM][packer plugin for UTM]. Please see the [UTM Box Guide][UTM Box Guide] on how these UTM Vagrant boxes were built using packer.

* Debian 11 (Xfce):
* Debian 12 - Built from cloud image:
```ruby
config.vm.box = "utm/bookworm"
```

* Debian 11 (Xfce) - Built from UTM file of UTM gallery:
```ruby
config.vm.box = "utm/debian11"
```

* Ubuntu 24.04 :
* Ubuntu 24.04 - Built from ISO:
```ruby
config.vm.box = "utm/ubuntu-24.04"
```

* Help build more boxes using [packer plugin for UTM][packer plugin for UTM]
* Build your own boxes using [packer plugin for UTM][packer plugin for UTM]
<!-- * ArchLinux ARM -->


Expand Down
10 changes: 5 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ vagrant plugin install vagrant_utm
Option 1: Create a Vagrantfile and initiate the box (OR)

```
vagrant init utm/debian11
vagrant init utm/bookworm
```

Option 2: Open the Vagrantfile and replace the contents with the following

```ruby
Vagrant.configure("2") do |config|
config.vm.box = "utm/debian11"
config.vm.box = "utm/bookworm"
end
```

Expand All @@ -81,9 +81,9 @@ Now start using your machine!

`vagrant ssh` to log into machine or forward ports to check your website or share folders and start developing.

Check [Commands](commands.md) for all supported Vagrant commands.
Check [Configuration](configuration.md) for more UTM provider config options.

Check [Commands](commands.md) for all supported Vagrant commands.
Check [Configuration](configuration.md) for more UTM provider config options.
Discover UTM Vagrant boxes at [HCP Vagrant UTM Registry](https://portal.cloud.hashicorp.com/vagrant/discover/utm), which as boxes of popular OS including OpenBSD!

## About the project

Expand Down
56 changes: 56 additions & 0 deletions lib/vagrant_utm/cap/mount_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1

require_relative "../util/unix_mount_helpers"

module VagrantPlugins
module Utm
module Cap
# Capability for mount options
module MountOptions
extend VagrantPlugins::SyncedFolder::UnixMountHelpers

# Mount type for VirtFS
UTM_MOUNT_TYPE = "9p"

# Returns mount options for a utm synced folder
#
# @param [Machine] machine
# @param [String] name of mount
# @param [String] path of mount on guest
# @param [Hash] hash of mount options
def self.mount_options(machine, _name, guest_path, options)
mount_options = options.fetch(:mount_options, [])
detected_ids = detect_owner_group_ids(machine, guest_path, mount_options, options)
mount_uid = detected_ids[:uid]
mount_gid = detected_ids[:gid]

# VirtFS mount options
mount_options << "trans=virtio"
mount_options << "version=9p2000.L"
mount_options << if mount_options.include?("ro")
"ro"
else
"rw"
end
mount_options << "_netdev"
mount_options << "nofail"
mount_options << "auto"

mount_options = mount_options.join(",")
[mount_options, mount_uid, mount_gid]
end

def self.mount_type(_machine)
UTM_MOUNT_TYPE
end

def self.mount_name(_machine, name, _data)
name.gsub(%r{[\s/\\]}, "_").sub(/^_/, "")
end
end
end
end
end
Loading
Loading