KVM虚拟化笔记(十一)------kvm之Linux虚拟机在线扩展磁盘

简介:

  kvm虚拟机也支持在线扩展磁盘功能,在线扩展有特定的使用环境,主要用于不能随便停用的生产环境中,本文以hadoop为例具体步骤如下:

1,查看现有磁盘

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@KVM  test ] # virsh list --all
  Id    Name                           State
----------------------------------------------------
  1     win7                           running
  17    hadoop1                        running
  18    hadoop4                        running
  20    hadoop2                        running
  -     hadoop3                        shut off
[root@KVM  test ] # virsh domblklist hadoop1
Target     Source
------------------------------------------------
vda         /images/test/hadoop1 .qcow2
hdc        -

 

2,创建一块qcow2虚拟磁盘

1
2
3
[root@KVM  test ] # qemu-img create -f qcow2 hadoop1_add01.qcow2 5G
Formatting  'hadoop1_add01.qcow2' fmt =qcow2 size=5368709120 encryption=off cluster_size=65536 
[root@KVM  test ] #

wKioL1a0YSaS9zkQAADshmPf3WA450.png3,在线添加这台qcow2虚拟磁盘

1
2
3
4
5
6
7
8
[root@KVM  test ] # virsh attach-disk hadoop1 /images/test/hadoop1_add01.qcow2 vdb --cache=none --subdriver=qcow2            
Disk attached successfully
[root@KVM  test ] # virsh domblklist hadoop1                       
Target     Source
------------------------------------------------
vda         /images/test/hadoop1 .qcow2
vdb         /images/test/hadoop1_add01 .qcow2
hdc        -

wKioL1a0YizibtGZAABeCpmwwdk206.png4,进入虚拟机查看,如下图:

wKioL1a0Yn2hSA2zAABSB9swk_Q757.png

5,然后进入系统里边划分区

fdisk /dev/vdb

wKiom1a0Y4biAtfzAAAaEIuPcKI184.png

wKiom1a0Y06AqiANAABACXkO1jM598.png

wKioL1a0Y6HzlILkAAAo0LWA1Yw548.png

6,划分逻辑卷LVM省略,前边的可以参考。


7,修改虚拟机配置文件,把新增的磁盘配置写到虚拟机磁盘配置

 (1)查看当前虚拟机hadoop1的磁盘配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
[root@KVM  test ] # virsh dumpxml hadoop1
<domain  type = 'qemu'  id = '17' >
   <name>hadoop1< /name >
   <uuid>919f0921-0736-ad5b-780b-a440de2f35cb< /uuid >
   <memory unit= 'KiB' >524288< /memory >
   <currentMemory unit= 'KiB' >524288< /currentMemory >
   <vcpu placement= 'static' >1< /vcpu >
   <os>
     < type  arch= 'x86_64'  machine= 'rhel6.6.0' >hvm< /type >
     <boot dev= 'hd' />
   < /os >
   <features>
     <acpi/>
     <apic/>
     <pae/>
   < /features >
   <clock offset= 'utc' />
   <on_poweroff>destroy< /on_poweroff >
   <on_reboot>restart< /on_reboot >
   <on_crash>restart< /on_crash >
   <devices>
     <emulator> /usr/libexec/qemu-kvm < /emulator >
     <disk  type = 'file'  device= 'disk' >
       <driver name= 'qemu'  type = 'qcow2'  cache= 'none' />
       < source  file = '/images/test/hadoop1.qcow2' />
       <target dev= 'vda'  bus= 'virtio' />
       < alias  name= 'virtio-disk0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x05'  function = '0x0' />
     < /disk >
     <disk  type = 'file'  device= 'disk' >
       <driver name= 'qemu'  type = 'qcow2'  cache= 'none' />
       < source  file = '/images/test/hadoop1_add01.qcow2' />
       <target dev= 'vdb'  bus= 'virtio' />
       < alias  name= 'virtio-disk1' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x07'  function = '0x0' />
     < /disk >
     <disk  type = 'block'  device= 'cdrom' >
       <driver name= 'qemu'  type = 'raw' />
       <target dev= 'hdc'  bus= 'ide' />
       < readonly />
       < alias  name= 'ide0-1-0' />
       <address  type = 'drive'  controller= '0'  bus= '1'  target= '0'  unit= '0' />
     < /disk >
     <controller  type = 'usb'  index= '0'  model= 'ich9-ehci1' >
       < alias  name= 'usb0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x7' />
     < /controller >
     <controller  type = 'usb'  index= '0'  model= 'ich9-uhci1' >
       < alias  name= 'usb0' />
       <master startport= '0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x0'  multifunction= 'on' />
     < /controller >
     <controller  type = 'usb'  index= '0'  model= 'ich9-uhci2' >
       < alias  name= 'usb0' />
       <master startport= '2' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x1' />
     < /controller >
     <controller  type = 'usb'  index= '0'  model= 'ich9-uhci3' >
       < alias  name= 'usb0' />
       <master startport= '4' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x2' />
     < /controller >
     <controller  type = 'ide'  index= '0' >
       < alias  name= 'ide0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x01'  function = '0x1' />
     < /controller >
     <interface  type = 'bridge' >
       <mac address= '52:54:00:b6:bf:1f' />
       < source  bridge= 'br0' />
       <target dev= 'vnet1' />
       <model  type = 'virtio' />
       < alias  name= 'net0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x03'  function = '0x0' />
     < /interface >
     <serial  type = 'pty' >
       < source  path= '/dev/pts/2' />
       <target port= '0' />
       < alias  name= 'serial0' />
     < /serial >
     <console  type = 'pty'  tty = '/dev/pts/2' >
       < source  path= '/dev/pts/2' />
       <target  type = 'serial'  port= '0' />
       < alias  name= 'serial0' />
     < /console >
     <input  type = 'mouse'  bus= 'ps2' />
     <graphics  type = 'vnc'  port= '5911'  autoport= 'no'  listen= '0.0.0.0' >
       <listen  type = 'address'  address= '0.0.0.0' />
     < /graphics >
     <video>
       <model  type = 'cirrus'  vram= '9216'  heads= '1' />
       < alias  name= 'video0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x02'  function = '0x0' />
     < /video >
     <memballoon model= 'virtio' >
       < alias  name= 'balloon0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x06'  function = '0x0' />
     < /memballoon >
   < /devices >
