Welcome 微信登录

首页 / 操作系统 / Linux / KVM创建虚拟机后指定启动脚本

在vmbuilder命令中创建vm时,可以通过参数虚拟机第一次启动的时候执行的脚本文件。但是由于这个时候虚拟机网络可能还不通,必须要延迟一会儿,才能保证一些apt-get install命令能够顺利执行。下面的脚本是我常用的,贡献出来:boot.sh文件内容:
  1. # Set time zone
  2. cp /usr/share/zoneinfo/Asia/Harbin /etc/localtime
  3. # Set proxy server
  4. echo "Acquire::http::Proxy "http://10.112.18.178:3142";" >> /etc/apt/apt.conf
  5. while (! ping -c 1 www.baidu.com); do sleep 1; done
  6. echo "apt-get install acpid" >> /opt/x
  7. apt-get install acpid
第一行设置时区第二行设置代理第三行等待ping通www.baidu.com后面安装acpidvmbuilder的参数添加:--firstboot=/var/lib/libvirt/images/$1/boot.sh  我原来测试脚本是bash,但是不能在boot.sh中执行,奇怪,不过先放在这里,以后还有用。
  1. # Test Internet connection is ok or not
  2. # If failed 10 times, exit
  3. # Return immediately if network is ok
  4. i=0
  5. count=10
  6. while [ $i -lt $count ]
  7. do
  8. echo "testing"
  9. let i++
  10. ping -c2 www.baidu.com > /dev/null
  11. r=$?
  12. echo $r
  13. if [ $r -ne 0 ]
  14. then
  15. echo "network is down"
  16. sleep 10
  17. else
  18. echo "network is up"
  19. let i=count+1
  20. fi
  21. done 
Linux使用dd命令测试硬盘读写速度KVM虚拟机关闭相关资讯      KVM  KVM虚拟机  KVM创建虚拟机 
  • 使用Shell脚本监控KVM虚拟机  (06月17日)
  • 怎样在 Ubuntu 和 Debian 中通过命  (02月29日)
  • RHCSA 系列(十五): 虚拟化基础  (10/07/2015 15:25:43)
  • 调整KVM虚拟机硬盘大小  (05月11日)
  • KVM嵌套虚拟化配置  (11/20/2015 20:16:53)
  • Ubuntu下使用KVM+Qemu 搭建虚拟机  (10/04/2015 06:48:51)
本文评论 查看全部评论 (0)
表情: 姓名: 字数