KVM 核心功能:磁盘虚拟化
1 磁盘虚拟化简介
- 本地存储虚拟机镜像文件。
- host 上物理磁盘或磁盘分区。
- LVM(Logical Volume Management),逻辑分区。
- NFS(Network File System),网络文件系统。
- GFS(Gluster File System),分布式文件系统。
2 磁盘虚拟化配置
2.1 本地存储镜像
[lianhua@host ~]$ time qemu-img create -f raw lianhua_demo.img -o preallocation=off 10G
Formatting 'lianhua_demo.img', fmt=raw size=10737418240 preallocation=off real 0m0.040s
user 0m0.015s
sys 0m0.015s [lianhua@host ~]$ qemu-img info lianhua_demo.img
image: lianhua_demo.img
file format: raw
virtual size: 10G (10737418240 bytes)
disk size: 0
[lianhua@host ~]$ time qemu-img create -f raw lianhua_demo_full.img -o preallocation=full 10G
Formatting 'lianhua_demo_on.img', fmt=raw size=10737418240 preallocation=full real 0m22.955s
user 0m0.013s
sys 0m8.930s
[lianhua@host ~]$ time qemu-img create -f raw lianhua_demo_falloc.img -o preallocation=falloc 10G
Formatting 'lianhua_demo_falloc.img', fmt=raw size=10737418240 preallocation=falloc real 0m8.256s
user 0m0.008s
sys 0m8.114s [lianhua@host ~]$ du -h lianhua_demo*.img
11G lianhua_demo_falloc.img
0 lianhua_demo.img
11G lianhua_demo_full.img
[lianhua@host ~]$ /usr/libexec/qemu-kvm -m 1024 -smp 2 -hda lianhua_demo_falloc.img -monitor stdio
WARNING: Image format was not specified for 'lianhua_demo_falloc.img' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
QEMU 2.6.0 monitor - type 'help' for more information
(qemu) VNC server running on '::1;5900' (qemu) info pci
Bus 0, device 0, function 0:
Host bridge: PCI device 8086:1237
id ""
Bus 0, device 1, function 1:
IDE controller: PCI device 8086:7010
BAR4: I/O at 0xc040 [0xc04f].
id ""
Bus 0, device 1, function 3:
Bridge: PCI device 8086:7113
IRQ 9.
id ""
Bus 0, device 3, function 0:
Ethernet controller: PCI device 8086:100e
IRQ 11.
BAR0: 32 bit memory at 0xfebc0000 [0xfebdffff].
BAR1: I/O at 0xc000 [0xc03f].
BAR6: 32 bit memory at 0xffffffffffffffff [0x0003fffe].
id ""
2.2 LVM 逻辑分区
[root@host ~]# pvdisplay
--- Physical volume ---
PV Name /dev/loop2
VG Name cinder-volumes
PV Size 602.34 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 154199
Free PE 146519
Allocated PE 7680
PV UUID pTkQ5Z-zNdc-LRrn-qWAX-13D6-bhbG-DdcGFD [root@host ~]# vgdisplay
--- Volume group ---
VG Name cinder-volumes
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1447
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 602.34 GiB
PE Size 4.00 MiB
Total PE 154199
Alloc PE / Size 7680 / 30.00 GiB
Free PE / Size 146519 / 572.34 GiB
VG UUID Mrrh1r-qKQw-bCgW-0WXi-d5Bd-OiVV-cTBrg5 [root@host ~]# lvdisplay
--- Logical volume ---
LV Path /dev/cinder-volumes/volume-c34555f0-fd26-42fe-a3b2-86098b590be2
LV Name volume-c34555f0-fd26-42fe-a3b2-86098b590be2
VG Name cinder-volumes
LV UUID n81Af6-cWEe-LvAm-wjA3-vgKD-RxgV-qMtIq6
LV Write Access read/write
LV Creation host, time host.localdomain, 2020-08-02 00:47:30 +0800
LV Status available
# open 1
LV Size 26.00 GiB
Current LE 6656
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
(看这里详细了解 LVM)
[root@host ~]# openstack volume list
+--------------------------------------+--------------------------------------------+--------+------+---------------------------------------------+
| ID | Display Name | Status | Size | Attached to |
+--------------------------------------+--------------------------------------------+--------+------+---------------------------------------------+
| c34555f0-fd26-42fe-a3b2-86098b590be2 | lianhua-vm1-vol | in-use | 26 | Attached to lianhua-vm1-vol on /dev/vdb |
+--------------------------------------+--------------------------------------------+--------+------+---------------------------------------------+
[root@lianhua-vm1:/home/robot]
# fdisk -l | grep vdb
Disk /dev/vdb: 26 GiB, 27917287424 bytes, 54525952 sectors [root@lianhua-vm1:/home/robot]
# lspci
...
00:0b.0 SCSI storage controller: Red Hat, Inc. Virtio block device [root@lianhua-vm1:/home/robot]
# lspci -s 00:0b.0 -vvv
00:0b.0 SCSI storage controller: Red Hat, Inc. Virtio block device
Subsystem: Red Hat, Inc. Device 0002
Physical Slot: 11
Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
Latency: 0
Interrupt: pin A routed to IRQ 10
Region 0: I/O ports at 1000 [size=64]
Region 1: Memory at c0004000 (32-bit, non-prefetchable) [size=4K]
Region 4: Memory at c0000000 (64-bit, prefetchable) [size=16K]
Capabilities: [98] MSI-X: Enable+ Count=2 Masked-
Vector table: BAR=1 offset=00000000
PBA: BAR=1 offset=00000800
Capabilities: [84] Vendor Specific Information: VirtIO: <unknown>
BAR=0 offset=00000000 size=00000000
Capabilities: [70] Vendor Specific Information: VirtIO: Notify
BAR=4 offset=00003000 size=00001000 multiplier=00000004
Capabilities: [60] Vendor Specific Information: VirtIO: DeviceCfg
BAR=4 offset=00002000 size=00001000
Capabilities: [50] Vendor Specific Information: VirtIO: ISR
BAR=4 offset=00001000 size=00001000
Capabilities: [40] Vendor Specific Information: VirtIO: CommonCfg
BAR=4 offset=00000000 size=00001000
Kernel driver in use: virtio-pci
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/disk/by-path/ip-172.18.0.22:3260-iscsi-iqn.2010-10.org.openstack:volume-c34555f0-fd26-42fe-a3b2-86098b590be2-lun-0'/>
<target dev='vdb' bus='virtio'/>
<serial>c34555f0-fd26-42fe-a3b2-86098b590be2</serial>
<address type='pci' domain='0x0000' bus='0x00' slot='0x0b' function='0x0'/>
</disk>
[root@host 2177d777-2a46-4e5b-ac92-ba7ad27e21a3]# /usr/libexec/qemu-kvm -m 1024 -smp 2 -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x6,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive file=/var/lib/nova/instances/2177d777-2a46-4e5b-ac92-ba7ad27e21a3/disk.config,format=raw,if=none,id=drive-ide0-0-0,readonly=on,cache=none -monitor stdio
3 磁盘虚拟化环境部署
- 使用 virtio 半虚拟化方式指定镜像文件实现磁盘虚拟化,虚拟出的磁盘设备名为 vda。
- 使用 virtio 半虚拟化方式指定 volume 实现磁盘虚拟化,虚拟出的磁盘设备名为 vdb。
- 在虚拟机内部使用 LVM 分割磁盘设备 vdb 为 lv volume,并将 volume 指定为文件系统。
- 使用 NFS 方式共享虚拟机的文件系统。
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/var/lib/nova/instances/2177d777-2a46-4e5b-ac92-ba7ad27e21a3/disk'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</disk>
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/disk/by-path/ip-172.18.0.22:3260-iscsi-iqn.2010-10.org.openstack:volume-c34555f0-fd26-42fe-a3b2-86098b590be2-lun-0'/>
<target dev='vdb' bus='virtio'/>
<serial>c34555f0-fd26-42fe-a3b2-86098b590be2</serial>
<address type='pci' domain='0x0000' bus='0x00' slot='0x0b' function='0x0'/>
</disk>
</devices>
[root@host 2177d777-2a46-4e5b-ac92-ba7ad27e21a3]# qemu-img info disk
image: disk
file format: qcow2
virtual size: 40G (42949672960 bytes)
disk size: 1.7G
cluster_size: 65536
backing file: /var/lib/nova/instances/_base/52968ae0bfbfeef835844ee0b97be5e45d382e4c
Format specific information:
compat: 1.1
lazy refcounts: false
refcount bits: 16
corrupt: false
[root@lianhua-vm1:/home/robot]
# fdisk -l | grep vd
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors # 这里 vda 的磁盘容量为 40G
/dev/vda1 * 2048 83886046 83883999 40G 83 Linux
Disk /dev/vdb: 26 GiB, 27917287424 bytes, 54525952 sectors [root@lianhua-vm1:/home/robot]
# lspci | grep block
00:06.0 SCSI storage controller: Red Hat, Inc. Virtio block device
00:0b.0 SCSI storage controller: Red Hat, Inc. Virtio block device
[root@lianhua-vm1:/home/robot]
# pvdisplay
--- Physical volume ---
PV Name /dev/vdb
VG Name lianhua-vm1-vol
PV Size 26.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 6655
Free PE 1405
Allocated PE 5250
PV UUID OqdKmO-PspN-0ZKe-M0l4-0vGD-cY7k-VjZvTJ [root@lianhua-vm1:/home/robot]
# vgdisplay
--- Volume group ---
VG Name lianhua-vm1-vol
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 6
Open LV 6
Max PV 0
Cur PV 1
Act PV 1
VG Size <26.00 GiB
PE Size 4.00 MiB
Total PE 6655
Alloc PE / Size 5250 / <20.51 GiB
Free PE / Size 1405 / <5.49 GiB
VG UUID JcVrao-YnJ7-mRpK-8Rxc-i07i-WVH4-aVgAoD [root@lianhua-vm1:/home/robot]
# lvdisplay
--- Logical volume ---
LV Path /dev/lianhua-vm1-vol/provider_sys
LV Name provider_sys
VG Name lianhua-vm1-vol
LV UUID C6byt7-5cby-h2RT-xcLg-OJU0-Qq1E-27G6jB
LV Write Access read/write
LV Creation host, time lianhua-vm1, 2020-08-02 00:50:11 +0800
LV Status available
# open 1
LV Size <9.77 GiB
Current LE 2500
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0 --- Logical volume ---
LV Path /dev/lianhua-vm1-vol/provider_lianhua
LV Name provider_lianhua
VG Name lianhua-vm1-vol
LV UUID vfeZg8-PKVR-kKxv-yidf-rQqp-A7De-CvXqws
LV Write Access read/write
LV Creation host, time lianhua-vm1, 2020-08-02 00:50:11 +0800
LV Status available
# open 1
LV Size 4.88 GiB
Current LE 1250
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:1 --- Logical volume ---
LV Path /dev/lianhua-vm1-vol/provider_log
LV Name provider_log
VG Name lianhua-vm1-vol
LV UUID mHdD60-QjSy-sRlz-GLmK-CFIM-l42c-QGthXa
LV Write Access read/write
LV Creation host, time lianhua-vm1, 2020-08-02 00:50:12 +0800
LV Status available
# open 1
LV Size 1000.00 MiB
Current LE 250
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:2
[root@lianhua-vm1:/home/robot]
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 7.0G 31G 19% /
/dev/mapper/lianhua-vm1-vol-provider_sys 9.1G 37M 8.6G 1% /mnt/sys
/dev/mapper/lianhua-vm1-vol-provider_lianhua 4.6G 20M 4.3G 1% /mnt/lianhua
/dev/mapper/lianhua-vm1-vol-provider_log 922M 18M 838M 3% /mnt/log
[root@lianhua-vm2:/mnt/log]
# ls
[root@lianhua-vm2:/mnt/log]
# mkdir lianhua
[root@lianhua-vm2:/mnt/log]
# ls
lianhua [root@lianhua-vm1:/mnt/log]
# ls
lianhua
KVM 核心功能:磁盘虚拟化的更多相关文章
- Linux学习-核心编译的前处理与核心功能选择
硬件环境检视与核心功能要求 根据自己的需求来确定编译的选项 保持干净原始码: make mrproper 我们还得要处理一下核心原始码底下的残留文件才行!假设我们是第一次 编译, 但是我们不清楚到底下 ...
- [ kvm ] 学习笔记 3:KVM 基础功能详解
1. 构建 KVM 环境 KVM 从诞生开始就需要硬件虚拟化的支持,KVM 必需的硬件虚拟化扩展分别是:Intel 的虚拟化技术(Intel VT)和 AMD 的 AMD-V 技术.首先处理器(CPU ...
- kvm简介及创建虚拟化安装(1)
kvm虚拟化介绍 一.虚拟化分类 1.虚拟化,是指通过虚拟化技术将一台计算机虚拟为多台逻辑计算机.在一台计算机上同时运行多个逻辑计算机,每个逻辑计算机可运行不同的操作系统,并且应用程序都可以在相互独立 ...
- [ kvm ] 学习笔记 4:KVM 高级功能详解
1. 半虚拟化驱动 1.1 virtio 概述 KVM 是必须使用硬件虚拟化辅助技术(如 Intel VT-x .AMD-V)的 Hypervisor,在CPU 运行效率方面有硬件支持,其效率是比较高 ...
- KVM + LinuxBridge 的网络虚拟化解决方案实践
目录 文章目录 目录 前言 Linux bridge 的基本操作 创建 Bridge 将 veth pair 连上 Bridge 为 Bridge 配置 IP 地址 将物理网卡接口设备挂靠 Bridg ...
- 在 Centos7 的KVM上启用嵌套虚拟化
1.嵌套虚拟化意味着在虚拟机内配置虚拟化环境.换句话说,我们可以说嵌套虚拟化是虚拟机管理程序hypervisor的一个特性,它允许我们通过虚拟化管理程序(宿主机)的硬件加速在虚拟服务器内安装和运行虚拟 ...
- kvm虚拟机扩展磁盘空间
kvm虚拟机磁盘空间扩展与xen虚拟机磁盘空间扩展思路一致.原因在于xen/kvm默认的虚拟机磁盘格式为raw,所以方式可以通用. raw磁盘格式扩展思路如下 (1) 新添加一块raw格式的磁盘加入到 ...
- KVM基本功能管理
一.KVM基础功能管理 1.查看命令帮助 virsh -h 2.查看 KVM 的配置文件存放目录(CENTOS7.0.xml是虚拟系统实例的配置文件) ls /etc/libvirt/qemu ...
- 带连接池的netty客户端核心功能实现剖解
带连接池的netty客户端核心功能实现剖析 带连接池的netty的客户端核心功能实现剖析 本文为原创,转载请注明出处 源码地址: https://github.com/zhangxianwu/ligh ...
- Chrome扩展开发之四——核心功能的实现思路
目录: 0.Chrome扩展开发(Gmail附件管理助手)系列之〇——概述 1.Chrome扩展开发之一——Chrome扩展的文件结构 2.Chrome扩展开发之二——Chrome扩展中脚本的运行机制 ...
随机推荐
- LeetCode1806:还原排列的最少操作步数(置换群 or 模拟)
题意:题目的意思是,给定一个初始状态perm,然后对perm的每个元素按照上述的规则进行变换操作.问:perm经过多少次这种操作能够变回初始的perm. 解题思路:第一种方法就是模拟,一直变换,直到变 ...
- 时间加权平均价格算法(TWAP)和成交量平均算法(VWAP)在量化回测的应用
为什么要引入TWAP和 VWAP? 为了评估策略的资金容量,我们对M.trade模块里买入点和卖出点这两个参数进行了更丰富的扩展,支持了策略能够按更丰富的算法交易价格(WAP)进行撮合. 如果资金是1 ...
- 如何屏蔽各大AI公司爬虫User Agent
罗列各大AI公司Scraper爬虫Crawler使用的User Agent,教您如何在robots.txt里面屏蔽这些爬虫的访问,禁止它们下载您的网站内容以训练 AI 模型,保护数据,降低带宽,防止宕 ...
- [笔记01]---solr
什么是Solr 1.直接使用sql搜索存在的问题 大多数搜索引擎应用都必须具有某种搜索功能 搜索功能往往是巨大的资源消耗 它们由于沉重的数据库加载而拖垮你的应用的性能 所有我们一般在做搜索的时候 会把 ...
- st_geometry、st_transform配置及问题汇总
1.文件配置修改 路径上一定要使用双斜杠 2.使用sde账号登录,执行以下SQL,路径按照实际环境填写. select * from user_libraries; create or replace ...
- 【OpenVINO】 使用 OpenVINO CSharp API 部署 PaddleOCR 项目介绍
前言: 在之前的项目中,我们已经使用 OpenVINOTM CSharp API 部署 PaddleOCR 全系列模型,但随着PaddleOCRv4版本发布以及OpenVINO CSharp AP ...
- Blazor快速开发框架Known-V2.0.0
Known2.0 Known是基于Blazor的企业级快速开发框架,低代码,跨平台,开箱即用,一处代码,多处运行. 官网:http://known.pumantech.com Gitee: https ...
- JavaImprove--Lesson01--枚举类,泛型
一.枚举 认识枚举类 枚举是一种特殊的类 枚举的格式: 修饰符 enmu 枚举类名{ 名称1,名称2: 其它成员 } //枚举类 public enum A { //枚举类的第一列必须是罗列枚举 ...
- Asp .Net Core系列:Exceptionless简介和部署(Windows、Linux、Docker)
目录 一.简介 二.版本 三.运行说明 1.Exceptionless 2.Elasticsearch 3.Exceptionless.UI 四.打包Exceptionless.UI 五.window ...
- 华为云GaussDB城市沙龙活动走进安徽,助力金融行业数字化转型
本文分享自华为云社区<华为云GaussDB城市沙龙活动走进安徽,助力金融行业数字化转型>,作者: GaussDB 数据库 . 近日,华为云GaussDB数据库城市沙龙·安徽站圈层活动顺利举 ...