标签:kvm virt install
使用Virt-Manager安装虚拟机:从Virtual Machine Manager, 在工具栏上点击 【Create a new virtual machine 】或选择【File | New Virtual Machine】去打开这个向导,也允许从Virt-manager上面去创建新的虚拟机。
这个向导可以分为五步:
在我们上面安装方法中的第2项时,选择有点区别,详情见下图。
PXE方法安装系统需要注意一点:就是网卡类型不能设置为NAT。可以设置为Bridge. 由于现在流行虚拟化,PXE可能用的比较少,了解即可。
(1)从virt-manager GUI【Create a New Virtual Machine】,然后选择【Import existing disk image】作为OS的安装方法。
案例:安装windows 7系统
qemu-img create -f raw -o size=10G /var/lib/libvirt/qemu/win7.img
virt -install \
--name win7 \
--ram 1024 \
--disk path=./var/lib/libvirt/qemu/win7.img \
-- vcpus 1 \
--os-type windows \
--os-variant Windows 7 \
--network bridge=virbr0 \
--graphics vnc, port =5999 \
--console pty, target_type=serial \
--cdrom ./win7.iso \
同样的地,我们可以使用virt-install -promot命令来进行交互的安装,它将会和你进行交互,你可以再输入上面的信息。
virt-viewer <virtual machine> name
Automated virtual machine deployment
virtual builder这个命令是由libguestfs-tools-c这个包来提供的,所以我们需要首先安装此包。
virt-builder默认下载模板是从 http://libguestfs.org/download/builder/ 库下载的,可能由于国外的网站,所以比较慢而已,当然也可以自己构建本地的镜像库。(此处不作介绍 )
例子:比如我们想要创建一个CenotOS 7.14的虚拟机,该虚拟机有50GB的磁盘空间。
[ 1.0] Downloading: http://libguestfs.org/download/builder/centos-7.1.xz
[ 2.0] Planning how to build this image
[ 2.0] Uncompressing
[ 14.0] Resizing (using virt-resize) to expand the disk to 50.0G
[ 149.0] Opening the new disk
[ 179.0] Setting a random seed
[ 180.0] Setting passwords
virt-builder: Setting random password of root to Arw83LnDi66eMcmh
[ 198.0] Finishing off
Output file: centos-7.1.img
Output size: 50.0G
Output format: raw
Total usable space: 48.1G
Free space: 47.3G (98%)
#virt-install --name centos --ram 1028 --vcpus=2 --disk path=/var/lib/libvirt/qemu/centos-7.1.img --import
virt-builder的缓存砋载的模板到当前用户的家目录,位置是 $XDG_CACHE_HOME/virt-builder/ or $HOME/.cache/virt-builder.
通过virt-builder --print-cache输出缓存的信息
cache directory: /root/.cache/virt-builder
centos-6 x86_64 no
centos-7.0 x86_64 no
centos-7.1 x86_64 cached?
cirros-0.3.1 x86_64 no
debian-6 x86_64 no
debian-7 x86_64 no
debian-8 x86_64 no
fedora-18 x86_64 no
fedora-19 x86_64 no
fedora-20 x86_64 no
fedora-21 x86_64 no
fedora-21 aarch64 no
fedora-21 armv7l no
fedora-21 ppc64 no
fedora-21 ppc64le no
fedora-22 x86_64 no
fedora-22 aarch64 no
fedora-22 armv7l no
scientificlinux-6 x86_64 no
ubuntu-10.04 x86_64 no
ubuntu-12.04 x86_64 no
ubuntu-14.04 x86_64 no
#virt-builder --delete-cache
virt-builder --cache-all-templates
oz作为一个模板,描述了创建虚拟机的指导方针。
IOS或镜像的URL
磁盘的尺寸
额外包的安装
在镜像创建之后 ,其它命令的执行
Debian: 5, 6, 7
Fedora Core: 1, 2, 3, 4, 5, 6
Fedora: 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
FreeBSD: 10
Mageia: 4
Mandrake: 8.2, 9.1, 9.2, 10.0, 10.1
Mandriva: 2005, 2006.0, 2007.0, 2008.0
OpenSUSE: 10.3, 11.0, 11.1, 11.2, 11.3, 11.4, 12.1, 12.2, 12.3, 13.1
RHEL 2.1: GOLD, U2, U3, U4, U5, U6
RHEL 7: Beta, 0
RHEL/CentOS 3: GOLD, U1, U2, U3, U4, U5, U6, U7, U8, U9
RHEL/CentOS/Scientific Linux 4: GOLD, U1, U2, U3, U4, U5, U6, U7, U8, U9
RHEL/OL/CentOS/Scientific Linux{,CERN} 5: GOLD, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11
RHEL/OL/CentOS/Scientific Linux{,CERN} 6: 0, 1, 2, 3, 4, 5
RHL: 7.0, 7.1, 7.2, 7.3, 8, 9
Ubuntu: 5.04, 5.10, 6.06[.1,.2], 6.10, 7.04, 7.10, 8.04[.1,.2,.3,.4], 8.10, 9.04, 9.10, 10.04[.1,.2,.3], 10.10, 11.04, 11.10, 12.04[.1,.2,.3,.4,.5], 12.10, 13.04, 13.10, 14.04[.1], 14.10
Windows: 2000, XP, 2003, 7, 2008, 2012, 8, 8.1
#yum install -y oz libguestfs-tools
For Fedora 22: http://dl.fedoraproject.org/pub/fedora/linux/releases/22/Server/x86_64/os/
For CentOS 7: http://mirrors.dcarsat.com.ar/centos/7/os/x86_64/
创建简单的 TDL (Template Definition Language) 文件. TDL的详细使用请参考如下网址: https://github.com/clalancette/oz/wiki/Oz-template-description-language
oz-install -u -d3 TDL_FILE_PATH
:
u: After installation, perform the customization
d: Turn up the logging level. The levels are:
0: Errors only (this is the default)
1: Errors and warnings
2: Errors, warnings, and information
3: All messages
4: All messages, prepended with the level and classname
virsh define <xml_fike>
virsh start <vm_name>
[paths]
output_dir = /var/lib/libvirt/images
data_dir = /var/lib/oz
screenshot_dir = /var/lib/oz/screenshots
[libvirt]
uri = qemu:///system
image_type = raw
type = kvm
bridge_name = virbr0
cpus = 1
memory = 1024
[cache]
original_media = yes
modified_media = no
jeos = no
[icicle]
safe_generation = no
创建windows 7 虚拟机:
The resultant virtual machine should have 2048 memory assigned to it
The bridge to which the virtual machine is connected should be vswitch
The disk size should be 50G
The install media should be an ISO file stored locally on the system
编辑 /etc/oz/oz.cfg 文件,设置内存和桥的配置,并保存。
memory = 2048
bridge_name = vswitch
<template>
<name>win7jeos</name>
<os>
<name>Windows</name>
<version>7</version>
<arch>i386</arch>
<install type=‘iso‘>
<iso>file:///path/to/isos/win2k.iso</iso>
</install>
<key>MY_KEY_HERE</key>
</os>
<disk>
<size>50</size>
</disk>
<description>Minimal Windows7 </description>
</template>
Replace file:///path/to/isos/win2k.iso with the actual path of the ISO file
在MY_KEY_HERE这里要填入你主机真正的key文件,要不然安装可能不会成功。
安装完成后,应该会看到如下信息。
virsh define win7jeos_feb_11-2016
virsh start win7jeos
标签:kvm virt install
原文地址:http://blog.51cto.com/aishangwei/2124501