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

changing number of CPUs for an instance #1158

Closed
VasiliyS opened this issue Oct 30, 2019 · 62 comments · Fixed by #2353
Closed

changing number of CPUs for an instance #1158

VasiliyS opened this issue Oct 30, 2019 · 62 comments · Fixed by #2353
Labels
enhancement medium medium importance

Comments

@VasiliyS
Copy link

Is it possible to change number of CPUs available to an existing instance? What about memory?

@Saviq
Copy link
Collaborator

Saviq commented Oct 30, 2019

Hi @VasiliyS, I'm afraid it's not, not easily at the moment. #756 designs the experience, but it's not yet implemented.

Depending on platform, you could just edit the VM in the hypervisor (Hyper-V, VirtualBox), or stop Multipass and edit its instance database.

Let us know what your environment is and we can guide you there :)

@Saviq Saviq added enhancement medium medium importance labels Oct 30, 2019
@VasiliyS
Copy link
Author

@Saviq - Thank you. I'm on a Mac. Where can I find the instance database?

@Saviq
Copy link
Collaborator

Saviq commented Oct 30, 2019

@VasiliyS here are the steps:

# stop multipassd
sudo launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist

# edit /var/root/Library/Application Support/multipassd/multipassd-vm-instances.json
# you'll need sudo for that

# start multipassd again
sudo launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist

The format should be quite easy to grok:

{
    "primary": {
        "deleted": false,
        "disk_space": "5368709120",
        "mac_addr": "52:54:00:5c:f4:14",
        "mem_size": "1073741824",
        "metadata": {
        },
        "mounts": [
        ],
        "num_cores": 1,
        "ssh_username": "ubuntu",
        "state": 0
    }
}

You want to edit num_cores for CPU and mem_size for memory :)

@VasiliyS
Copy link
Author

@Saviq - Just tried it. The instance doesn't start - the cli times out ("timed out waiting for response"). multipass info tells me that the state is unknown and the json file has state set to 8. multipass stop ends with "process error occurred Crashed". The state key in the json file is now 0.


After stopping the multipassd, editing the num_cores key value back to 1 and re-starting the daemon, the instance starts fine.

@Saviq
Copy link
Collaborator

Saviq commented Oct 31, 2019

@VasiliyS hmm can you look in /Library/Logs/Multipass/multipassd.log for any errors? Does a new instance with 2 CPUs (multipass launch --cpus 2) work fine?

@VasiliyS
Copy link
Author

@Saviq - I was able to create a new instance with 2 cpus, worked fine.

I'm attaching 2 files with excerpts from the log. One where I've edited the cpu key to 2 and the instance doesn't start.
2_cpus_doesnt_start.log

The second one where I've changed the setting back to 1 cpu and it works.
1_cpu_starts.log

@VasiliyS
Copy link
Author

@Saviq - Update!
I've just tried something. The instance actually starts fine, it's the cli that timeouts.
multipass start exits with a timeout message, but I'm still able to ssh into the instance, etc.


The weird thing is , now even the instance that I've launch'd with --cpus 2 option from scratch doesn't start normally (i.e. multipass start timeouts), but the instance actually works fine. That gave me an idea to try again with editing the num_cores key and ignore the timeout message. Now that I know where the id_rsa is, I can login directly even when multipass shell/info/etc don't work normally. Oh well...

@townsend2010
Copy link
Contributor

Hi @VasiliyS,

It looks like you are hitting #1122 when it's using 2 cpu's. The next version of Multipass has a fix for that. We have a release candidate for 0.9 up and can be found at https://github.com/CanonicalLtd/multipass/releases/download/v0.9.0-rc/multipass-0.9.0-rc.425+g37fa4305.mac-Darwin.pkg if you are interested.

@VasiliyS
Copy link
Author

VasiliyS commented Nov 1, 2019

Hi @townsend2010 - thanks! The RC works just fine.
I guess now my original request has been met. I'm now able to change the number of CPUs for an existing instance.

Would be great to add a command to update the instance configuration via the cli, though. It's probably a common need, especially if one uses multipass to create a K8S machine and then discovers that the original resources are not sufficient.

@Saviq
Copy link
Collaborator

Saviq commented Nov 2, 2019

@VasiliyS glad you got it going. Yes, we'll allow changing the number of CPUs in due course :)

@sourcedelica
Copy link

And memory please.

@kramik1
Copy link

