KVM虚拟化笔记(二)------kvm虚拟机Linux系统安装

简介:

1,在根目录下创建images目录,然后依次创建iso和test。其中ISO目录是存放ISO镜像的,test是存放虚拟机的主机名的,然后把Linux安装镜像的iso文件,上传到iso文件夹里

1
2
[root@KVM ~] # mkdir -p /images/iso
[root@KVM ~] # mkdir -p /images/test
1
2
3
[root@KVM ~] # ll /data/iso/
total 407556
-rw-r--r-- 1 qemu qemu 417333248 Aug  5 09:11 CentOS-6.5-x86_64-minimal.iso

2,安装Linux虚拟主机:

 a)安装raw磁盘格式的虚拟机:

1
[root@KVM images] #virt-install --name hadoop2  --ram 1024 --vcpus 1 --disk path=/images/test/hadoop2.img,size=10    --network bridge=br0,model=virtio --noautoconsole --accelerate  --vnc --vncport=5912 --vnclisten=0.0.0.0  --cdrom /images/iso/CentOS-6.5-x86_64-minimal.iso -d

  b)安装qcow2格式的磁盘(空间动态增长),首先要先创建qcow2格式的磁盘。

1
2
3
[root@KVM  test ] # qemu-img create -f qcow2 hadoop3.img 10G
Formatting  'hadoop3.img' fmt =qcow2 size=10737418240 encryption=off cluster_size=65536 
[root@KVM  test ] # virt-install --name=hadoop3 --ram 512 --vcpus=1 --disk path=/images/test/hadoop3.img,format=qcow2,size=7,bus=virtio --accelerate --cdrom /images/iso/CentOS-6.5-x86_64-minimal.iso -d --vnc --vncport=5913   --network network:default --noautoconsole

具体的安装信息,如下:

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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
[root@KVM  test ] # qemu-img create -f qcow2 hadoop3.img 10G
Formatting  'hadoop3.img' fmt =qcow2 size=10737418240 encryption=off cluster_size=65536 
[root@KVM  test ] # virt-install --name=hadoop3 --ram 512 --vcpus=1 --disk path=/images/test/hadoop3.img,format=qcow2,size=7,bus=virtio --accelerate --cdrom /images/iso/CentOS-6.5-x86_64-minimal.iso -d --vnc --vncport=5913   --network network:default --noautoconsole
Tue, 02 Feb 2016 14:12:36 DEBUG    Launched with  command  line:
/usr/sbin/virt-install  --name=hadoop3 -- ram  512 --vcpus=1 --disk path= /images/test/hadoop3 .img, format =qcow2,size=7,bus=virtio --accelerate --cdrom  /images/iso/CentOS-6 .5-x86_64-minimal.iso -d --vnc --vncport=5913 --network network:default --noautoconsole
Tue, 02 Feb 2016 14:12:36 DEBUG    Requesting libvirt URI default
Tue, 02 Feb 2016 14:12:36 DEBUG    Received libvirt URI qemu: ///system
Tue, 02 Feb 2016 14:12:36 DEBUG    Requesting virt method  'default' , hv  type  'default' .
Tue, 02 Feb 2016 14:12:36 WARNING  KVM acceleration not available, using  'qemu'
Tue, 02 Feb 2016 14:12:36 DEBUG    Received virt method  'hvm'
Tue, 02 Feb 2016 14:12:36 DEBUG    Hypervisor name is  'qemu'
Tue, 02 Feb 2016 14:12:36 DEBUG    --graphics compat generated: vnc,port=5913
Tue, 02 Feb 2016 14:12:36 DEBUG    DistroInstaller location is a  local  file /path /images/iso/CentOS-6 .5-x86_64-minimal.iso
Tue, 02 Feb 2016 14:12:36 DEBUG    Guest.has_install_phase: True
Starting  install ...
Tue, 02 Feb 2016 14:12:36 DEBUG    Generated  install  XML: 
<domain  type = 'qemu' >
   <name>hadoop3< /name >
   <uuid>ae9def17-b45b-f9ea-4ff9-ece22c95503e< /uuid >
   <memory>524288< /memory >
   <currentMemory>524288< /currentMemory >
   <vcpu>1< /vcpu >
   <os>
     < type  arch= 'x86_64' >hvm< /type >
     <boot dev= 'cdrom' />
     <boot dev= 'hd' />
   < /os >
   <features>
     <acpi/><apic/><pae/>
   < /features >
   <clock offset= "utc" />
   <on_poweroff>destroy< /on_poweroff >
   <on_reboot>destroy< /on_reboot >
   <on_crash>destroy< /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/hadoop3.img' />
       <target dev= 'vda'  bus= 'virtio' />
     < /disk >
     <disk  type = 'file'  device= 'cdrom' >
       <driver name= 'qemu' />
       < source  file = '/images/iso/CentOS-6.5-x86_64-minimal.iso' />
       <target dev= 'hdc'  bus= 'ide' />
       < readonly />
     < /disk >
     <controller  type = 'usb'  index= '0'  model= 'ich9-ehci1' >
     < /controller >
     <controller  type = 'usb'  index= '0'  model= 'ich9-uhci1' >
         <master startport= '0' />
     < /controller >
     <controller  type = 'usb'  index= '0'  model= 'ich9-uhci2' >
         <master startport= '2' />
     < /controller >
     <controller  type = 'usb'  index= '0'  model= 'ich9-uhci3' >
         <master startport= '4' />
     < /controller >
     <interface  type = 'network' >
       < source  network= 'default' />
       <mac address= '52:54:00:87:5b:c0' />
     < /interface >
     <input  type = 'mouse'  bus= 'ps2' />
     <graphics  type = 'vnc'  port= '5913' />
     <console  type = 'pty' />
     <video>
       <model  type = 'cirrus' />
     < /video >
   < /devices >
