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