Specify the startup script after creating a VM in KVM.

Source: Internet
Author: User


After creating a vm in KVM, specify the startup script. When creating a vm in the vmbuilder command, you can run the script file when the vm is started for the first time. However, the virtual machine network may not be available at this time, so you must wait for a while to ensure that some apt-get install commands can be executed smoothly. The scripts under www.2cto.com are commonly used and contributed: boot. sh file content: [plain] # Set time zone cp/usr/share/zoneinfo/Asia/Harbin/etc/localtime # Set proxy server echo 'acquire: http: Proxy" http://10.112.18.178:3142 "; '>/Etc/apt. conf while (! Ping-c 1 www.baidu.com); do sleep 1; done echo 'apt-get install acpid '>/opt/x apt-get install acpid the first line sets the time zone the second line sets the proxy the third line waits for the acpid vmbuilder to be installed after ping www.baidu.com add parameters: [plain] -- firstboot =/var/lib/libvirt/images/$1/boot. sh my original test script is bash, but it cannot be in boot. sh execution, strange, but put it here first, and will be used later. [Plain] # Test Internet connection is OK or not # If failed 10 times, exit # Return immediately if network is OK I = 0 count = 10 while [$ I-lt $ count] do echo "testing" let I ++ ping-c2 www.baidu.com>/dev/ null r = $? Echo $ r if [$ r-ne 0] then echo 'network is down 'sleep 10 else echo 'network is up 'let I = count + 1 fi done

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.