kramik1 commented Jan 22, 2020

Just to save some people some time, the below is for Ubuntu 19.10.

sudo systemctl stop snap.multipass.multipassd.service
sudo vi /var/snap/multipass/common/data/multipassd/multipassd-vm-instances.json
sudo systemctl start snap.multipass.multipassd.service

@denizzzka
Copy link

@kramik1 these settings will be overwritten by previous values if snapcraft clean will be called

@denizzzka
Copy link

denizzzka commented Mar 3, 2020

I drive into same problem with RAM setting: it is just too low for my snap (only 2Gb) and I can't to build anything.

@townsend2010
Copy link
Contributor

Hi @denizzzka,

There are some Snapcraft environment variables you can set to tweak memory, CPU count, and disk size. They are:

SNAPCRAFT_BUILD_ENVIRONMENT_CPU
SNAPCRAFT_BUILD_ENVIRONMENT_MEMORY
SNAPCRAFT_BUILD_ENVIRONMENT_DISK

Hope this helps!

@denizzzka
Copy link

Thanks @townsend2010

I tried this variables. Looks like it work inside of multipass VM, but VM itself still uses 2 cores and 2Gb of RAM (I checked this by atop utility)

@townsend2010
Copy link
Contributor

Hey @denizzzka,

Hmm, it's not supposed to work that way. 😕

I'll run some experiments in a while and if it's not working as it should, I'll ping the Snapcraft folks as they are the ones responsible for setting up these Multipass instances.

@denizzzka
Copy link

Thanks!

Please note that I did not change /var/snap/multipass/common/data/multipassd/multipassd-vm-instances.json settings file, because this makes no sense - it is automatically overwritten every time if snapcraft repository is cleaned

@townsend2010
Copy link
Contributor

Hey @denizzzka,

It seems to be working as expected here. Here's what I did on my Ubuntu host machine:

$ SNAPCRAFT_BUILD_ENVIRONMENT_CPU=4 SNAPCRAFT_BUILD_ENVIRONMENT_MEMORY=8G snapcraft
Launching a VM.
'SNAPCRAFT_BUILD_ENVIRONMENT_CPU' was set to '4' in the environment. Changing the default allocation upon user request
'SNAPCRAFT_BUILD_ENVIRONMENT_MEMORY' was set to '8G' in the environment. Changing the default allocation upon user request
...

I can clearly see the snapcraft instance used to build my snap is now using 4 cores and has 8GB allocated to it. Did you snapcraft clean and ensure the instance was gone via multipass list before trying the environment variables?

@denizzzka
Copy link

Offtopic:
I removed everything from my Debian and start again. After snapcraft was installed I faced with:

$ snapcraft
cannot snap-exec: cannot exec "/snap/snapcraft/4126/usr/bin/python3": no such file or directory

It worked previously. The experiments are postponed indefinitely.

@denizzzka
Copy link

Ok, I sucessfully reinstalled it. Works! Thanks @townsend2010 !

@acefei
Copy link

acefei commented Mar 13, 2020

is there any effect way on windows?
The following steps (run as Administrator) are what I did, but the modification doesn't work, the VM started as before.

multipass.exe stop --all
Stop-Service -Name Multipass
notepad.exe 
 C:\Windows\System32\config\systemprofile\AppData\Roaming\multipassd\multipassd-vm-instances.json
Start-Service -Name Multipass
multipass.exe start --all

multipass version

multipass  1.1.0+win
multipassd 1.1.0+win

@Saviq
Copy link
Collaborator

Saviq commented Mar 13, 2020

@acefei on Windows you can go to the Hyper-V manager (or psexec.exe -s -i VirtualBox, if using that) and change it there.

@Saviq
Copy link
Collaborator

Saviq commented Mar 15, 2020

@acefei you can do that with PowerShell's Set-VMProcessor cmdlet.

@huangxuankai
Copy link

I try two solution to chage cpu, mem, disk space, learn from @kramik1
host: ubuntu 16.04
guest: ubuntu 18.04
snap multipass: 1.2.0

sudo systemctl stop snap.multipass.multipassd.service

// here i only change memory and cpu 
sudo vi /var/snap/multipass/common/data/multipassd/multipassd-vm-instances.json
sudo qemu-img resize /var/snap/multipass/common/data/multipassd/vault/instances/instance_xxx/instance_xxx.img +10G

sudo systemctl start snap.multipass.multipassd.service

