使用oz制作镜像

1、安装软件包

# rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm

# yum install -y oz libguestfs-tools

2、修改配置文件(默认即可)

需要注意的是,制作出来的镜像,不管是raw格式还是qcow2格式,都是不经过压缩的,具体往下看

 # cat /etc/oz/oz.cfg 
[paths]
output_dir = /var/lib/libvirt/images
data_dir = /var/lib/oz
screenshot_dir = /var/lib/oz/screenshots
# sshprivkey = /etc/oz/id_rsa-icicle-gen

[libvirt]
uri = qemu:///system
image_type = qcow2
#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

3、定义tdl文件

cat centos6.6.ks
<template>
<name>centos66_x86_64</name>
<description>Centos 6.6 x86_64 template</description>
<os>
<name>CentOS-6</name>
<version>6</version>
<arch>x86_64</arch>
<rootpw>root</rootpw>
<install type='iso'>
<iso>file:/iso/CentOS-6.6-x86_64-bin-DVD1.iso</iso>
</install>
</os>
<disk>
   <size>20</size>
</disk>
<commands>
<command name='update'>
sed -i '/^HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i '/^UUID/d' /etc/sysconfig/network-scripts/ifcfg-eth0
echo -n > /etc/udev/rules.d/70-persistent-net.rules
echo -n > /lib/udev/rules.d/75-persistent-net-generator.rules
sed -i '/^SELINUX=/s/enforcing/disabled/' /etc/selinux/config
</command>
</commands>
</template>

4、定义ks文件

# cat centos_6.6.tdl 
install
text
key --skip
keyboard us
lang en_US.UTF-8
skipx
network --device eth0 --bootproto dhcp
rootpw hscloud
firewall --disabled
authconfig --enableshadow --enablemd5
selinux --disabled
timezone --utc Asia/Shanghai
bootloader --location=mbr --append="console=tty0 console=ttyS0,115200"
zerombr yes
clearpart --all

part /boot --fstype ext4 --size=500
part /     --fstype ext4 --size=15000
part swap  --fstype swap --size=4096
reboot

%packages
@base
@core
%post

EOF

5、开始制作

# oz-install -p -u -d3 -a centos6.6.ks centos_6.6.tdl

6、镜像对比

qcow2

# qemu-img info centos66_x86_64.qcow2 
    image: centos66_x86_64.qcow2
    file format: qcow2
    virtual size: 20G (21474836480 bytes)
    disk size: 1.5G
    cluster_size: 65536

raw

# qemu-img info centos66_x86_64_raw.dsk 
    image: centos66_x86_64_raw.dsk
    file format: raw
    virtual size: 20G (21474836480 bytes)
    disk size: 1.5G
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值