Modifying your VM

Modify your VM using the Anka Virtualization CLI

The rest of this Getting Started guide focuses heavily on the Anka Virtualization CLI (Command-Line Interface). These will be performed from within your macOS Terminal. For all available CLI commands, flags, and options, see the Command Reference.

Prerequisites

  1. You’ve installed the Anka Virtualization package
  2. You’ve got an active license
  3. You’ve created your first VM

Using the modify command

> sudo anka modify --help
Usage: anka modify [OPTIONS] VM_ID COMMAND [ARGS]...

  Modify a VM's configuration

Options:
  --help  Display usage information

Commands:
  add
  delete
  set
  show
> sudo anka modify 12.0.1 set --help
Usage: anka modify set [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Display usage information

Commands:
  cpu              Set number of vcpu cores and frequency
  custom-variable  Set custom nvram & smb variables (Example: .
  description      Set description of the VM
  display          Configure displays
  hard-drive       Modify hard drive settings
  name             Set new template name for the VM
  network-card     Modify network card settings
  policy           Enable VM access management
  ram              Set RAM size and parameters

Increase your VM’s disk space with hard-drive

Change the disk space on an existing VM with the following commands:

anka modify {vmNameOrUUID} set hard-drive --size 100GB
anka run --no-volume {vmNameOrUUID} diskutil apfs resizeContainer disk1 0

It’s currently impossible to downsize a VM’s hard-drive. We suggest creating your initial VM with a smaller amount of available disk and then increase in subsequent Tags.

Changing your VM’s network configuration with network-card

Depending on your network topology, there are instances where you might need to use a bridge mode and assign your VM a unique IP address instead of the default shared IP of the host:

> sudo anka modify 12.0.1 set network-card --help
Usage: anka modify set network-card [OPTIONS] [INDEX]...

  Modify network card settings

Options:
  -t, --type [shared|host|bridge|disconnected]
  -b, --bridge TEXT               host interface name to bridge with
  -m, --mac TEXT                  specify fixed MAC address
  -n, --no-mac                    deassign fixed MAC address
  --direct-mac / --no-direct-mac  expose --mac externally
  -v, --vlan INTEGER              assign VLAN ID
  -c, --controller [anet|virtio-net]
                                  set controller
  --local / --no-local            enable (default)/disable inter-VM and VM-host communication
  --help                          Display usage information
❯ anka describe 11.0.1
. . .
network_cards

+------------+--------+--------+-----------+
|   pci_slot | type   | mode   |    pci_id |
+============+========+========+===========+
|         28 | anet   | shared | 538975646 |
+------------+--------+--------+-----------+
. . .

❯ anka modify 11.0.1 set network-card --type bridge --bridge en7

❯ anka describe 11.0.1
. . .
network_cards

+------------+--------+--------+-----------+
|   pci_slot | type   | mode   |    pci_id |
+============+========+========+===========+
|         28 | anet   | bridge | 538975646 |
+------------+--------+--------+-----------+
. . .

Set up your VM for external access with port-forwarding

If you wish for the VM to be accessible to other machines on your network, and are using a Shared network mode (the default), you will need to setup port forwarding:

❯ sudo anka modify 10.15.4 add port-forwarding --guest-port 22 ssh

❯ sudo anka describe 10.15.4

. . .

port_forwarding_rules

+------------+--------------+-------------+------------+-----------+-------------+
|   net_card |   guest_port | rule_name   | protocol   |   host_ip |   host_port |
+============+==============+=============+============+===========+=============+
|          0 |           22 | ssh         | tcp        |         0 |           0 |
+------------+--------------+-------------+------------+-----------+-------------+

❯ sudo anka start 10.15.4
. . . 
port_forwarding

+--------------+-------------+------------+--------+-----------+
|   guest_port |   host_port | protocol   | name   | host_ip   |
+==============+=============+============+========+===========+
|           22 |       10000 | tcp        | ssh    | 0.0.0.0   |
+--------------+-------------+------------+--------+-----------+

❯ ssh anka@localhost -p 10000
Password:
Last login: Mon Apr  6 12:45:50 2020
Mac-mini:~ anka

The VM can then be accessed using: ssh anka@{theHostRunningTheVMsIP} -p {host_port}

Unless you customize the host_port (with anka config portfwd_base), we default to using the 10000-10XXX port range. If you start a VM it will get 10000 unless a VM already exist. The existing VM using the 10000 port will cause an automatic assignment of 10001 to the newly started VM. Ensure that both the Controller server and any CI servers (where you host Jenkins for example) can reach the Node’s ports in your firewall rules.

Modify the hardware UUID and Serial with custom-variable

At times you might need to modify the hardware serial or UUID to run proper builds/tests that require specific hardware to function properly:

> sudo anka modify 12.0.1 set custom-variable --help
Usage: anka modify set custom-variable [OPTIONS] KEY VALUE

  Set custom nvram & smb variables (Example: . . . set custom-variable hw.serial "<SERIAL>"

Options:
  --help  Display usage information
sudo anka modify {vmNameOrUUID} set custom-variable hw.uuid "GUID"
sudo anka modify {vmNameOrUUID} set custom-variable hw.serial 'MySerial'

Running commands inside of the VM

We have a useful example bash script which shows how to automate the execution of commands to create the various VM Templates/Tags necessary for your project. You can find the script here. (requires a registry)

Installing dependencies, making OS or application level configuration changes, and even kicking off your build or test requires execution of commands inside of the VM. In the previous section on accessing your VM, we explained how you can use Anka Run to execute commands from the host’s terminal. Below are some examples, giving you an idea how to prepare the VM Template/Tag for your projects.

Disable Spotlight/MDS to avoid it consuming CPU/RAM resources

❯ anka run 12.1.0 bash -c "set -exo pipefail; \
echo \"Disable indexing\" && \
sudo defaults write ~/.Spotlight-V100/VolumeConfiguration.plist Exclusions -array \"/Volumes\" && \
sudo defaults write ~/.Spotlight-V100/VolumeConfiguration.plist Exclusions -array \"/Network\" && \
sudo killall mds && \
sleep 60 && \
sudo mdutil -a -i off && \
sudo mdutil -a -i off && \
sudo rm -rf /.Spotlight-V100/*"
+ echo 'Disable indexing'
+ sudo defaults write /Users/anka/.Spotlight-V100/VolumeConfiguration.plist Exclusions -array /Volumes
Disable indexing
+ sudo defaults write /Users/anka/.Spotlight-V100/VolumeConfiguration.plist Exclusions -array /Network
+ sudo killall mds
+ sleep 60
+ sudo mdutil -a -i off
2022-01-10 05:39:03.164 mdutil[1083:6592] mdutil disabling Spotlight: / -> kMDConfigSearchLevelFSSearchOnly
2022-01-10 05:39:03.273 mdutil[1083:6592] mdutil disabling Spotlight: /System/Volumes/Data -> kMDConfigSearchLevelFSSearchOnly
/:
	Indexing disabled.
/System/Volumes/Data:
	Indexing disabled.
+ sudo mdutil -a -i off
2022-01-10 05:39:03.815 mdutil[1085:6610] mdutil disabling Spotlight: / -> kMDConfigSearchLevelFSSearchOnly
2022-01-10 05:39:03.856 mdutil[1085:6610] mdutil disabling Spotlight: /System/Volumes/Data -> kMDConfigSearchLevelFSSearchOnly
/:
	Indexing disabled.
/System/Volumes/Data:
	Indexing disabled.
+ sudo rm -rf '/.Spotlight-V100/*'

Then, ensure there is no heavy usage from mds:

❯ anka run 12.1.0 bash -c "ps aux | grep mds"
anka              1091   0.0  0.0 34123248    984   ??  S     5:39AM   0:00.00 bash -c ps aux | grep mds
root               865   0.0  1.3 34024748 110880   ??  Ss    5:38AM   0:18.58 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support/mds_stores
root               863   0.0  0.4 33740376  34864   ??  Ss    5:38AM   0:12.59 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Support/mds
anka              1093   0.0  0.0 34122720    684   ??  S     5:39AM   0:00.00 grep mds

It’s always a good idea to run anka run 12.1.0 bash -c "ps aux | head" and ensure that there are no heavy CPU or RAM processes running.

Stop or Suspend the VM

This is not necessary for anka modify commands.

Once you’ve finalized your changes inside of the VM, be sure to use anka stop or anka suspend.

> sudo anka stop --help
Usage: anka stop [OPTIONS] [VMID]...

  Shut down a VM(s)

Options:
  -f, --force  Forcefully stop the VM
  -a, --all    Shutdown all running vms
  --help       Display usage information
> sudo anka suspend --help
Usage: anka suspend [OPTIONS] [VMID]...

  Suspend a running VM(s)

Options:
  -a, --all  Suspend all running vms
  --help     Display usage information

What’s next?