canonical / multipass

Multipass orchestrates virtual Ubuntu instances
https://multipass.run
GNU General Public License v3.0
7.88k stars 651 forks source link

Add configuration option for storage location #2417

Closed daniel-lenz closed 1 month ago

daniel-lenz commented 2 years ago

What are you trying to do? Option or configuration needed to save instances/images on a custom path.

What's your proposed solution? Add configuration file or configuration item (multipass set default.image.path=/some/path).

Saviq commented 2 years ago

Hi @daniel-lenz, have a look at #1215, it's now possible through the MULTIPASS_STORAGE environment variable. Moving it to a fully supported setting will be slightly trickier - do we move all the data, or only the images? Do we migrate existing VMs? Need to answer such questions.

daniel-lenz commented 2 years ago

Ok, wow! I'll give it a try now :+1:

daniel-lenz commented 2 years ago

Is not working for me setting MULTIPASS_STORAGE in the override.conf is not working: ● snap.multipass.multipassd.service - Service for snap application multipass.multipassd Loaded: loaded (/etc/systemd/system/snap.multipass.multipassd.service; enabled; vendor preset: enabled) Drop-In: /etc/systemd/system/snap.multipass.multipassd.service.d └─override.conf Active: failed (Result: exit-code) since Sat 2022-01-29 17:34:27 CET; 3s ago Process: 15170 ExecStart=/usr/bin/snap run multipass.multipassd (code=exited, status=1/FAILURE) Main PID: 15170 (code=exited, status=1/FAILURE)

Jan 29 17:34:27 notebook systemd[1]: snap.multipass.multipassd.service: Scheduled restart job, restart counter is at 5. Jan 29 17:34:27 notebook systemd[1]: Stopped Service for snap application multipass.multipassd. Jan 29 17:34:27 notebook systemd[1]: snap.multipass.multipassd.service: Start request repeated too quickly. Jan 29 17:34:27 notebook systemd[1]: snap.multipass.multipassd.service: Failed with result 'exit-code'. Jan 29 17:34:27 notebook systemd[1]: Failed to start Service for snap application multipass.multipassd.

daniel-lenz commented 2 years ago

Now I can not use multipass at all: launch failed: cannot connect to the multipass socket
Please ensure multipassd is running and '/var/snap/multipass/common/multipass_socket' is accessible snap info multipass
name: multipass summary: Instant Ubuntu VMs publisher: Canonical✓ store-url: https://snapcraft.io/multipass contact: https://github.com/CanonicalLtd/multipass/issues/new license: GPL-3.0 description: | Multipass is a tool to launch and manage VMs on Windows, Mac and Linux that simulates a cloud environment with support for cloud-init. Get Ubuntu on-demand with clean integration to your IDE and version control on your native platform.

Launch an instance (by default you get the current Ubuntu LTS)

 multipass launch --name foo

Run commands in that instance, try running bash (logout or ctrl-d to quit)

 multipass exec foo -- lsb_release -a

Pass a cloud-init metadata file to an instance on launch

 multipass launch -n bar --cloud-init cloud-config.yaml

See your instances

 multipass list

Stop and start instances

 multipass stop
 multipass start

Get help

 multipass help

commands:

daniel-lenz commented 2 years ago

seems to be a permission problem: snap logs multipass
2022-01-29T18:08:07+01:00 systemd[1]: Stopped Service for snap application multipass.multipassd. 2022-01-29T18:08:07+01:00 systemd[1]: Started Service for snap application multipass.multipassd. 2022-01-29T18:08:07+01:00 multipassd[12691]: Caught an unhandled exception: unable to create directory '/vms/cache' 2022-01-29T18:08:07+01:00 systemd[1]: snap.multipass.multipassd.service: Main process exited, code=exited, status=1/FAILURE 2022-01-29T18:08:07+01:00 systemd[1]: snap.multipass.multipassd.service: Failed with result 'exit-code'. 2022-01-29T18:08:08+01:00 systemd[1]: snap.multipass.multipassd.service: Scheduled restart job, restart counter is at 5. 2022-01-29T18:08:08+01:00 systemd[1]: Stopped Service for snap application multipass.multipassd. 2022-01-29T18:08:08+01:00 systemd[1]: snap.multipass.multipassd.service: Start request repeated too quickly. 2022-01-29T18:08:08+01:00 systemd[1]: snap.multipass.multipassd.service: Failed with result 'exit-code'. 2022-01-29T18:08:08+01:00 systemd[1]: Failed to start Service for snap application multipass.multipassd.

daniel-lenz commented 2 years ago

still getting: 2022-01-29T19:08:50+01:00 multipassd[5492]: Caught an unhandled exception: unable to create directory '/media/cache'

my fstab: /dev/sda1 on /media type ext4 (rw,relatime)

daniel-lenz commented 2 years ago

dmesg tells me: [ 24.322499] audit: type=1400 audit(1643480065.310:84): apparmor="DENIED" operation="mkdir" profile="snap.multipass.multipassd" name="/media/cache/" pid=1469 comm="multipassd" requested_mask="c" denied_mask="c" fsuid=0 ouid=0

Saviq commented 2 years ago

@daniel-lenz you need to connect the removable-media interface: sudo snap connect multipass:removable-media. Otherwise confinement won't allow access.

https://snapcraft.io/docs/removable-media-interface

daniel-lenz commented 2 years ago

@Saviq saving multipass data on "/media" worked now, but not on another mount point e.g. "/vms". I also disabled apparmor=0 intermediately in grub defaults and activated it again, rebooted and now I am unsure that apparmor.service is running correctly, so I opened an issue with the apparmor-devs here: https://gitlab.com/apparmor/apparmor/-/issues/212

daniel-lenz commented 2 years ago

ok, apparmor developers checked the service configuration and all looks as it should. The only thing to do was manually, temporary disable apparmor with adding the grub default parameter "apparmor=0" and reboot. Then multipass service was able to create the directories below my /media-mountpoint.

Afterward removing the parameter "apparmor=0" from grub default and reboot. Multipass works as expected.

Good job!

Saviq commented 2 years ago

Glad to hear. I'll leave it open for the full multipass set local.storage=… experience.

daniel-lenz commented 2 years ago

yeah, great @Saviq keep it coming :+1:

daniel-lenz commented 2 years ago

@daniel-lenz you need to connect the removable-media interface: sudo snap connect multipass:removable-media. Otherwise confinement won't allow access.

https://snapcraft.io/docs/removable-media-interface

OMG, shout RTFM to me, my bad! :+1:

cpressland commented 1 year ago

Unfortunately it looks like we can no longer set environment variables on macOS using the method described in the documentation.

$ launchctl setenv MULTIPASS_STORAGE "/Volumes/WD2/multipass"
Could not set environment: 150: Operation not permitted while System Integrity Protection is engaged

So that multipass set local.storage= option would be really really helpful for macOS users right about now.

EDIT: As a workaround I've executed the following:

$ launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist
$ cd /var/root/Library/Application Support
$ rm -rf multipassd
$ ln -s /Volumes/WD2/multipass/data multipassd
$ launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist
huyz commented 1 year ago

Same as @cpressland . As of macOS 13.4 (Ventura), it looks like launchctl setenv requires disabling System Integrity Protection. So the docs at https://multipass.run/docs/configure-multipass-storage#heading--macos need to be updated with the symlink workaround (I use /Library/Application\ Support/multipassd/data)

giuliazanchi commented 1 month ago

The workaround is documented in https://multipass.run/docs/configure-multipass-storage