Before. Installing the Software
Yum install libvirt libguestfs-tools QEMU-KVM Qemu-imgyum groupinstall Virtualization "Virtualization Client"-yyum-y ins Tall Libvirt libguestfs-tools-y
1. Download a minimum centos6.5 ISO file
wget Http://mirrors.163.com/centos/6.5/isos/x86_64/CentOS-6.5-x86_64-minimal.iso
2. Create an empty image file
Qemu-img create-f Qcow2/tmp/centos6.5-working.qcow2 10G
3. Create a virtual machine
Qemu-img create-f qcow2/tmp/centos6.5-working.qcow2 10G virt-install--VIRT-TYPE=KVM--name=CentOS6.5--ram=1024-- Cdrom=/tmp/centos-6.5-x86_64-minimal.iso--disk=/tmp/centos6.5-working.qcow2,format=qcow2--graphics=vnc,listen= 0.0.0.0--noautoconsole--os-type=linux--os-variant=rhel6
4.VNC Remote Installation, address port 5900, partition only one, mount to "/", the format is EXT4;
#重启后执行命令开启虚拟机virsh Start centos6.5
5. Initializing the
#!/bin/bash# add the epel repo and updaterpm -uvh http:// Download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm#yum -y update# install cloud-inityum -y install cloud-utils cloud-init parted git acpidchkconfig acpid on # install linux rootfs resizecd /tmpgit clone https://github.com/flegmatik/linux-rootfs-resize.gitcd linux-rootfs-resize./installif [[ $? -eq 0 ]];then cd /tmp rm -rf linux-rootfs-resizeelse exitfi #change sshd portsed -i ' s/^ #Port 22/ Port 65530/g ' /etc/ssh/sshd_config# clean up the network interface stuffrm /etc/udev/rules.d/70-persistent-net.rulessed -i '/hwaddr/d ' /etc/sysconfig/ network-scripts/ifcfg-eth0sed -i '/uuid/d ' /etc/sysconfig/network-scripts/ifcfg-eth0sed -i '/^onboot/ s/no/yes/g ' /etc/sysconfig/ network-scripts/ifcfg-eth0sed -i '/^nm_controlled/ s/yes/no/g ' /etc/sysconfig/ network-scripts/ifcfg-eth0echo "Nozeroconf=yes" >> /etc/sysconfig/network# graft up grubsed -i ' s/timeout=5/timeout=0/g ' /boot/grub/menu.lstsed -i '/^\ skernel/ s/$/ console=tty0 console=ttys0,115200n8/' /boot/grub/menu.lst# say something cute in /etc/motdecho "This is openstack-centos-6" >> /etc/motd# notify we ' re haltingecho "halting instance in 5 seconds!" Sleep 5# halt the instancehalt
6. Aftercare Operations
#清除网络相关硬件生成信息virt-sysprep-d centos6.5# Compressed image virt-sparsify--compress/tmp/centos6.5-working.qcow2 Centos6.5-working_ 1.qcow2
7. Complete
This article is from the "8446082" blog, please be sure to keep this source http://8456082.blog.51cto.com/8446082/1698680
OpenStack CentOS-6.5 Image creation