vesystem

  在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

  后面安装acpid
  vmbuilder的参数添加:

1 --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

 本文转自:http://hi.baidu.com/xunizhongduan/item/a03896a9bee0c8088919d3d6

分类:

技术点:

相关文章:

  • 2022-02-07
  • 2021-07-23
  • 2021-10-06
  • 2021-11-01
  • 2022-12-23
  • 2021-11-19
  • 2022-12-23
  • 2022-01-04
猜你喜欢
  • 2021-11-23
  • 2021-06-21
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案