Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

KVM Project (3) Storage

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

KVM storage mode is based on file system storage

Dir: storage in directory format

Fs: disk partition storage

Neyfs: network shared file storage

Device-based storage

Disk: physical hard disk storage

Iscsi:iSCSITarget back-end storage

Logical: storage of logical volumes

Virtual disk types supported by KVM

Raw this is not a true disk format, but represents the original image used by the virtual machine. It does not store metadata, so it can be used as a candidate to ensure virtual machine compatibility. Advanced features such as snapshots and compression are not supported. The format is simple but easy to convert to other formats. Need support for file system to use sparse filecow: copy-on-write format. Flash in the pan qcow: QEMU early copy-on-write format qcow2 allocates disk space on demand Regardless of whether the file system supports snapshot support zlib disk compression support AES encrypted vmdk VMware environment the default disk format vhd\ vhdx Microsoft default file format using qemu-imgg management virtual disk qemu-img is a feature mandatory disk mirror management tool check check integrity create Create a mirror commit submission update the compare compare convert conversion info get information snopshot snapshot management resize resize for example: create a piece of raw format 1g Size virtual disk qemu-img create t1.img 1g / / default disk will be stored in the current directory to create a qcow2 format 10g virtual disk qemu-img create t2.img-f qcow2 10g view the specific information of the t2.img virtual disk qemu-img info t2.img detect the running status of the t1.img disk qemu-img check t1.img resize the oa-disk.qcow2 virtual disk Add 5 g qemu-img resize oa-disk.qcow2 + 5G / / Note: after disk expansion, the file system needs to be created at the operating system level of the virtual machine. Create a snapshot for oa-disk.qcow2 qemu-img snapshot-a S1 oa-disk.qcow2 view the snapshot just created qemu-img snapshot-l oa-disk.qcow2 rollback snapshot qemu-img snapshot-a S1 oa-disk.qcow2

When we create these virtual disk files, we can add them to the virtual machine, which is called a disk in the virtual machine.

Use a specific example to demonstrate: qemu-img create-f qcow2 vm1-disk1.qcow2 10G virt-install\-- name=vm1\-- disk path=/tmp/vm1-disk1.qcow2\ / / specify the disk file path to be installed-- vcpus=1-- ram=1024\ / / set the virtual memory size-- cdrom=/tmp/CentOS-7-x86_64-. DVD-1708.iso\ / / specify that the startup file can also be-- location / tmp/CentOS-7-x86_64-DVD-1708.iso-- network network=default\-- graphics vnc Listen=0.0.0.0\-os-type=linux\-os-variant=Centos7.0

Backup differential virtual hard disk

In a real production environment, you can use a backing_file base image as a parent image, and then let multiple virtual machines use the same parent image, so you only need to provide a basic image for the virtual machine.

For parent images, it can be in raw or qcow2 file format, but qcow2 must be used for virtual machines that use the parent image

Prepare the template

Qemu-img create-f qcow2\ >-o backing_file=vm1-disk1.qcow2\ / / disk image creates a virtual machine virt-install for the operating system image > oa-disk.qcow2 / / Associate the basic disk with the parent disk image-- import\ >-- name=oa\ >-- vcpus=1\ >-- ram=1024\ >-- disk path=/tmp/oa-disk.qcow2\ >-- network network=default\ >-- graphics vnc,listen=0.0.0.0

Note that when the virtual machine is created with the specified disk, the virtual machine disk file belongs to the master group and becomes qemu

If we remove or change the parent mirror disk (base image) at this time, the virtual machine cannot start.

Storage Pool:

Basic concepts of storage pools

Libvirt can manage storage uniformly and simplify operation in the form of storage pool.

Storage pools and volumes are not required for virtual machine operations

For example, let's create a directory-based storage pool mkdir / guest_images/ / create directory chown root:root / guest_images/ change directory subordinate group chmod / guest_images/ change permissions virsh pool-define-as guest_images dir-- target "/ guest_images" / / create a partition-based storage pool first create a new disk partition Then use the virsh command to create a storage pool virsh pool-define-as guest_images2_fs-- source-dev "/ dev/sdb1"-- target "/ guest_test (mount point)" virsh pool-start guest_images2_fs / / start a storage pool to create a disk-based storage pool

Add a new disk and change the disk format to gpt format

Prepare the xml file

Guest_images3_fs / dev save exit virsh pool-define / tmp/guest_images_disk.xml / / create a storage pool using the xml file virsh pool-start guest_images3_fs: start a storage pool create an iscsi-based storage pool install the target service on the iscsi Target server And configure / backstores/block > create block1 dev=/dev/sdb1 / / partition based on disk / backstores/fileio > create fikeio1 / tmp/foo1.img 50m / / partition based on file / iscsi > create iqn.2019-02.org.linuxplus.srv1:tomtest / / create target/iscsi/iqn.20...est/tpg1/luns > create / backstores/block/block1 / / create LUNScreate / backstores/fileio/fikeio1create iqn.1994-05.com.redhat:tomkvm1 / / create acl in iscsi Client configure iscsiadm-- mode discovery-- type sendtargets-- portal 192.168.153.8iscsiadm-D2-m node-- login Note: change the information in the iscsi client / etc/iscsi/initiatorname.iscsi file to the corresponding iqn information InitiatorName=iqn.1994-05.com.redhat:tomkvm1

Storage Volum

* * vol-create-as default test1.qcow2 1G-- format qcow2 creates a storage volume called test1.qcow2 in the default directory

Management of storage volumes

In virsh interactive mode

Delete:

Vol-delete lv-name vg-name

Vol-delete test1.qcow2 default

Divide the disk directly into logical volumes

Attach-disk

Add a new disk device through parameters

Virsh attach-disk-domain VM1-source=/vm/t1.img-target=vdb-cache=none

First create a virtual disk for the virtual machine

There are three ways to create virtual disks:

You can use the dd command:

Qemu-img tool to do it.

Qemu-img create-f qcow2 test00.qcow2 2g

The third way:

Virsh vol-create-as vm test00.qocw2 2g-- format qcow2

Create a xml file * *

Virsh # attach-device vm1 / tmp/disk.xml-- persistent

The second way to add

Virsh# attach-disk vm1 / tmp/test00.qcow2-- target=vdc

In fact, I personally understand that the storage pool is the directory where the virtual disk is stored, and the storage volume is the virtual disk file under the directory.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report