首页 > 虚拟化 > openstack镜像快速制作
您的足迹
  • 你没有浏览过任何文章或者你没有开启cookies。

openstack镜像快速制作

以前用KVM手动一步步安装虚拟机然后做镜像,现在想想真是弱爆了,现在有更神器了。OZ介绍我就不多写了,我是参照沙克的文档做的

http://www.chenshake.com/oz-making-centos-mirror/

但这里有个地方要注意,从网上复制下来的ks文件里面有windows下回车符,里面脚本怎么都执行不成功 ,用dos2unix转换一下就OK了

你只需yum -y install oz (要EPEL源)

然后你只需要配置2个文件,一个模板文件,一个ks文件。另外,你也可以根据你的需要设置一下你oz的配置文件 ,如下:

 

 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
# type = kvm,这边要设置你的网桥
bridge_name = br0
# cpus = 1
# memory = 1024

[cache]
original_media = yes
modified_media = no
jeos = no

[icicle]
safe_generation = no

模板文件如下:

<template>
   <name>centos_63_x86_64</name>
   <description>CentOS 6.3 x86_64 template</description>
   <os>
      <name>CentOS-6</name>
      <version>3</version>
      <arch>x86_64</arch>
      <install type='url'>
         <url>http://10.10.10.100/cobbler/ks_mirror/CentOS6.3-x86_64/</url>
      </install>
   </os>
  <disk>
    <size>10</size>
  </disk>
</template>

ks文件如下:

#version=DEVEL
# Firewall configuration
firewall --enabled --service=ssh

repo --name="repo0" --baseurl=http://mirrors.kernel.org/centos/6/os/x86_64
repo --name="repo1" --baseurl=http://mirrors.kernel.org/centos/6/updates/x86_64
repo --name="repo2" --baseurl=http://mirrors.kernel.org/fedora-epel/6/x86_64
repo --name="repo3" --baseurl=http://repos.fedorapeople.org/repos/openstack/cloud-init/epel-6
# Root password
rootpw --iscrypted --iscrypted $1$tuniu$bbKnWN9KQ7Kb31rdBvDfo.

# System authorization information
auth --useshadow --enablemd5
# System keyboard
keyboard us
# System language
lang en_US.UTF-8
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System services
services --disabled="avahi-daemon,iscsi,iscsid,firstboot,kdump" --enabled="network,sshd,rsyslog,tuned"
# System timezone
timezone --isUtc Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --append="console=ttyS0,115200n8 console=tty0" --location=mbr --driveorder="sda" --timeout=1
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all  
# Disk partitioning information
#part / --fstype="ext4" --grow --size=1
part /boot --fstype ext4 --size=200
part swap --size=1024
part / --fstype ext4 --size=4198 --grow

%post
# make sure firstboot doesn't start
echo "RUN_FIRSTBOOT=NO" > /etc/sysconfig/firstboot

cat <<EOL >> /etc/rc.local
if [ ! -d /root/.ssh ] ; then
    mkdir -p /root/.ssh
    chmod 0700 /root/.ssh
    restorecon /root/.ssh
fi
EOL

cat <<EOL >> /etc/ssh/sshd_config
UseDNS no
PermitRootLogin without-password
EOL

# bz705572
ln -s /boot/grub/grub.conf /etc/grub.conf

# bz688608
sed -i 's|\(^PasswordAuthentication \)yes|\1no|' /etc/ssh/sshd_config

# allow sudo powers to cloud-user
echo -e 'cloud-user\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers

# bz983611
echo "NOZEROCONF=yes" >> /etc/sysconfig/network

# set virtual-guest as default profile for tuned
echo "virtual-guest" > /etc/tune-profiles/active-profile

#bz 1011013
# set eth0 to recover from dhcp errors
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
DEVICE="eth0"
BOOTPROTO="dhcp"
ONBOOT="yes"
TYPE="Ethernet"
USERCTL="yes"
PEERDNS="yes"
IPV6INIT="no"
PERSISTENT_DHCLIENT="1"
EOF

#bz912801
# prevent udev rules from remapping nics
touch /etc/udev/rules.d/75-persistent-net-generator.rules

#setup getty on ttyS0
echo "ttyS0" >> /etc/securetty
cat <<EOF > /etc/init/ttyS0.conf
start on stopped rc RUNLEVEL=[2345]
stop on starting runlevel [016]
respawn
instance /dev/ttyS0
exec /sbin/agetty /dev/ttyS0 115200 vt100-nav
EOF

# lock root password
#passwd -d root
#passwd -l root

# let's randomise the root password
#head -n1 /dev/urandom | md5sum| awk {'print $1'} | passwd --stdin root

# clean up installation logs"
yum clean all
rm -rf /var/log/yum.log
rm -rf /var/lib/yum/*
rm -rf /root/install.log
rm -rf /root/install.log.syslog
rm -rf /root/anaconda-ks.cfg
rm -rf /var/log/anaconda*
%end

%packages --nobase --excludedocs
wget
vim
cloud-init
cloud-utils

%end

两个文件下载

file


相关博文

  1. 还没有评论
评论提交中, 请稍候...

留言

可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackbacks & Pingbacks ( 0 )
  1. 还没有 trackbacks
Feed