KVM : 仮想管理ツール2021/08/27 |
|
仮想マシンを管理できるツール群をインストールしておくと、仮想管理がより容易になります。
|
|
| [1] | 仮想管理ツールをインストールします。 |
|
root@dlp:~# apt -y install libguestfs-tools
|
| [2] | 公式の OS イメージを取得して仮想マシンイメージを作成する。 ( OS インストールから自身で実行する場合はこちらの [1] を参照 ) |
|
# 作成可能な OS テンプレートの一覧 root@dlp:~# virt-builder -l ..... ..... debian-10 x86_64 Debian 10 (buster) debian-6 x86_64 Debian 6 (Squeeze) debian-7 sparc64 Debian 7 (Wheezy) (sparc64) debian-7 x86_64 Debian 7 (wheezy) debian-8 x86_64 Debian 8 (jessie) debian-9 x86_64 Debian 9 (stretch) ..... ..... # Debian 10 の仮想マシンイメージを作成する root@dlp:~# virt-builder debian-10 --format qcow2 --size 10G -o /var/kvm/images/debian-10.qcow2 --root-password password:myrootpassword
[ 7.2] Downloading: http://builder.libguestfs.org/debian-10.xz
[ 109.4] Planning how to build this image
[ 109.4] Uncompressing
[ 113.7] Resizing (using virt-resize) to expand the disk to 10.0G
[ 137.2] Opening the new disk
[ 140.7] Setting a random seed
virt-builder: warning: random seed could not be set for this type of guest
[ 140.8] Setting passwords
[ 141.6] Finishing off
Output file: /var/kvm/images/debian-10.qcow2
Output size: 10.0G
Output format: qcow2
Total usable space: 9.8G
Free space: 8.9G (90%)
# 作成した仮想マシンイメージで仮想マシンを設定するには virt-install
root@dlp:~# virt-install \
--name debian-10 \
--ram 4096 \
--disk path=/var/kvm/images/debian-10.qcow2 \
--vcpus 2 \
--os-variant debian10 \
--network bridge=br0 \
--graphics none \
--noautoconsole \
--boot hd \
--noreboot \
--import
Starting install...
Domain creation completed.
You can restart your domain by running:
virsh --connect qemu:///system start debian-10
|
| [3] | 仮想マシン内のあるディレクトリを [ls] する。 |
|
# 仮想マシン [debian11] の [/root] を [ls -l] root@dlp:~# virt-ls -l -d debian11 /root total 24 drwx------ 3 0 0 4096 Aug 27 00:30 . drwxr-xr-x 19 0 0 4096 Aug 27 00:25 .. -rw------- 1 0 0 16 Aug 27 00:30 .bash_history -rw-r--r-- 1 0 0 571 Apr 10 20:00 .bashrc drwx------ 2 0 0 4096 Aug 27 00:29 .cache -rw-r--r-- 1 0 0 161 Jul 9 2019 .profile |
| [4] | 仮想マシン内のあるファイルを [cat] する。 |
|
# 仮想マシン [debian11] の [/etc/passwd] を [cat] root@dlp:~# virt-cat -d debian11 /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin ..... ..... |
| [5] | 仮想マシン内のあるファイルを編集する。 |
|
# 仮想マシン [debian11] の [/etc/fstab] を編集 root@dlp:~# virt-edit -d debian11 /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # systemd generates mount units based on this file, see systemd.mount(5). # Please run 'systemctl daemon-reload' after making changes here. # # <file system> <mount point> <type> <options> <dump> <pass> /dev/mapper/debian--vg-root / ext4 errors=remount-ro 0 1 # /boot was on /dev/vda1 during installation UUID=61e4e763-4804-4894-8a09-a6756cde4080 /boot ext2 defaults 0 2 /dev/mapper/debian--vg-swap_1 non swap sw 0 0 /dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0 |
| [6] | 仮想マシン内のディスク使用量を表示する。 |
|
# 仮想マシン [debian11] のディスク使用量を表示 root@dlp:~# virt-df -d debian11 Filesystem 1K-blocks Used Available Use% debian11:/dev/sda1 480618 61883 393801 13% debian11:/dev/debian-vg/root 18982140 3811780 14180768 21% |
| [7] | 仮想マシンのディスクをマウントする。 |
|
# 仮想マシン [debian11] のディスクを [/mnt] にマウント root@dlp:~# guestmount -d debian11 -i /mnt root@dlp:~# ll /mnt total 81 lrwxrwxrwx 1 root root 7 Aug 26 19:18 bin -> usr/bin drwxr-xr-x 4 root root 1024 Aug 26 19:27 boot drwxr-xr-x 4 root root 4096 Aug 26 19:18 dev drwxr-xr-x 118 root root 12288 Aug 26 19:29 etc drwxr-xr-x 3 root root 4096 Aug 26 19:27 home lrwxrwxrwx 1 root root 30 Aug 26 19:19 initrd.img -> boot/initrd.img-5.10.0-8-amd64 ..... ..... |
| Sponsored Link |
|
|