multipass start instance_xxx
// here runing ok
multpass info instance_xxx

but key disk_space in file multipassd-vm-instances.json remain not change, I don't know if there will be problems in the future

another solution
i stop all instance on multpasss
set sudo multipass set local.driver=libvirt
then use virt-manager to change cpu and mem
disk space change use sudo qemu-img resize /var/snap/multipass/common/data/multipassd/vault/instances/instance_xxx/instance_xxx.img +10G
finally, start instance, and it run well

@santiagomoneta
Copy link

Can anyone share some light on how to do this on MacOS (Catalina). Thanks

@Saviq
Copy link
Collaborator

Saviq commented Jun 19, 2020

Hi @santiagomoneta, one of the first comments (#1158 (comment)) has the steps.

@hemna
Copy link

hemna commented Jun 22, 2021

Seems like there should be a much easier way to do this from the multipass command line itself.
Like,
multipass stop
multipass update -c 4
multipass start

@Saviq
Copy link
Collaborator

Saviq commented Jun 22, 2021

@hemna we have something like this scheduled for the near months. See #756 for details of what we want to go for.

@mconner
Copy link

mconner commented Jul 22, 2021

@Saviq

If we modify the cpu or memory in Hyper-V Manager, the values in multipassd-vm-instances.json are not updated. Should we edit it to match?

@Saviq
Copy link
Collaborator

Saviq commented Jul 22, 2021

@mconner for Hyper-V and VirtualBox there's no need - they hold their own VM configuration.

@Saviq
Copy link
Collaborator

Saviq commented Jul 22, 2021

FWIW we have scheduled basic instance modification this cycle, we'll be starting on it soon.

@oldthreefeng
Copy link

Niubility...

@tuxerrante
Copy link

tuxerrante commented Aug 31, 2021

@magmine then you want to follow https://multipass.run/docs/using-virtualbox-in-multipass-windows and modify the instance with either VBoxManage or the VirtualBox GUI. The Set-VMProcessor cmdlet only works for Hyper-V instances.

Note that when you can't keep the GUI open, otherwise Multipass will have trouble managing the instance (VirtualBox only allows a single entity to manage VMs at any time).

After switching to VBox I can't see them anymore, nor in multipass list nor in VBox GUI, even after other commands of that tutorial.
Should I delete them and recreate them with the VBox driver?
Can I choose the image directory such that I can manually import them in VBox?

immagine

EDIT:
I was able to do it through the Hyper-v manager
immagine

@matejk
Copy link

matejk commented Nov 19, 2021

sudo vim /var/root/Library/Application Support/multipassd/multipassd-vm-instances.json

You either need to escape the space (Application\ Support), or put the whole path in quotes.

With multipass 1.8.1 on macOS Monterey the configuration file is

/var/root/Library/Application\ Support/multipassd/qemu/multipassd-vm-instances.json

@sijakret
Copy link

sijakret commented Dec 7, 2021

For mac OS this is what helped me: https://www.atpeaz.com/change-multipass-instance-memory-and-cpu-allocation-after-launch/

it was important to unload the multipass service first:

sudo launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist

then modify multipassd-vm-instances.json

@VasiliyS here are the steps:

# stop multipassd
sudo launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist

# edit /var/root/Library/Application Support/multipassd/multipassd-vm-instances.json
# you'll need sudo for that

# start multipassd again
sudo launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist

The format should be quite easy to grok:

{
    "primary": {
        "deleted": false,
        "disk_space": "5368709120",
        "mac_addr": "52:54:00:5c:f4:14",
        "mem_size": "1073741824",
        "metadata": {
        },
        "mounts": [
        ],
        "num_cores": 1,
        "ssh_username": "ubuntu",
        "state": 0
    }
}

You want to edit num_cores for CPU and mem_size for memory :)

then restart

sudo launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist

otherwise it would always reset the changes I made. (multipass stop was not enough in my case!)

@jbosse
Copy link

jbosse commented Feb 15, 2022

I can't find multipassd-vm-instances.json anywhere on my M1 Mac.

@Saviq
Copy link
Collaborator

Saviq commented Feb 15, 2022

@jbosse it should be /var/root/Library/Application Support/multipassd/qemu/multipassd-vm-instances.json - if it doesn't exist… did you launch any instances?

@jbosse
Copy link

jbosse commented Feb 16, 2022

