How to Use the Command 'multipass' (with examples)

How to Use the Command 'multipass' (with examples)

Multipass is an essential tool used to manage Ubuntu virtual machines seamlessly using native hypervisors. It is especially favored for its simplicity and speed, enabling users to spin up instances of Ubuntu in just a few commands. This makes it an ideal tool for developers, testers, and system administrators who need to quickly test software in a clean, isolated environment that can be easily destroyed and recreated.

Use case 1: List the aliases that can be used to launch an instance

Code:

multipass find

Motivation:

Understanding which Ubuntu images and configurations are available is crucial for users who need specific versions or setups for their application testing or development. This command provides an easy way to explore the ready-to-use image aliases without needing to consult external documentation. It ensures that users select the correct instance tailored for their requirements.

Explanation:

  • multipass: The command-line tool used to interact with virtual machines.
  • find: Subcommand that lists available image aliases which can be directly used with the launch command.

Example Output:

Image                       Aliases           Version
18.04                       bionic
20.04                       focal             20201026
21.04                       hirsute

The output showcases possible images that users can launch. Each alias can be specified to create an instance of the chosen version, aiding in replicating environments reliably across different machines and projects.

Use case 2: Launch a new instance, set its name, and use a cloud-init configuration file

Code:

multipass launch -n instance_name --cloud-init configuration_file

Motivation:

This use case allows for creating a virtual machine with a custom setup during its initial boot process, which is perfect for automating the setup of testing or development environments. Using cloud-init greatly simplifies configurations, like setting up users, installing packages, or configuring services without requiring manual intervention after boot.

Explanation:

  • multipass launch: Launches a new instance.
  • -n instance_name: Sets the name of the new virtual machine. This makes it easier for users to manage and reference the instance later.
  • --cloud-init configuration_file: Specifies a cloud-init configuration file to apply when the instance is first created. Cloud-init is a standard method for automating configuration of cloud instances.

Example Output:

Launched: instance_name

The output confirms the successful launch of a virtual machine named “instance_name”, ready and configured according to the provided cloud-init file.

Use case 3: List all the created instances and some of their properties

Code:

multipass list

Motivation:

Keeping track of all running, paused, or stopped virtual instances is essential for effective resource management. This command provides a quick overview of all existing instances and their statuses, allowing users to monitor resources and perform necessary management operations.

Explanation:

  • multipass list: Lists all instances managed by Multipass, displaying key information like instance names, states, and IP addresses.

Example Output:

Name                    State             IPv4             Image
instance_name           Running           192.168.64.3     Ubuntu 20.04 LTS
another_instance        Stopped           --               Ubuntu 18.04 LTS

The output displays the names, statuses, IP addresses, and images of various instances, providing essential data at a glance for system administrators.

Use case 4: Start a specific instance by name

Code:

multipass start instance_name

Motivation:

There are times when an instance may have been stopped to conserve resources or is intentionally paused. This command is used to restart such an instance when it’s needed again for development or testing, ensuring the workflow is seamless and efficient.

Explanation:

  • multipass start: A subcommand to start a virtual instance.
  • instance_name: The specific name of the instance to be started, which was set during creation to ensure that the correct instance is launched.

Example Output:

Starting instance_name

The output indicates that the instance “instance_name” is being started.

Use case 5: Show the properties of an instance

Code:

multipass info instance_name

Motivation:

Detailed information about an instance might be needed to debug issues, gather configuration data, or verify instance properties. This command is efficient for obtaining otherwise manually cumbersome details about an instance.

Explanation:

  • multipass info: Retrieves detailed information about a specific instance.
  • instance_name: The target instance whose information is to be fetched.

Example Output:

Name:                   instance_name
State:                  Running
IPv4:                   192.168.64.3
Release:                Ubuntu 20.04.4 LTS

The output confirms the instance status along with its release version and IP address, aiding troubleshooting and configuration verification.

Use case 6: Open a shell prompt on a specific instance by name

Code:

multipass shell instance_name

Motivation:

At times, directly interacting with the instance via a terminal is necessary for debugging, running scripts, or installing software manually. This command allows users to open a command line on the instance quickly, avoiding the need for SSH configuration.

Explanation:

  • multipass shell: Opens an interactive shell session on the given instance.
  • instance_name: The instance you want to connect to.

Example Output:

Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-42-generic x86_64)

The output signifies a successful login into the instance with a shell prompt ready for users to enter commands directly.

Use case 7: Delete an instance by name

Code:

multipass delete instance_name

Motivation:

Deleting instances that are no longer needed helps free up system resources, especially disk space. This command is particularly useful in maintaining a tidy working environment, where only actively needed virtual machines are retained.

Explanation:

  • multipass delete: Deletes a specified instance from the system.
  • instance_name: The target instance selected for deletion.

Example Output:

Deleted: instance_name

This output confirms the successful deletion of the instance “instance_name”, clearing up resources consumed by the VM.

Use case 8: Mount a directory into a specific instance

Code:

multipass mount path/to/local/directory instance_name:path/to/target/directory

Motivation:

Mounting local directories allows sharing data and files between the host and VM without duplication. This capability is critical for testing or running applications needing direct access to large datasets or frequently changing files stored on the host machine.

Explanation:

  • multipass mount: Command to mount a directory.
  • path/to/local/directory: Specifies the local system’s directory intended to share.
  • instance_name:path/to/target/directory: The target directory inside the virtual instance where the local directory will be mounted.

Example Output:

Mounted: path/to/local/directory -> instance_name:path/to/target/directory

An indication that a local directory has been successfully mounted onto the instance, enabling shared access to its content.

Conclusion:

Using Multipass effectively can revolutionize the way virtual machines are managed for testing and development purposes. By understanding these use cases and the commands involved, users can manipulate Ubuntu VMs with ease, enabling intricate workflows and seamless transitions between different development environments. Whether it’s creating, managing, or deleting instances, Multipass provides a straightforward interface that caters to developers and administrators alike.

Related Posts

Mastering Tmuxinator Commands (with examples)

Mastering Tmuxinator Commands (with examples)

Tmuxinator is a powerful command-line utility designed to streamline the process of managing tmux sessions.

Read More
How to use the command qemu-img (with examples)

How to use the command qemu-img (with examples)

qemu-img is a versatile command-line utility designed to create and manipulate virtual HDD images for Quick Emulator (QEMU).

Read More
How to Use the Command 'vgcreate' (with Examples)

How to Use the Command 'vgcreate' (with Examples)

The vgcreate command is a crucial tool in the Linux Logical Volume Manager (LVM) system used to create volume groups.

Read More