< /domain >
Tue, 02 Feb 2016 14:12:36 DEBUG    Generated boot XML: 
<domain  type = 'qemu' >
   <name>hadoop3< /name >
   <uuid>ae9def17-b45b-f9ea-4ff9-ece22c95503e< /uuid >
   <memory>524288< /memory >
   <currentMemory>524288< /currentMemory >
   <vcpu>1< /vcpu >
   <os>
     < type  arch= 'x86_64' >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/hadoop3.img' />
       <target dev= 'vda'  bus= 'virtio' />
     < /disk >
     <disk  type = 'block'  device= 'cdrom' >
       <target dev= 'hdc'  bus= 'ide' />
       < readonly />
     < /disk >
     <controller  type = 'usb'  index= '0'  model= 'ich9-ehci1' >
     < /controller >
     <controller  type = 'usb'  index= '0'  model= 'ich9-uhci1' >
         <master startport= '0' />
     < /controller >
     <controller  type = 'usb'  index= '0'  model= 'ich9-uhci2' >
         <master startport= '2' />
     < /controller >
     <controller  type = 'usb'  index= '0'  model= 'ich9-uhci3' >
         <master startport= '4' />
     < /controller >
     <interface  type = 'network' >
       < source  network= 'default' />
       <mac address= '52:54:00:87:5b:c0' />
     < /interface >
     <input  type = 'mouse'  bus= 'ps2' />
     <graphics  type = 'vnc'  port= '5913' />
     <console  type = 'pty' />
     <video>
       <model  type = 'cirrus' />
     < /video >
   < /devices >
< /domain >
Creating domain...                                                             |    0 B     00:00     
Tue, 02 Feb 2016 14:12:36 DEBUG    Started guest, connecting to console  if  requested
Tue, 02 Feb 2016 14:12:36 DEBUG    XML fetched from libvirt object:
<domain  type = 'qemu'  id = '15' >
   <name>hadoop3< /name >
   <uuid>ae9def17-b45b-f9ea-4ff9-ece22c95503e< /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= 'cdrom' />
     <boot dev= 'hd' />
   < /os >
   <features>
     <acpi/>
     <apic/>
     <pae/>
   < /features >
   <clock offset= 'utc' />
   <on_poweroff>destroy< /on_poweroff >
   <on_reboot>destroy< /on_reboot >
   <on_crash>destroy< /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/hadoop3.img' />
       <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= 'cdrom' >
       <driver name= 'qemu'  type = 'raw' />
       < source  file = '/images/iso/CentOS-6.5-x86_64-minimal.iso' />
       <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 = 'network' >
       <mac address= '52:54:00:87:5b:c0' />
       < source  network= 'default' />
       <target dev= 'vnet3' />
       < alias  name= 'net0' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x03'  function = '0x0' />
     < /interface >
     <serial  type = 'pty' >
       < source  path= '/dev/pts/8' />
       <target port= '0' />
       < alias  name= 'serial0' />
     < /serial >
     <console  type = 'pty'  tty = '/dev/pts/8' >
       < source  path= '/dev/pts/8' />
       <target  type = 'serial'  port= '0' />
       < alias  name= 'serial0' />
     < /console >
     <input  type = 'mouse'  bus= 'ps2' />
     <graphics  type = 'vnc'  port= '5913'  autoport= 'no'  listen= '127.0.0.1' >
       <listen  type = 'address'  address= '127.0.0.1' />
     < /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 >

然后按照提示安装步骤一步步来安装,操作系统的安装省略。

也可以通过VNC使用virt-manager远程进行安装管理

[参数说明]

--name   虚拟机名称

--hvm     使用全虚拟化(与para-irtualization向对),不支持xen hypervisor

--ram      虚拟机内存大小

--vcpus   虚拟机虚拟CPU个数

--disk      虚拟机使用的磁盘(文件)的路径,本例中文件放置在/images/test目录下

--network 网络设置,使用默认设置即可

--vnc     设置连接桌面环境的vnc端口,本例是5911

--cdrom   设置光驱获取虚拟光驱文件的路径 -d 指示从光驱启动( -c 指示从硬盘启动)我们这里是/images/iso

安装时建议一个来安装,否则会出现报错信息



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