@Saviq Thank you. Mac really doesn't want you to see it in the finder or open it in VSCode. I could only make it open in nano. I had given up though and just made a new instance passing the --mem and --cpus options I wanted.

@colemancda
Copy link

multipassd-vm-instances.json doesn't exist on my MacBook Pro (M1 Pro) either.

@jbosse
Copy link

jbosse commented Mar 15, 2022

multipassd-vm-instances.json doesn't exist on my MacBook Pro (M1 Pro) either.

@colemancda Try sudo ls /var/root/Library/Application\ Support/multipassd/qemu/ to see the contents or sudo nano /var/root/Library/Application\ Support/multipassd/qemu/multipassd-vm-instances.json to view the file.

@pauljsymonds
Copy link

@VasiliyS here are the steps:

# stop multipassd
sudo launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist

# edit /var/root/Library/Application Support/multipassd/multipassd-vm-instances.json
# you'll need sudo for that

# start multipassd again
sudo launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist

The format should be quite easy to grok:

{
    "primary": {
        "deleted": false,
        "disk_space": "5368709120",
        "mac_addr": "52:54:00:5c:f4:14",
        "mem_size": "1073741824",
        "metadata": {
        },
        "mounts": [
        ],
        "num_cores": 1,
        "ssh_username": "ubuntu",
        "state": 0
    }
}

You want to edit num_cores for CPU and mem_size for memory :)

How would I do this on Ubuntu?

# stop multipassd
sudo launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist

# edit /var/root/Library/Application Support/multipassd/multipassd-vm-instances.json
# you'll need sudo for that

# start multipassd again
sudo launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist

@Saviq
Copy link
Collaborator

Saviq commented Apr 11, 2022

Anyone stumbling here, you can now try the implementation in action in #2353, with snaps under edge/pr2353 channel and Windows and macOS packages.

@muhammad-asn
Copy link

muhammad-asn commented Apr 16, 2022

Thank you this solution works on Mac

@lulor
Copy link

lulor commented Apr 22, 2022

@Saviq Thank you for the update, it works great!
May I ask why both the number of cores and the memory can only be increased? It makes perfect sense for the disk, but to me it's less obvious for the other two parameters

@Saviq
Copy link
Collaborator

Saviq commented Apr 22, 2022

@lulor the primary reason are blueprints, which declare the minimum memory and CPU cores meaningful for a particular use case. That said, we're reconsidering whether we should be that limiting, especially that if you make a mistake and give too much, there's currently no way back.

@lulor
Copy link

lulor commented Apr 22, 2022

@Saviq I see, thank you for the explanation

@almontes1987
Copy link

almontes1987 commented May 31, 2022

I got it using another way. If you're using the VirtualBox driver, open the VirtualBox with the root account. There will be a new tab for Multipass with the instance already created. Just turn off the multipass instance, change the setting on the VirtualBox window and then turn on your multipass instance again.

@daviewales
Copy link

daviewales commented Jun 22, 2022

# stop multipassd
sudo launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist

# edit /var/root/Library/Application Support/multipassd/multipassd-vm-instances.json
# you'll need sudo for that

# start multipassd again
sudo launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist

How would one do this on Windows?

EDIT:

The file is here, but it doesn't appear to have an effect:

C:\ProgramData\Multipass\data\multipassd-vm-instances.json
  • I stopped Multipass Service in the Windows Services app.
  • I edited the file and changed mem_size to 3221225472 (3 GB).
  • I started the service again.
  • I launched my image and ran multipath info, but I still get Memory usage: 322.6M out of 912.5M.

Have I missed a step somewhere? Where can I find the logs?

@sebmartin
Copy link

I got it using another way. If you're using the VirtualBox driver, open the VirtualBox with the root account. There will be a new tab for Multipass with the instance already created. Just turn off the multipass instance, change the setting on the VirtualBox window and then turn on your multipass instance again.

FYI you can launch VirtualBox with the root account on macOS by running the following command in Terminal:

sudo /Applications/VirtualBox.app/Contents/MacOS/VirtualBox

@ricab
Copy link
Collaborator

ricab commented Nov 8, 2022

@almontes1987, @daviewales, @sebmartin, multipass set local.<instance>.cpus=<ncpus> should be enough to get you what you need; multipass get --keys shows instance attributes that can be changed that way (along with other settings). Let us know if you have problems with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement medium medium importance
Projects
None yet
Development

Successfully merging a pull request may close this issue.