How to use the command 'multipass' (with examples)
The ‘multipass’ command is a tool that allows users to manage Ubuntu virtual machines using native hypervisors. It provides a convenient way to create, start, stop, and delete instances, as well as access their properties and execute commands within them.
Use case 1: List the aliases that can be used to launch an instance
Code:
multipass find
Motivation: When using the ‘multipass’ command, it is possible to launch instances with different aliases. This command helps users to list those aliases, providing a quick reference and simplifying the instance management.
Explanation: The ‘multipass find’ command does not require any arguments. It simply lists all the available aliases that can be used when launching an instance.
Example output:
Aliases:
eos:bionic # Ubuntu 18.04 LTS (Bionic Beaver)
fos:focal # Ubuntu 20.04 LTS (Focal Fossa)
groovy # Ubuntu 20.10 (Groovy Gorilla)
lts # Newest LTS available
lts-prelease # Newest LTS pre-release available
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: Launching a new instance with a specific name and using a cloud-init configuration file enables users to customize the instance’s initial setup. This allows for automating the configuration process and creating instances with predefined settings.
Explanation: The ‘multipass launch’ command is used to create a new instance, while the ‘-n’ flag sets a custom name for the instance. The ‘–cloud-init’ flag specifies the path to a cloud-init configuration file, which contains instructions for customizing the instance during its initial setup.
Example output:
Launching instance: instance_name
Downloading cloud-init file (example.yaml)...
Use case 3: List all created instances and their properties
Code:
multipass list
Motivation: Listing all the created instances and their properties gives users a clear overview of the existing virtual machines. It helps to keep track of active instances and their current states.
Explanation: The ‘multipass list’ command does not require any arguments. It simply lists all the instances that have been created, along with their names, IPv4 addresses, state, and the hypervisor they are running on.
Example output:
Name State IPv4 Release
instance1 Running 192.168.64.1 Ubuntu 20.04 LTS
instance2 Running 192.168.64.2 Ubuntu 18.04 LTS
Use case 4: Start a specific instance by name
Code:
multipass start instance_name
Motivation: Starting a specific instance by name is useful when you want to selectively run an instance without affecting others. This command is handy when working with multiple instances and needing to start them individually.
Explanation: The ‘multipass start’ command is used to start a specific instance. The ‘instance_name’ argument specifies the name of the instance to be started.
Example output:
Starting instance: instance_name
Use case 5: Show the properties of an instance
Code:
multipass info instance_name
Motivation: Displaying the properties of an instance provides important information about its configuration, such as its IP address, current state, and the hypervisor it is running on. This can be helpful for troubleshooting or monitoring purposes.
Explanation: The ‘multipass info’ command is used to display the properties of a specific instance. The ‘instance_name’ argument specifies the name of the instance to show information about.
Example output:
Name: instance_name
State: Running
IPv4: 192.168.64.1
Release: Ubuntu 20.04 LTS
Use case 6: Open a shell prompt on a specific instance by name
Code:
multipass shell instance_name
Motivation: Opening a shell prompt on a specific instance allows users to execute commands directly within the instance. This can be useful for managing and configuring the instance without the need for additional SSH connections.
Explanation: The ‘multipass shell’ command is used to open a shell prompt on a specific instance. The ‘instance_name’ argument specifies the name of the instance to connect to.
Example output:
Connected to instance_name
Use case 7: Delete an instance by name
Code:
multipass delete instance_name
Motivation: Deleting an instance is necessary when it is no longer needed or when it needs to be recreated. This command allows users to easily remove a specific instance by name.
Explanation: The ‘multipass delete’ command is used to delete a specific instance. The ‘instance_name’ argument specifies the name of the instance to be deleted.
Example output:
Deleting instance: instance_name
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 a directory into a specific instance allows users to share files and easily transfer data between their local machine and the instance. It simplifies the process of moving files and ensures seamless file access.
Explanation: The ‘multipass mount’ command is used to mount a directory from the local machine into a specific instance. The ‘path/to/local/directory’ argument specifies the path of the local directory to be mounted, while ‘instance_name:path/to/target/directory’ specifies the path where the directory should be mounted within the instance.
Example output:
Mounting path/to/local/directory on instance_name:/path/to/target/directory