1
2
|
# yum -y install lorax pykickstart virt-install libguestfs-tools imagefactory oz
# yum -y groupinstall Virtualization Host
|
1
2
|
# setenforce 0
# sed -i "s/^SELINUX.*/SELINUX=permissive/g" /etc/sysconfig/selinux
|
1
2
3
4
5
|
# cd /tmp/
# git clone git://gerrit.ovirt.org/ovirt-appliance
# cd ovirt-appliance
# git submodule update --init
# cd engine-appliance
|
1
|
# make ovirt-appliance-fedora.raw
|
1
|
# make
|
1
2
3
4
5
6
7
8
9
10
11
|
Traceback (most recent call last):
File
"scripts/create_ova.py"
, line 4,
in
from imagefactory_plugins.ovfcommon.ovfcommon
import
RHEVOVFPackage
File
"/tmp/ovirt-appliance/engine-appliance/imagefactory/imagefactory_plugins/ovfcommon/ovfcommon.py"
, line 28,
in
from imgfac.PersistentImageManager
import
PersistentImageManager
File
"/tmp/ovirt-appliance/engine-appliance/imagefactory/imgfac/PersistentImageManager.py"
, line 17,
in
from ApplicationConfiguration
import
ApplicationConfiguration
File
"/tmp/ovirt-appliance/engine-appliance/imagefactory/imgfac/ApplicationConfiguration.py"
, line 25,
in
from imgfac.Version
import
VERSION as VERSION
ImportError: No module named Version
make
: *** [ovirt-appliance-fedora.ova] 错误 1
|
1
|
# cp /usr/lib/python2.7/site-packages/imgfac/Version.py /tmp/ovirt-appliance/engine-appliance/imagefactory/imgfac/
|
1
2
3
|
kill
$(
cat
spawned_pids)
/bin/bash
:行1: qemu-kvm: 未找到命令
make
[1]: 离开目录“
/tmp/ovirt-appliance/engine-appliance
”
|
1
|
ln
-s
/usr/libexec/qemu-kvm
/bin/
|
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
|
MAIN_NAME ?= ovirt-appliance-fedora
#定义文件名
VM_CPUS ?= 2
#定义虚拟机CPU数量
VM_RAM ?= 4096
#定义虚拟机RAM大小(M)
VM_DISK ?= 8000
#定义虚拟机DISK大小(M)
OVA_RAM ?= 4096
#定义OVA模板RAM大小(M)
OVA_CPUS ?= $(VM_CPUS)
#定义OVA模板CPU数量
ARCH := x86_64
#定义架构
RELEASEVER := 7
#定义版本
PYTHON ?= PYTHONPATH=
"$(PWD)/imagefactory/"
python
#定义Python环境变量
CURL ?= curl
#定义CURL工具
.SECONDARY:
.PHONY:$(MAIN_NAME).ks.tpl
#定义ks模板文件名称
.INTERMEDIATE: hda.qcow2
#定义虚拟机磁盘文件名
all: $(MAIN_NAME).ova
echo
"$(MAIN_NAME)"
appliance
done
%.ks: %.ks.tpl
#基于ks模板,拼合生成ks文件(修改一些ks文件信息)
ksflatten $< > $@
sed
-i \
-e
"/^[-]/ d"
\
-e
"/^text/ d"
\
-e
"s/^part .*/part \/ --size $(VM_DISK) --fstype ext4 --fsoptions discard/"
\
-e
"s/^network .*/network --activate/"
\
-e
"s/^%packages.*/%packages --ignoremissing/"
\
-e
"/default\.target/ s/^/#/"
\
-e
"/RUN_FIRSTBOOT/ s/^/#/"
\
-e
"/remove authconfig/ s/^/#/"
\
-e
"/remove linux-firmware/ s/^/#/"
\
-e
"/remove firewalld/ s/^/#/"
\
-e
"/^bootloader/ s/bootloader .*/bootloader --location=mbr --timeout=1/"
\
-e
"/rawhide/ s/^/#/"
\
-e
"/^reboot/ s/reboot/poweroff/"
\
-e
"/^services/ s/sshd/sshd,initial-setup-text/"
\
-e
"/^firstboot/ s/$$/ --reconfig/"
\
-e
"s#\$$basearch#$(ARCH)#g"
\
-e
"s#\$$releasever#$(RELEASEVER)#g"
\
$@
%.qcow2: %.ks
#制作qcow2格式模板文件
make
-f imgbased
/data/images/poor-mans-lmc
.makefile \
#执行第二次make
KICKSTART=
"$<"
\
RELEASEVER=$(RELEASEVER) \
QEMU_APPEND=
"cmdline $(QEMU_APPEND)"
\
DISK_SIZE=$$(( $(VM_DISK) / 1000 ))G \
run-
install
#执行run-install,制作hda.qcow2文件
qemu-img convert -O qcow2 hda.qcow2
"$@"
#将hda.qcow2文件转换为qcow2格式并重新命名
rm
-f hda.qcow2
#删除hda.qcow2文件(该文件为中间文件,此后已不需要)
%.ova: %.qcow2
#调用scripts/create_ova.py,制作ova格式模板文件
$(SUDO) $(PYTHON) scripts
/create_ova
.py -m $(OVA_RAM) -c $(OVA_CPUS)
"$*.qcow2"
"$@"
clean: clean-log
#清除log
echo
clean-log:
rm
-f *.log
#删除log文件
|
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
|
KICKSTART = kickstarts
/runtime-layout
.ks
#需要再研究下文件是否会被调用
DISK_NAME = hda.qcow2
#定义虚拟机磁盘文件名
DISK_SIZE = 10G
#定义虚拟机磁盘大小
VM_RAM = 2048
#定义虚拟机内存
VM_SMP = 4
QEMU = qemu-kvm
#定义QEMU工具
QEMU_APPEND =
#QEMU附加信息
CURL = curl -L -O
#CURL命令附加选项
FEDORA_RELEASEVER = 7
#定义版本
FEDORA_ANACONDA_RELEASEVER = 7
#定义Anaconda版本
FEDORA_URL = http:
//192
.168.3.239
/mirrors/Fedora/19/os/x86_64/
#定义FEDORA dvd镜像URL
FEDORA_ANACONDA_URL = $(FEDORA_URL)
#定义Anaconda URL
ifneq ($(FEDORA_RELEASEVER), $(FEDORA_ANACONDA_RELEASEVER))
FEDORA_ANACONDA_URL = http:
//192
.168.3.239
/mirrors/Fedora/19/os/x86_64/
endif
SHELL =
/bin/bash
.INTERMEDIATE: spawned_pids
vmlinuz:
#定义vmlinuz文件位置
$(CURL) $(FEDORA_ANACONDA_URL)
/isolinux/vmlinuz
initrd.img:
#定义initrd.img文件位置
$(CURL) $(FEDORA_ANACONDA_URL)
/isolinux/initrd
.img
squashfs.img:
#定义squashfs.img文件位置
$(CURL) $(FEDORA_ANACONDA_URL)
/LiveOS/squashfs
.img
define TREEINFO
#定义TreeInfo信息
[general]
name = Fedora-$(FEDORA_RELEASEVER)
family = Fedora
variant = Fedora
version = $(FEDORA_RELEASEVER)
packagedir =
arch = x86_64
[stage2]
mainimage = squashfs.img
[images-x86_64]
kernel = vmlinuz
initrd = initrd.img
endef
.PHONY: .treeinfo
export
TREEINFO
.treeinfo:
echo
-e
"$$TREEINFO"
> $@
run-
install
: PYPORT:=$(shell
echo
$$(( 50000 + $$RANDOM % 15000 )) )
run-
install
: vmlinuz initrd.img squashfs.img .treeinfo $(KICKSTART)
python -m SimpleHTTPServer $(PYPORT) &
echo
$$! > spawned_pids
qemu-img create -f qcow2 $(DISK_NAME) $(DISK_SIZE)
$(QEMU) \
#调用qemu-kvm启动虚拟机,根据ks文件配置自动安装系统并进行相关配置
-vnc 0.0.0.0:7 \
-serial stdio \
-smp $(VM_SMP) -m $(VM_RAM) \
-hda $(DISK_NAME) \
-kernel vmlinuz \
-initrd initrd.img \
-append
"console=ttyS0 inst.repo=$(FEDORA_URL) inst.ks=http://10.0.2.2:$(PYPORT)/$(KICKSTART) inst.stage2=http://10.0.2.2:$(PYPORT)/ quiet $(QEMU_APPEND)"
; \
kill
$$(
cat
spawned_pids)
|