[LINUX] LPIC304 virtualization memo


I took the Lpic304 exam, so I made a note about server virtualization.

What is server virtualization?


Operate multiple virtual servers (virtual servers) on one physical server

Software for virtualizing servers is called virtualization software, VMM, virtual machine monitor, etc.

Virtualization techniques

Types of virtualization-paravirtualized and fully virtualized-

Hypervisor type Xen and KVM

Features of Xen


Manage and operate KVM

Basically, use the virsh command via libvirt (described later). However, there are other commands that can be operated.

QEMU operation

KVM storage

Storage backend

There are two types: block devices and regular files. For block devices, use those on NFS or LUN

What is a block device? https://xtech.nikkei.com/it/article/Keyword/20081023/317625/

file format

・ Raw

(*) Sparse file ... Instead of allocating the data for the file size to the disk, it is an apparent file that has only the metadata (file information). Therefore, it is possible to create a file that exceeds the disk capacity.

・ Qcow2 qcow2 is an abbreviation of "QEMU Copy On Write version2", which has the same function as a sparse file for an environment (Windows, etc.) where a sparse file cannot be used originally. It has a feature that it has metadata in the file and can collect snapshots.

The raw format does not support the snapshot function. However, by converting the file format of the virtual disk image to qcow2 with qemu-img convert, you can use the snapshot function without recreating the virtual machine.

KVM networking

tap device and virtual bridge

Method https://qiita.com/hot_study_man/items/52af652d7b20a8a998b6

What is libvirt


Supported VMs

Xen Hypervisor	http://www.xen.org
Qemu Machine Emulator	http://www.qemu.org
KVM(Kernel-based Virtual Machine)	http://www.linux-kvm.org
LXC(LinuX Containers)	http://lxc.sourceforge.net
UML(User Mode Linux)	http://user-mode-linux.sourceforge.net
OpenVZ	http://www.openvz.org
VMWare ESX	http://www.vmware.com

wikipedia https://ja.wikipedia.org/wiki/Libvirt


libvirtd daemon

libvirtd allows remote as well as local access. You can also manage VMs remotely with libvirtd.

Various commands of KVM


After creating a virtual disk image with the qemu-img command, install the OS on the disk image using the qemu-kvm command and start the virtual machine.

Example) Set the virtual disk image "vm1.img" as a hard disk and start the virtual machine using the user mode network. qemu-kvm -hda vm1.img -net nic -net user

OS installation Example) Set the virtual disk image "vm1.img" as a hard disk and perform OS installation using the ISO file "centos.iso".

qemu-kvm -hda vm1.img -cdrom centos.iso

Example) Set the virtual disk image "vm1.img" as a hard disk and start the virtual machine directly. qemu-kvm -hda vm1.img -kernel /boot/bzImage -initrd /boot/initramfs.img -append "root=/dev/hda"

When booting directly from the Linux kernel, you need to specify the root file system in the -append option.

The qemu-kvm command is for the host OS It can also be booted by loading the Linux kernel and initial ramdisk directly into the virtual machine. Three options are available: "-kernel", "-initrd", and "-append"

qemu-img command


qemu-img create qemu-img convert qemu-img resize qemu-img info qemu-img snapshot

1) qemu-Create a virtual disk image with the img command
Example)Format:qcow2, disk capacity:2GB, file name "centos".Create a disk image with "img"

qemu-img create -f qcow2 centos.img 2G
qemu-img create1 -f raw2 /images/sles11/hda3 8G4

2)qemu-Install the guest OS in the prepared virtual disk image with the kvm command.
Example)Virtual disk image "centos.With "img" as the hard disk, memory 1024MB, OS installation medium "centos".Start the virtual machine by specifying "iso"

qemu-kvm -hda centos.img -cdrom centos.iso -boot once=d -m 1024

Convert raw to qcow2

qemu-img convert raw.img -O qcow2 QC2.img


qemu-img resize hdd.img +5G

qemu-img info


qemu-img snapshot -l hdd.img

qemu-kvm command


After creating the image, use qemu-kvm to configure the virtual machine and boot the installation system.

qemu-kvm -name "sles11"1 -M pc-0.122 -m 7683 \
-smp 24 -boot d5 \
-drive file=/images/sles11/hda,if=virtio,index=0,media=disk,format=raw6 \
-drive file=/isos/SLES-11-SP1-DVD-x86_64-GM-DVD1.iso,index=1,media=cdrom7 \
-net nic,model=virtio,macaddr=52:54:00:05:11:118 \
-vga cirrus9 -balloon virtio10

System boot after this is done

After installing the guest operating system, you no longer need to specify the CD-ROM device and you can easily boot the system:

qemu-kvm -name "sles11" -M pc-0.12 -m 768
-smp 2 -boot c
-drive file=/images/sles11/hda,if=virtio,index=0,media=disk,format=raw
-net nic,model=virtio,macaddr=52:54:00:05:11:11
-vga cirrus -balloon virtio


The device specified in the qemu-kvm command is emulated by QEMU as an IDE device "ideN-hdN" or "ideN-cdN". The correspondence is as follows: Block device: qemu-kvm command option specification ide0-hd0/ide0-cd0 : -hda,| -drive |index=0 ide0-hd1/ide0-cd1 : -hdb,|-drive| index=1 ide1-hd0/ide1-cd0 : -hdc,|-drive| index=2, | -cdrom ide1-hd1/ide1-cd1 : -hdd,|-drive| index=3

How to get a snapshot with KVM

Create Example) Create a snapshot of the virtual machine "Fedora" with the name "snapshot1"

virsh snapshot-create-as Fedora snapshot1

restore Example) Restore the virtual machine "Fedora" to the snapshot "snapshot1"

virsh snapshot-revert Fedora snapshot1

・ Create a snapshot Example) Create a snapshot

(qemu) savevm

・ Snapshot restoration Example) Restore to ID3 of snapshot

(qemu) loadvm 3

・ Create a snapshot Example) Create a snapshot of the virtual disk image "cent6.img" with the name "snapshot2".

qemu-img snapshot -c snapshot2 cent6.img

・ Snapshot restoration Example) Restore the virtual disk image "cent6.img" to the snapshot "snapshot2"

qemu-img snapshot -a snapshot2 cent6.img

Recommended Posts

LPIC304 virtualization memo
LPIC201 learning memo
LPIC101 study memo
LPIC Lv1-101 (Ver5.0) memo
Linux command [ldconfig] LPIC learning memo
gzip memo
Raspberry-pi memo
Pandas memo
HackerRank memo
Python memo
python memo
graphene memo
Flask memo
pyenv memo
Matplotlib memo
pytest memo
sed memo
Python memo
Install Memo
BeautifulSoup4 memo
networkx memo
python memo
tomcat memo
command memo
Generator memo.
LPIC304 test preparation 330.1 Virtualization concept and theory
psycopg2 memo
Python memo
SSH memo
Command memo
Memo: rtl8812
pandas memo
Shell memo
Python memo
Pycharm memo
Python memo