multipassを使って仮想マシンを管理する
概要
multipassはいいぞ。
使いましょう。
前提
・Ubuntu 18.04
WindowsでもmacOSでも動作するらしいです。
注意
ひとまず動く状態を作っているだけなので、品質とかは期待しないでください。
multipassって何?
仮想マシン管理のためのツールです。気軽の仮想マシンの作成・削除・起動・停止をすることが可能です。
インストール手順概要
snapでインストールできるので、インストールする。
$ sudo snap install multipass
動作確認
$ multipass version
multipass 1.4.0
multipassd 1.4.0
仮想マシンの構築
$ multipass find
Image Aliases Version Description
snapcraft:core core16 20200831 Snapcraft builder for Core 16
~~~~~~~~省略~~~~~~~~
ore 18
16.04 xenial 20200904 Ubuntu 16.04 LTS
18.04 bionic 20200908 Ubuntu 18.04 LTS
20.04 focal,lts 20200907 Ubuntu 20.04 LTS
~~~~~~~~省略~~~~~~~~
appliance:plexmediaserver 20200812 Ubuntu Plex Media Server Appliance
multipass findコマンドを実行すると利用可能な仮想マシンイメージの一覧が表示されます。Aliasesにltsとあるものがデフォルトで利用される仮想マシンイメージです。
multipass launchを利用して仮想マシンを起動します。
$ multipass launch -n primary 20.04
launch failed: Cannot check BIOS for determining KVM extensions support.
Unable to load KVM support. Please ensure KVM is installed on your machine.
うまく行かないときはこのあたりをインストール(参考: Ubuntu 18.04: 仮想化のKVMをインストールする)したりBIOSでVT-x, VT-dなどの仮想化関連のテクノロジーが有効になっているかを確認します。
sudo apt install -y qemu-kvm libvirt0 libvirt-bin virt-manager libguestfs-tools
勢い余ってkvmをインストールしていますが、デフォルトではqemuを使うらしいのでここの作業はいらないかもしれません。
必要な要件を満たしてmultipass launchコマンドを実行すると仮想マシンが立ち上がります。
$ multipass launch -n primary 20.04
Launched: primary
Mounted '/home/fujiwara' into 'primary:Home'
起動した仮想マシンを確認。
$ multipass list
Name State IPv4 Image
primary Running 10.204.85.168 Ubuntu 20.04 LTS
シェルにアクセスしてみます。
$ multipass shell primary
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-47-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Sat Sep 12 16:04:25 JST 2020
System load: 0.08 Processes: 110
Usage of /: 26.3% of 4.67GB Users logged in: 0
Memory usage: 20% IPv4 address for ens4: 10.204.85.168
Swap usage: 0%
1 update can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable
あとはお好きに利用してください。
インスタンスの生成・削除・起動停止に関わるコマンド
■仮想マシンの作成と起動
$ multipass launch 仮想マシン名 (仮想マシンイメージ名)
-------------------------------------------------
■仮想マシンの削除関連コマンド
- 仮想マシンを削除状態にする
$ multipass delete 仮想マシン名
- 仮想マシンを削除する
$ multipass purge 仮想マシン名
-仮想マシンの復旧を行う(削除状態の仮想マシンを元に戻す)
$ multipass recover 仮想マシン名
-------------------------------------------------
■仮想マシンを起動する
$ multipass start 仮想マシン名
-------------------------------------------------
■仮想マシンを停止する
$ multipass stop 仮想マシン名
仮想マシンの作成についてもう少し詳しく
仮想マシンのリソース割当を変更したい場合は以下の内容を利用します。
$ multipass launch -n 仮想マシン名 \
-c 割当CPUコア数 \
-m 割当メモリ \
-d 割当ディスクサイズ
例えばCPU 2コア、8GBメモリ、50GBのディスクを備えた仮想マシンsecondaryが必要な場合は以下のコマンドを実行します。
$ multipass launch -n secondary \
-c 2 \
-m 8G \
-d 50G
仮想マシンへのアクセス
仮想マシンにアクセスする際にはmultipass shellコマンドを使います。
$ mutlipass shell 仮想マシン名
実際には裏側で公開鍵認証を利用したsshを行っているようです。
新規に作成したユーザで公開鍵認証して操作するなり、初期からあるubuntuユーザにパスワードを設定するなり色々自由に使えばいいと思います。
$ multipass shell primary
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-47-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Sat Sep 12 16:44:25 JST 2020
System load: 0.0 Processes: 107
Usage of /: 26.5% of 4.67GB Users logged in: 1
Memory usage: 17% IPv4 address for ens4: 10.204.85.168
Swap usage: 0%
1 update can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable
Last login: Sat Sep 12 16:22:41 2020 from 10.204.85.1
ubuntu@primary:~$
この記事が気に入ったらサポートをしてみませんか?