Debian 12 bookworm
Sponsored Link

KVM : Management tools for VM2023/06/20

 
Install useful tools for virtual machine management.
[1] Install required packages.
root@dlp:~#
apt -y install libguestfs-tools
[2] Get official OS image and Create a Virtual Machine.
( If you'd like to create VM from OS installation, refer to here of [1] )
# display available OS template

root@dlp:~#
virt-builder -l

.....
.....
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                x86_64     Debian 10 (buster)
debian-11                x86_64     Debian 11 (bullseye)
debian-12                x86_64     Debian 12 (bookworm)
.....
.....

# create an image of Debian 12

root@dlp:~#
virt-builder debian-12 --format qcow2 --size 10G -o /var/kvm/images/debian-12.qcow2 --root-password password:myrootpassword

[   9.2] Downloading: http://builder.libguestfs.org/debian-12.xz
[  67.6] Planning how to build this image
[  67.6] Uncompressing
[  71.0] Resizing (using virt-resize) to expand the disk to 10.0G
[  90.1] Opening the new disk
[  93.1] Setting a random seed
[  93.2] Setting passwords
[  93.8] 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%)

# to configure VM with the image above, run virt-install
root@dlp:~# virt-install \
--name debian-12 \
--ram 4096 \
--disk path=/var/kvm/images/debian-12.qcow2 \
--vcpus 2 \
--os-variant debian11 \
--network bridge=br0 \
--graphics none \
--noautoconsole \
--boot hd \
--noreboot \
--import 

Starting install...
Creating domain... 
Domain creation completed.
You can restart your domain by running:
  virsh --connect qemu:///system start debian-12
[3] [ls] a directory in a virtual machine.
root@dlp:~#
virt-ls -l -d debian12 /root

total 24
drwx------  3 0 0 4096 Jun 19 23:57 .
drwxr-xr-x 18 0 0 4096 Jun 19 23:52 ..
-rw-------  1 0 0   16 Jun 19 23:57 .bash_history
-rw-r--r--  1 0 0  571 Apr 10  2021 .bashrc
-rw-r--r--  1 0 0  161 Jul  9  2019 .profile
drwx------  2 0 0 4096 Jun 19 23:52 .ssh
[4] [cat] a file in a virtual machine.
root@dlp:~#
virt-cat -d debian12 /etc/passwd

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
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
.....
.....
[5] Edit a file in a virtual machine.
root@dlp:~#
virt-edit -d debian12 /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=8e8d5f88-16cd-473a-88de-1900abeff03c /boot ext2 defaults  0       2
/dev/mapper/debian--vg-swap_1 none  swap    sw              0       0
/dev/sr0        /media/cdrom0   udf,iso9660 user,noauto     0       0
[6] Display disk usage in a virtual machine.
root@dlp:~#
virt-df -d debian12

Filesystem                           1K-blocks       Used  Available  Use%
debian12:/dev/sda1                      465124      58923     381267   13%
debian12:/dev/debian-vg/root          18982140    1010616   16981932    6%
[7] Mount disk image of a virtual machine.
root@dlp:~#
guestmount -d debian12 -i /mnt

root@dlp:~#
ll /mnt

total 73
lrwxrwxrwx  1 root root     7 Jun 19 18:51 bin -> usr/bin
drwxr-xr-x  4 root root  1024 Jun 19 18:55 boot
drwxr-xr-x  4 root root  4096 Jun 19 18:51 dev
drwxr-xr-x 67 root root  4096 Jun 19 18:56 etc
drwxr-xr-x  3 root root  4096 Jun 19 18:55 home
.....
.....
Matched Content