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扩展中脚本的运行机制 ...
随机推荐
- zookeeper JavaApi 修改节点
*修改数据 * 1.修改数据 * 2.根据版本修改 * * * */ @Test public void testSet() throws Exception{ Stat stat = new Sta ...
- Activity发送信息给Fragment
在MainActivity中设置发送的信息,在fragment中接收, @Override public void onClick(View view) { switch (view.getId()) ...
- 基于winform(C#)的飞鸟小游戏
本项目是一款基于C# (winform)版本的飞鸟小游戏,是一款益智类游戏 其效果如下图所示 如上图所示为飞鸟游戏的初始化界面: 可以看到游戏包含了四个功能: 启动 注册 登陆 排行榜 启动:是用于开 ...
- 一个WPF版的Layui前端UI库
前言 相信做.NET后端开发的很多小伙伴都用过Layui前端UI组件库,今天我们分享一个WPF版的Layui前端UI样式库:Layui-WPF. WPF介绍 WPF 是一个强大的桌面应用程序框架,用于 ...
- CTFHub XSS 过滤关键词 WriteUp
前文链接:DOM反射xss 这次直接浏览器输入payload,发现 script 被过滤掉了 </textarea>'"><script src=http://xss ...
- JavaFx之模态窗口(二十六)
JavaFx之模态窗口(二十六) 模态窗口:在场景A打开场景B,则A场景无法选择和操作,只能操作B 设置方式,在场景B初始化时设置 stage.initModality(Modality.APPLIC ...
- 完蛋,我被挖矿木马包围了|使用 TLS 连接 Docker
事故还原 近日,白泽在使用 docker 的时候,开放了防火墙的端口,以 SSH 方式访问远程服务器的 docker 守护进程(无需使用密钥即可建立连接),随后竟遭到了挖矿木马的攻击,好一顿折腾之后, ...
- [LitCTF 2023]1zjs
打开环境: 一个魔方♂ 习惯性打开 F12,之后发现有个./dist/index.umd.js Ctrl u 打开 把这个蓝色的点开 0.o? 这里眼神好的话就能看到有个" /f@k3f1a ...
- Next.js 开发指南 路由篇 | 动态路由、路由组、平行路由和拦截路由
前言 实际项目开发的时候,有的路由场景会比较复杂,比如数据库里的文章有很多,我们不可能一一去定义路由,此时该怎么办?组织代码的时候,有的路由是用于移动端,有的路由是用于 PC 端,该如何组织?如何有条 ...
- Java日期时间处理详解
Java中SimpleDateFormat.LocalDateTime和DateTimeFormatter的区别及使用 在Java的世界里,处理日期和时间是常见的任务.尤其在Java 8之前,Simp ...