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扩展中脚本的运行机制 ...
随机推荐
- 浅谈 Socket.D 与响应式编程
一.Socket.D 的主要特性 首先,Scoket.D 是高效一个二进制的网络通讯协议(官方我讲法是:基于事件和语义消息流的网络应用协议),能够满足很多场景下使用.其次,Scoket.D 是温和的响 ...
- 在蓝图中使用flask-restful
flask-restful中的Api如果传递整个app对象,那么就是整个flask应用都被包装成restful. 但是,你可以只针对某个蓝图(django中的子应用)来进行包装,这样就只有某个蓝图才会 ...
- selenium之内联框架和多窗口切换
内联框架frame frame是一种内联框架,用于在html里面内部嵌入子页面(完整的html),对于这种元素,内部子页面的内容selenium无法直接控制,必须通过 switch_to跳转到对应的f ...
- CSS3学习笔记-字体属性
在CSS3中,可以使用字体属性来控制网页中文本的样式和排版.以下是常用的字体属性: font-family 该属性用于指定网页中的文本所使用的字体.我们可以通过使用通用的字体名称,或者直接使用字体名称 ...
- 解决 cv2.destroyAllWindows() 无效问题
方法一 示例代码: import cv2 import numpy as npimg = np.zeros((512,512),np.uint8)#生成一个空灰度图像 cv2.line(img,(0, ...
- tmux 增加历史回滚缓冲区 buffer
tmux 默认回滚 2000 行,如果要查看更多记录(比如编译报错)可以在.tmux.conf文件中增加一行 set -g history-limit 5000 重启 tmux session 生效
- JavaImprove--Lesson04--LocalDateTime,ZoneId,Instant,DateTimeFormatter
一.LocalDateTime LocalDateTime是JDK8的新时间特性,它解决了Date类和Calender类的很多不足,如使用不方便,线程不安全,以及获取时间戳只能拿到毫秒而不能拿到纳秒等 ...
- Spring Boot 应用部署流程
在本机操作,执行以下步骤启动项目 1.从Github上下载源码 git clone https://github.com/ChinaSilence/any-video.git 2.在数据库中建库,建表 ...
- 一文带你掌握OBS的两种常见的鉴权方式
摘要:本文就将带您了解OBS的两种常见的鉴权方式--Header携带签名和URL携带签名. OBS提供了REST(Representational State Transfer)风格API,支持您通过 ...
- 为了减少代码复杂度,我将if-else升级为面向状态编程
摘要:面向过程设计和面向对象设计的主要区别是:是否在业务逻辑层使用冗长的if else判断. 本文分享自华为云社区<从面向if-else编程升级为面向状态编程,减少代码复杂度>,作者:br ...