< /domain >


 (2)把以下配置添加到/etc/libvirt/qemu/hadoop1.xml配置文件中

1
2
3
4
5
6
7
  <disk  type = 'file'  device= 'disk' >
       <driver name= 'qemu'  type = 'qcow2'  cache= 'none' />
       < source  file = '/images/test/hadoop1_add01.qcow2' />
       <target dev= 'vdb'  bus= 'virtio' />
       < alias  name= 'virtio-disk1' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x07'  function = '0x0' />
     < /disk >


wKiom1a0Z2aD00LdAAGB6Cp_t9A795.pngwKioL1a0aBjT1aLqAAFy6S32LMg936.png




本文转自 lqbyz 51CTO博客,原文链接:http://blog.51cto.com/liqingbiao/1741252

相关文章
|
1月前
|
Linux 网络安全 数据安全/隐私保护
如何在 VM 虚拟机中安装 CentOS Linux 9 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 CentOS Linux 9 操作系统保姆级教程(附链接)
161 0
|
1月前
|
安全 Linux 网络安全
如何在 VM 虚拟机中安装 Red Hat Enterprise Linux 9.3 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 Red Hat Enterprise Linux 9.3 操作系统保姆级教程(附链接)
89 0
|
3月前
|
Linux 网络安全
物理机与虚拟机(linux)不能ping 通的原因之一
有时候,我们需要使用SSH来操作虚拟机的linux,这时候可能存在需要固定linux的固定ip,然后发现固定linuxIP后,window和linux无法ping通,而且linux无法上网的情况,这时候我们需要将linux的虚拟网卡设置为桥接方式 NAT模式和桥接模式的区别:NAT模式和桥接模式的区别
74 1
|
3月前
|
Linux 虚拟化 数据安全/隐私保护
【Linux】VMware安装虚拟机- Windows + Linux
【1月更文挑战第20天】【Linux】VMware安装虚拟机- Windows + Linux
|
3月前
|
Linux Windows
FinalShell连接Linux虚拟机报错java.net.ConnectException: Connection timed out: connect(亲测有效)
FinalShell连接Linux虚拟机报错java.net.ConnectException: Connection timed out: connect(亲测有效)
163 0
|
1天前
|
程序员 Linux KVM
【qemu虚拟化】将img镜像文件转换为VMware虚拟机
QEMU是一个开源的硬件虚拟化器,能在多种平台如x86、ARM、PowerPC上运行,支持虚拟化不同体系结构的操作系统。它具有硬件仿真、虚拟化支持、磁盘和网络仿真、快照回滚及可扩展性等特点。要使用QEMU,首先从[官网](https://www.qemu.org/download/)下载,然后通过命令行运行进行转换。转换后的vMDK文件可在VMware中导入,创建新的虚拟机进行使用。
32 1
【qemu虚拟化】将img镜像文件转换为VMware虚拟机
|
14天前
|
Linux 虚拟化
linux 虚拟机扩容--直接扩容到根目录
linux 虚拟机扩容--直接扩容到根目录
26 1
|
14天前
|
Linux Shell 虚拟化
linux 部署docker容器虚拟化平台(二)--------docker 镜像制作方法
linux 部署docker容器虚拟化平台(二)--------docker 镜像制作方法
25 0
|
1月前
|
关系型数据库 MySQL 数据库
虚拟机Linux-Centos系统网络配置常用命令+Docker 的常用命令
虚拟机Linux-Centos系统网络配置常用命令+Docker 的常用命令
40 0
|
1月前
|
Linux 虚拟化 数据安全/隐私保护
使用VMware安装linux虚拟机
使用VMware安装linux虚拟机
使用VMware安装linux虚拟机