相关文章
|
2月前
|
安全 Linux KVM
Linux虚拟化技术:从Xen到KVM
Xen和KVM是Linux平台上两种主要的虚拟化技术,各有优缺点和适用场景。通过对比两者的架构、性能、安全性、管理复杂性和硬件依赖性,可以更好地理解它们的适用场景和选择依据。无论是高性能计算、企业虚拟化还是云计算平台,合理选择和配置虚拟化技术是实现高效、稳定和安全IT环境的关键。
137 8
|
4月前
|
存储 Linux 调度
KVM 虚拟化的功能特性
【10月更文挑战第13天】虚拟化技术创建实体资源的虚拟版本,提升资源利用率。KVM(Kernel-based Virtual Machine)作为全虚拟化解决方案,借助Linux内核实现Hypervisor功能,通过模块化方式提供高效的虚拟化环境。
|
5月前
|
KVM 虚拟化
虚拟化技术概述及KVM环境安装
关于虚拟化技术概述及KVM环境安装的教程,涵盖了虚拟化的定义、分类、管理工具,以及KVM的系统需求、安装步骤和使用指南。
165 11
虚拟化技术概述及KVM环境安装
|
5月前
|
KVM 虚拟化
KVM虚拟机的热迁移
这篇文章详细介绍了KVM虚拟机的热迁移过程,包括临时迁移和永久迁移的步骤,以及可能遇到的故障和解决方案。
210 1
KVM虚拟机的热迁移
|
4月前
|
安全 KVM 虚拟化
OpenEuler 中配置 KVM 虚拟化环境指南
本文档详细介绍了如何在OpenEuler系统中配置和管理KVM虚拟化环境,包括环境准备、组件安装、虚拟机安装及管理命令等,适合初学者和有经验的用户。内容覆盖了从桥接网卡配置到虚拟机的安装与管理,以及常见问题的解决方法,帮助用户高效利用虚拟化技术。
328 0
|
5月前
|
KVM 虚拟化 数据安全/隐私保护
KVM虚拟机安装实战
本文讲述了如何创建并使用VNC连接KVM虚拟机的详细教程,包括安装图解和命令行参数说明。
166 8
|
5月前
|
KVM 虚拟化
KVM虚拟机的冷迁移
这篇文章详细描述了KVM虚拟机的冷迁移过程,包括无依赖环境迁移、有链接克隆虚拟机迁移、多块磁盘迁移的案例,以及可能遇到的错误和解决方案。
219 3
|
2天前
|
存储 虚拟化
【2025最新】 神奇!VMware Workstation Pro虚拟机还原与删除功能,让你轻松应对各种场景!
删除和还原VMware虚拟机的操作步骤如下: **删除虚拟机:** 1. 选择要删除的虚拟机,右键点击并选择“移除”。 2. 这仅从列表中移除虚拟机,并未彻底删除。需前往VMware默认存储路径(如 `D:\VMware\data`),找到对应虚拟机文件夹并删除。 **还原虚拟机:** 1. 若误删虚拟机列表项目,可通过右键点击空白处,选择“打开”,找到保存虚拟机的路径文件夹。 2. 选择被删除虚拟机对应的 `.vmx` 配置文件并打开,即可在列表中恢复该虚拟机。 总结:VMware虚拟机可用于模拟多种操作系统和开发环境,掌握删除与还原技巧可提高使用效率。
32 8
【2025最新】 神奇!VMware Workstation Pro虚拟机还原与删除功能,让你轻松应对各种场景!
|
2天前
|
虚拟化
【2025最新】VMware Workstation Pro 虚拟机基础配置教程,方便你的神操作!
VMware Workstation Pro 是一款强大的虚拟化工具,本文简要介绍其基本配置与操作。安装后,用户可以通过“编辑菜单 &gt; 首选项”设置虚拟机保存路径、是否显示托盘图标等全局配置。新建虚拟机时,需选择操作系统类型、配置处理器、内存、网络和硬盘等参数。建议根据主机硬件性能合理分配资源,避免过度占用。创建完成后,用户可加载 ISO 镜像文件安装所需操作系统。通过这些步骤,您可以轻松搭建并管理多个虚拟环境。
30 8
【2025最新】VMware Workstation Pro 虚拟机基础配置教程,方便你的神操作!
|
2天前
|
存储 编解码 虚拟化
【2025最新】VMware Workstation Pro 虚拟机配置与安装VMware Tools 感受它的强大~
VMware Tools 是 VMware 虚拟机中自带的一种增强工具,能够显著提升虚拟机的性能和用户体验。它提供了优化的显卡驱动程序、文件共享与拖放功能、时间同步以及跨虚拟机和宿主机的复制粘贴功能。安装 VMware Tools 可以让虚拟机在 VMware 平台上运行得更加高效,并且对于老旧系统(如 Win98、Win2000、WinXP)也能提供必要的驱动支持。每个虚拟机都需要独立安装与其操作系统版本相匹配的 VMware Tools,以确保最佳兼容性和性能表现。
30 6
【2025最新】VMware Workstation Pro 虚拟机配置与安装VMware Tools 感受它的强大~

热门文章

最新文章