標籤:openstack centos-6.5 鏡像
before.安裝軟體
yum install libvirt libguestfs-tools qemu-kvm qemu-imgyum groupinstall Virtualization "Virtualization Client" -yyum -y install libvirt libguestfs-tools -y
1.下載一個最小的centos6.5的iso檔案
wget http://mirrors.163.com/centos/6.5/isos/x86_64/CentOS-6.5-x86_64-minimal.iso
2.建立一個空的鏡像檔案
qemu-img create -f qcow2 /tmp/CentOS6.5-working.qcow2 10G
3.建立虛擬機器
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遠程安裝,地址連接埠5900;分區只分一個,掛載到“/”,格式為ext4;
#重啟後執行命令開啟虛擬機器virsh start centos6.5
5.初始化
#!/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.善後操作
#清除網路相關硬體產生資訊virt-sysprep -d centos6.5#壓縮鏡像virt-sparsify --compress /tmp/CentOS6.5-working.qcow2 CentOS6.5-working_1.qcow2
7.完成
本文出自 “8446082” 部落格,請務必保留此出處http://8456082.blog.51cto.com/8446082/1698680
OpenStack CentOS-6.5鏡像建立