做好系统后:
1.配置yum源:
yum -y install wget
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.$(date +%F)
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
2.关闭SeLinux
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/selinux/config
grep SELINUX=disabled /etc/selinux/config
setenforce 0
或者直接编辑/etc/sysconfig/selinux,修改成SELINUX=disabled
3.使nova console-log 能将实例启动过程输出到实例启动日志中,就要在文件/boot/grub/menu.lst 中kernel参数中增加下面的内容:
kernel ...(省略n个参数)... console=tty0 console=ttyS0,115200n8
如下:
[[email protected] yum.repos.d]# cat /boot/grub/menu.lst # grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,0) # kernel /vmlinuz-version ro root=/dev/vda2 # initrd /initrd-[generic-]version.img #boot=/dev/vda default=0 timeout=1 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title CentOS (2.6.32-431.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=UUID=f0a5d467-5101-4a63-bc26-48682cac231b rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet console=tty0 console=ttyS0,115200n8 initrd /initramfs-2.6.32-431.el6.x86_64.img
4.修改网络信息 /etc/sysconfig/network-scripts/ifcfg-eth0 (删掉mac信息)如下:
TYPE=Ethernet DEVICE=eth0 ONBOOT=yes BOOTPROTO=dhcp NM_CONTROLLED=no
做完后,重启网络服务
service network restart
5. 增加一行到/etc/sysconfig/network :
NOZERCONF=yes
6、增加epel源
yum -y install epel-release
7.安装ACPI服务,能让宿主机对虚拟机进行开关机等电源管理操作
yum install acpid
chkconfig acpid on
yum install acpid -ychkconfig acpid onservice acpid start
8.安装和配置qemu-guest-agent
安装:
yum -y install qemu-guest-agent
配置:
8.1 编辑/etc/sysconfig/qemu-ga
TRANSPORT_METHOD="virtio-serial" DEVPATH="/dev/virtio-ports/org.qemu.guest_agent.0" LOGFILE="/var/log/qemu-ga/qemu-ga.log" PIDFILE="/var/run/qemu-ga.pid" BLACKLIST_RPC="" FSFREEZE_HOOK_ENABLE=0
8.2 将虚拟机关机,在虚拟机配置文件libvirt.xml中的<devices>下面添加下述配置,并重新启动虚拟机
用这条命令编辑
virsh edit centos6-raw
添加如下条目:
<channel type=‘unix‘> <source mode=‘bind‘ path=‘/var/lib/libvirt/qemu/org.qemu.guest_agent.0.centos6-raw.sock‘/> <target type=‘virtio‘ name=‘org.qemu.guest_agent.0‘/> <address type=‘virtio-serial‘ controller=‘0‘ bus=‘0‘ port=‘1‘/></channel><channel type=‘spicevmc‘> <target type=‘virtio‘ name=‘com.redhat.spice.0‘/> <address type=‘virtio-serial‘ controller=‘0‘ bus=‘0‘ port=‘2‘/></channel>
修改完后保存配置
8.3 启动qemu-ga
[[email protected] ~]# service qemu-ga restart Stopping qemu-ga: [ OK ] Starting qemu-ga: [ OK ][[email protected] ~]# chkconfig qemu-ga on[[email protected] ~]# chkconfig --list|grep qemu-gaqemu-ga 0:off 1:off 2:on 3:on 4:on 5:on 6:off
测试:
这个需要在开启状态下测试
8.关机
init 0
9.清理信息
virt-sysprep -d centos6-raw
10、上传镜像
glance image-create --name "centos6-raw" --file ./centos6-raw --disk-format raw --container-format bare --property hw_qemu_guest_agent=yes --visibility public --progress
参考:
http://blog.sina.com.cn/s/blog_c094640c0102wv8t.html
http://blog.csdn.net/zouyee/article/details/49103077