KVM : 仮想管理ツール インストール2025/01/17 |
仮想マシンを管理できるツール群をインストールしておくと、仮想管理がより容易になります。 |
|
[1] | 仮想管理ツールをインストールします。 |
[root@dlp ~]# dnf -y install guestfs-tools virt-top
|
[2] | 公式の仮想マシンイメージから仮想マシンを作成する。 |
# 作成可能な OS テンプレートの一覧 [root@dlp ~]# virt-builder -l alma-8.5 x86_64 AlmaLinux 8.5 centos-6 x86_64 CentOS 6.6 centos-7.0 x86_64 CentOS 7.0 centos-7.1 x86_64 CentOS 7.1 centos-7.2 aarch64 CentOS 7.2 (aarch64) centos-7.2 x86_64 CentOS 7.2 centos-7.3 x86_64 CentOS 7.3 centos-7.4 x86_64 CentOS 7.4 centos-7.5 x86_64 CentOS 7.5 centos-7.6 x86_64 CentOS 7.6 centos-7.7 x86_64 CentOS 7.7 centos-7.8 x86_64 CentOS 7.8 centos-8.0 x86_64 CentOS 8.0 centos-8.2 x86_64 CentOS 8.2 centosstream-8 x86_64 CentOS Stream 8 centosstream-9 x86_64 CentOS Stream 9 cirros-0.3.1 x86_64 CirrOS 0.3.1 cirros-0.3.5 x86_64 CirrOS 0.3.5 ..... ..... # 例として [debian-12] の仮想マシンイメージを作成 # [myrootpassword] は設定したい root パスワードに置き換え [root@dlp ~]# virt-builder debian-12 --format qcow2 --size 10G -o /var/kvm/images/debian-12.qcow2 --root-password password:myrootpassword [ 4.5] Downloading: http://builder.libguestfs.org/debian-12.xz [ 109.9] Planning how to build this image [ 109.9] Uncompressing [ 112.4] Resizing (using virt-resize) to expand the disk to 10.0G [ 126.4] Opening the new disk [ 135.0] Setting a random seed virt-builder: warning: random seed could not be set for this type of guest [ 135.1] Setting passwords [ 135.7] SELinux relabelling [ 135.7] Finishing off Output file: /var/kvm/images/debian-12.qcow2 Output size: 10.0G Output format: qcow2 Total usable space: 9.8G Free space: 8.6G (87%) # 作成した仮想マシンイメージで仮想マシンを設定するには [virt-install] [root@dlp ~]# virt-install \ --name debian-12 \ --ram 4096 \ --disk path=/var/kvm/images/debian-12.qcow2 \ --vcpus 2 \ --os-variant debian12 \ --network bridge=br0 \ --graphics none \ --serial pty \ --console pty \ --boot hd \ --import |
[3] | 仮想マシン内のあるディレクトリを [ls] する。 |
[root@dlp ~]# virt-ls -l -d centos10 /root total 28 dr-xr-x---. 3 root root 147 Jan 17 00:11 . dr-xr-xr-x. 18 root root 235 Jan 17 00:03 .. -rw-------. 1 root root 16 Jan 17 00:11 .bash_history -rw-r--r--. 1 root root 18 Oct 29 00:00 .bash_logout -rw-r--r--. 1 root root 141 Oct 29 00:00 .bash_profile -rw-r--r--. 1 root root 429 Oct 29 00:00 .bashrc -rw-r--r--. 1 root root 100 Oct 29 00:00 .cshrc drwx------. 2 root root 6 Jan 17 00:03 .ssh -rw-r--r--. 1 root root 129 Oct 29 00:00 .tcshrc -rw-------. 1 root root 981 Jan 17 00:07 anaconda-ks.cfg |
[4] | 仮想マシン内のあるファイルを [cat] する。 |
[root@dlp ~]# virt-cat -d centos10 /etc/passwd root:x:0:0:Super User:/root:/bin/bash bin:x:1:1:bin:/bin:/usr/sbin/nologin daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin adm:x:3:4:adm:/var/adm:/usr/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/usr/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/usr/sbin/nologin operator:x:11:0:operator:/root:/usr/sbin/nologin ..... ..... |
[5] | 仮想マシン内のあるファイルを編集する。 |
[root@dlp ~]# virt-edit -d centos10 /etc/fstab # # /etc/fstab # Created by anaconda on Fri Jan 17 00:03:10 2025 # # Accessible filesystems, by reference, are maintained under '/dev/disk/'. # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info. # # After editing this file, run 'systemctl daemon-reload' to update systemd # units generated from this file. # UUID=6f8b7cd0-7af0-458b-b868-00a0bbaf3585 / xfs defaults 0 0 UUID=d17edee5-85d1-4755-af15-9982e62c2de9 /boot xfs defaults 0 0 UUID=80617d81-4d18-4f1e-9c98-d96e39333d20 none swap defaults 0 0 |
[6] | 仮想マシン内のディスク使用量を表示する。 |
[root@dlp ~]# virt-df -d centos10 Filesystem 1K-blocks Used Available Use% centos10:/dev/sda2 983040 232480 750560 24% centos10:/dev/cs/root 17756160 1716768 16039392 10% |
[7] | 仮想マシンのディスクをマウントする。 |
[root@dlp ~]# guestmount -d centos10 -i /media [root@dlp ~]# ll /media total 20 dr-xr-xr-x. 2 root root 6 Oct 29 09:00 afs lrwxrwxrwx. 1 root root 7 Oct 29 09:00 bin -> usr/bin dr-xr-xr-x. 5 root root 4096 Jan 17 09:06 boot drwxr-xr-x. 2 root root 6 Jan 17 09:03 dev drwxr-xr-x. 105 root root 8192 Jan 17 09:10 etc drwxr-xr-x. 3 root root 18 Jan 17 09:07 home ..... ..... |
[8] | 仮想マシンの状態を表示する。 |
[root@dlp ~]# virt-top virt-top 10:05:51 - x86_64 8/8CPU 2399MHz 15727MB 3 domains, 1 active, 1 running, 0 sleeping, 0 paused, 2 inactive D:0 O:0 X:0 CPU: 0.1% Mem: 4096 MB (4096 MB by guests) ID S RDRQ WRRQ RXBY TXBY %CPU %MEM TIME NAME 12 R 2 1 104 0 0.1 26.0 0:21.47 centos10 - (Win2k25) - (debian-12) |
Sponsored Link |
|