laitimes

Lightweight virtual machine!

For us engaged in the IT technology industry, everyone should be familiar with VMware virtual machines, usually build a learning, testing, development environment by yourself, and really can't do without it.

VMware virtual machines are very powerful, such as: fast start-up, easier and faster running programs; Virtual systems can only emulate the same environment as existing operating systems, while virtual machines can emulate other kinds of operating systems; And virtual machines need to emulate the underlying hardware instructions, so they run much slower than virtual systems.

VMware virtual machines are really good to use, but they are charged, and they are not cheap. So, today, I would like to introduce you to a user-friendly and lightweight virtual machine product Multipass (free and open source).

Introduction to Multipass

Multipass is a very lightweight virtual machine command management tool that supports multi-platform runtime environments such as Linux, Windows, and macO S.

Lightweight virtual machine!

Multipass is an open source project launched by Canonical, the Ubuntu operating company. On different operating systems, different virtualization technologies are used, and you can quickly create the virtual machines you need with minimal resource overhead.

For programmers using Linux systems, Multipass also provides a command-line interface to manage your Linux instance, which is very convenient, easy to operate and manage.

Multipass installation

On the official website: https://multipass.run/ Select the system version that should be downloaded on:

Lightweight virtual machine!

The version of Windows I chose here

Lightweight virtual machine!

After installation, check the version you installed

$ multipass version           

Multipass use

Create an Ubuntu virtual machine

Start by looking at the Ubuntu images you can download and use

$ multipass find
           

After successful operation, you can see the following list of these images, including various versions.

Image                       Aliases           Version          Description                                              
snapcraft:core18                              20201111         Snapcraft builder for Core 18                            
snapcraft:core20                              20201111         Snapcraft builder for Core 20                            
core                        core16            20200818         Ubuntu Core 16                                           
core18                                        20200812         Ubuntu Core 18                                           
16.04                       xenial            20210128         Ubuntu 16.04 LTS                                         
18.04                       bionic            20210129         Ubuntu 18.04 LTS                                         
20.04                       focal,lts         20210223         Ubuntu 20.04 LTS                                         
20.10                       groovy            20210209         Ubuntu 20.10                                             
appliance:adguard-home                        20200812         Ubuntu AdGuard Home Appliance                            
appliance:mosquitto                           20200812         Ubuntu Mosquitto Appliance                               
appliance:nextcloud                           20200812         Ubuntu Nextcloud Appliance                               
appliance:openhab                             20200812         Ubuntu openHAB Home Appliance                            
appliance:plexmediaserver                     20200812         Ubuntu Plex Media Server Appliance
           

Create a new container

$ multipass launch --name dg
Launched: dg
           

Then download the latest version of the Ubuntu image, and then we can use it directly.

$ multipass exec dg -- lsb_release -d
Description:    Ubuntu 18.04.4 LTS
           

Operate the virtual machine

View the list of virtual machines

After the virtual machine is created, view the list of virtual machines.

Name                 State             IPv4             Image
dg                   Running           192.168.24.5     Ubuntu 18.04 LTS
           

There is now a virtual machine running with Ubuntu version 18.04 with the corresponding IP address: 192.168.24.5.

View virtual machine information

Through the command, you can view the specific information of the currently running virtual machine.

$ multipass info --all
 
Name:           dg
State:          Running
IPv4:           192.168.24.5
Release:        Ubuntu 18.04.4 LTS
Image hash:     fe3030933742 (Ubuntu 18.04 LTS)
Load:           0.00 0.00 0.00
Disk usage:     1.5G out of 4.7G
Memory usage:   112.1M out of 985.7M
           

Enter the virtual machine

Use the following command to view the virtual machine's system configuration information, memory, disk usage, and so on.

$ multipass shell dg
           

If you don't want to go inside the system, you can also operate the Ubuntu system through the multipass exce command mentioned above.

Pause/restart the virtual machine

# 暂停
$ multipass stop dg
# 启动
$ multipass start dg
           

Delete/release the virtual machine

After you delete a virtual machine using the delete command, it actually exists, and you need to release the virtual machine to delete it completely.

# 删除
$ multipass delete dg
# 释放
$ multipass purge dg
           

Configure automation

It is necessary to keep the development environment and online environment consistent, while saving deployment time. We can initialize the container with --cloud-init:

$ multipass launch --name ubuntu --cloud-init config.yaml
config.yaml 是初始化配置文件,内容如下:

#cloud-config
 
runcmd:
 - curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
 - sudo apt-get install -y nodejs  
 - wget https://releases.leanapp.cn/leancloud/lean-cli/releases/download/v0.21.0/lean-cli-x64.deb  
 - sudo dpkg -i lean-cli-x64.deb
           

runcmd can specify commands that run when the container is first started.

summary

After using it for a while, I think this tool is really good! For example, I'm going to do some Linux experiments, and I can set up the system in a few minutes through Multipass to test it. To test a small DB cluster, you can also quickly set up a virtual machine cluster locally via Multipass, which is great!

The only fly in the ointment is that Multipass can only use Ubuntu images, because this tool is developed and open source by Canonical, the company behind Ubuntu.