kvm-img create -f raw CentOS-6.2-x86_64.img 10G
sudo kvm -m 1024 -cdrom CentOS-6.2-x86_64-bin-DVD1.iso -drive file=CentOS-6.2-x86_64.img,if=scsi,index=0 -boot d -net nic -net user -usbdevice tablet –nographic -vnc :4 (如果報錯可能是vnc端口已佔用,請換個端口)
使用vnc連接後
安裝完成之後虛擬機選擇重啓,虛擬機顯示no device boot ,就殺掉這個kvm進程
掉一些參數 ,啓動虛擬機
sudo kvm -m 1024 -drive file=CentOS-6.2-x86_64.img -boot c -net nic -net tap -usbdevice tablet -nographic -vnc :1
修改分區加載表(/etc/fstab),註釋或刪除以前的,加上 LABEL=cec-rootfs 一行:
# vi /etc/fstab
#UUID=47a90bea-2d88-4c82-a335-09c1533b1538 / ext4 defaults 1 1
LABEL=uec-rootf / ext4 defaults 0 0
在網絡接口配置裏面註釋或刪除這行 #HWADDR= 一行,啓用 DHCP:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
添加如下腳本來獲取私匙,編輯 /etc/rc.local ,在 touch /var/lock/subsys/local 之前添加:
mkdir -p /root/.ssh
cat /root/.ssh/authorized_keys|grep ssh-rsa
if [ $? -ne 0 ];
then
curl -m 10 -s http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key |grep 'ssh-rsa' >> /root/.ssh/authorized_keys
fi
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
別忘了還需要修改 sshd 的配置實現無密碼登錄:
# vi /etc/ssh/sshd_config
...
RSAAuthentication yes
PubkeyAuthentication yes
PasswordAuthentication no (根據需求更改)
需要關閉 SELINUX,否則即使上面 ssh 設定允許 root 無密碼登錄也無效:
# vi /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted
70-persistent-net.rules 會自動添加其他的網絡接口,需要刪除這個文件避免自動添加除了 eth0 以外的接口:
# rm -f /etc/udev/rules.d/70-persistent-net.rules
關閉系統:
# shutdown -h now
虛擬機關閉之後,上傳到glance
glance add name="CentOS-6.2-x86_64" is_public=true container_format=ovf disk_format=raw < CentOS-6.2-x86_64.img