(OK) Creating_VMs_from_an_existing_VDI_file.txt


http://stdioe.blogspot.com/2012/01/creating-virtual-machine-with.html



Let's create a sample virtual machine:

1-) The first step is the VM creation,

(We are using a "Ubuntu OS + VBox" system that is installed in "http://stdioe.blogspot.com/2012/01/install-vbox-with-extpack-on-ubuntu.html" article. It is recommanded to read that article first.)


support@tester:~VBoxManagecreatevmnametestMachineostypeDebianregisterVirtualmachinetestMachineiscreatedandregistered.UUID:e2bfd53014fb4b8e8dc28523c9bd045eSettingsfile:/home/support/VirtualBoxVMs/testMachine/testMachine.vboxsupport@tester: 


2-) At this point, we can start with checking existing Virtual machine with following command:

support@tester:~VBoxManageshowvminfotestMachineActually,ourvirtualmachinehasjustbeencreatedbutIthasntgotanyharddrivesandsomeofthosesettingsmaynotrequired.Forexample,theexistingvirtualmachinememorysizeis128megabytes.Probablyyouwanttoincreaseit.YoumaynotwanttouseNATmodeethernetdevice.Rightnow,letschangesomeoptionsonourvirtualsample.3)Changememoryandthencheckit:support@tester:  VBoxManage modifyvm testMachine --memory 1024
support@tester:~support@tester:  VBoxManage showvminfo testMachine | grep "Memory size"
Memory size:     256MB


4-) Change nic (ethernet interface) bridge mode.

We need a bridge adapter for this and the bridge adapter needs a physical interface on base OS. I am checking the pysical interface on base OS:

support@tester:~ifconfigeth0Linkencap:EthernetHWaddr00:1a:64:5b:60:2cinetaddr:172.28.202.216Bcast:172.28.202.255Mask:255.255.255.0inet6addr:fe80::21a:64ff:fe5b:602c/64Scope:LinkUPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1RXpackets:2932762errors:0dropped:0overruns:0frame:0TXpackets:1149518errors:0dropped:0overruns:0carrier:0collisions:0txqueuelen:1000RXbytes:936032419(936.0MB)TXbytes:89178513(89.1MB)Interrupt:17Memory:da000000da012800AndIlearnedthatmyphysicalinterfacesnameis"eth0".Rightnow,Icancreateabridgeadapterandcheckwiththesecommands:support@tester:  VBoxManage modifyvm testMachine --bridgeadapter1 eth0
support@tester:~VBoxManagemodifyvmtestMachinenic1bridgedsupport@tester:  VBoxManage showvminfo testMachine | grep "NIC 1"
NIC 1:           MAC: 080027E31FFE, Attachment: Bridged Interface 'eth0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny
support@tester:~5)CreateanHDDandattachtovirtualmachineusingfollowingcommands:support@tester:  VBoxManage createhd --filename testMachine.vdi --size 18000 --format
VDI0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Disk image created. UUID: 970c500d-2476-44ef-b11b-5938b5150c91

support@tester:~VBoxManagestoragectltestMachinename"SATAController"addsatacontrollerIntelAhcisupport@tester:  VBoxManage storageattach "testMachine" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium testMachine.vdi

and you can find the related information in "VBoxManage showvminfo testMachine" command output:

support@tester:~VBoxManageshowvminfotestMachine......StorageControllerName(0):SATAControllerStorageControllerType(0):IntelAhciStorageControllerInstanceNumber(0):0StorageControllerMaxPortCount(0):30StorageControllerPortCount(0):30StorageControllerBootable(0):onSATAController(0,0):/home/support/testMachine.vdi(UUID:970c500d247644efb11b5938b5150c91)......AlsoyoucanchangesomeofthoseoptionsonHDDspecificationsandcontrollertypeandallofthem.Forexample,youcanselectIDEforSATAinmysample.Orsizeofdiskordiskformat(VDI,VMDK,VHD)etc.Ifyouneed,youcanuse"VBoxManagecreatehd","VBoxManagemodifyhd"or"VBoxManageclonehd"tocreateanewone,modifytheexistingoneorcreateacopyofexistingone...6)Weneedtomountacdromordvdtoourvirtualmachinetostartoperationsysteminstallation.Thefollowingcommandwilldownloadadvdimagefromthedebiansiteanddothatmountingprogress:support@tester:  wget http://cdimage.debian.org/debian-cd/6.0.3/amd64/iso-cd/debian-6.0.3-amd64-netinst.iso

support@tester:~VBoxManagestoragectltestMachinename"IDEController"addidecontrollerPIIX4support@tester:  VBoxManage storageattach testMachine --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium debian-6.0.3-amd64-i386-netinst.iso

When we execute 'VBoxManage showvminfo testMachine | grep "IDE Controller" ' command to check the last step, we should see following output:

support@tester:~VBoxManageshowvminfotestMachine|grep"IDEController"StorageControllerName(1):IDEControllerIDEController(1,0):/home/support/debian6.0.3amd64i386netinst.iso(UUID:cbc7783474344a3caf96858ae1af1731)support@tester: 


7-) Almost all mandatory steps are completed, except "remote display" one.

We haven't got any GUI and we need a monitor to watch virtual machine output! We can use following first command to enable remote display feature and the second command to check the vrde option on our virtual machine.

support@tester:~VBoxManagemodifyvmtestMachinevrdeonsupport@tester:  VBoxManage showvminfo testMachine | grep VRDE

VRDE: enabled (Address 0.0.0.0, Ports 3389, MultiConn: off, ReuseSingleConn: off, Authentication type: null)
VRDE property: TCP/Ports  = "3389"
VRDE property: TCP/Address = <not set>
VRDE property: VideoChannel/Enabled = <not set>
VRDE property: VideoChannel/Quality = <not set>
VRDE property: VideoChannel/Downscale Protection = <not set>
VRDE property: Client/DisableDisplay = <not set>
VRDE property: Client/DisableInput = <not set>
VRDE property: Client/DisableAudio = <not set>
VRDE property: Client/DisableUSB = <not set>
VRDE property: Client/DisableClipboard = <not set>
VRDE property: Client/DisableUpstreamAudio = <not set>
VRDE property: H3DRedirect/Enabled = <not set>
VRDE property: Security/Method = <not set>
VRDE property: Security/ServerCertificate = <not set>
VRDE property: Security/ServerPrivateKey = <not set>
VRDE property: Security/CACertificate = <not set>
VRDE Connection: not activesupport@tester:~WecanboottestMachinebutwehaveonlyonesessionrightonVRDE.Ifweconnecttovirtualmachineremotedisplayfrommorethanoneclients,wehavetochangeMultiConnoptionto"on".Also,iftheport3389isusedbyanotherprocesswehavetochangeit.LetschangetheportandthemultiConnoptionandthencheckitagain,support@tester:  VBoxManage modifyvm testMachine --vrdemulticon on --vrdeport 3390

support@tester:~VBoxManageshowvminfotestMachine|grepVRDEVRDE:enabled(Address0.0.0.0,Ports3390,MultiConn:on,ReuseSingleConn:off,Authenticationtype:null)VRDEproperty:TCP/Ports="3390"VRDEproperty:TCP/Address=<notset>VRDEproperty:VideoChannel/Enabled=<notset>VRDEproperty:VideoChannel/Quality=<notset>VRDEproperty:VideoChannel/DownscaleProtection=<notset>VRDEproperty:Client/DisableDisplay=<notset>VRDEproperty:Client/DisableInput=<notset>VRDEproperty:Client/DisableAudio=<notset>VRDEproperty:Client/DisableUSB=<notset>VRDEproperty:Client/DisableClipboard=<notset>VRDEproperty:Client/DisableUpstreamAudio=<notset>VRDEproperty:H3DRedirect/Enabled=<notset>VRDEproperty:Security/Method=<notset>VRDEproperty:Security/ServerCertificate=<notset>VRDEproperty:Security/ServerPrivateKey=<notset>VRDEproperty:Security/CACertificate=<notset>VRDEConnection:notactivesupport@tester: 


8-) Well. Our Virtual Machine is really ready to boot right now. Let's boot it.

support@tester:~VBoxHeadlessstartvmtestMachineOracleVMVirtualBoxHeadlessInterface4.1.8(C)20082011OracleCorporationAllrightsreserved.VRDEserverislisteningonport3390.Thiscommanddoesnotreleasethetreminalandifwecloseterminalwindoworpress"ctrl+c",thevirtualmachinewillbeaborted.Wewillcomebacktothisbootissueagain.9)ConnecttovirtualmachineviaRDPclient:ismail@ismailThinkPadT410:  rdesktop 172.28.202.216:3390

Autoselected keyboard map en-usWARNING: Remote desktop changed from 800x600 to 640x480.


and you can see something like this :


Ok. Everything is well. But we want to auto start this virtual machine when booting the base operating system that is an Ubuntu server 11.10. In this case we have to write a start-up shell script and apply with updare-rc.d to inittab.

10-) The most important step of writing the start-up shell script is to set the right ownership. Because, we did everything as support user. But root user will execute it, when the base operation system is booting.

#!/bin/bash

u=`/usr/bin/id -u`

case "1"instart)if[u -eq 0 ]; then
             /bin/su support -c '/usr/bin/VBoxHeadless --startvm prxySMS &'
     else
             /usr/bin/VBoxHeadless -startvm testMachine &
     fi
;;
stop)
# something for shutdown virtual machine via vm OS, somehow ..
;;
restart)
# commands for restarting will come here then...hah?
stop
start
;;
status)
# May be shown running process with ps command with "| grep VBoxHeadless"
;;
*)
echo "Usage: /etc/init.d/prxySMS_starter :) [start|stop|restart|status]"
exit 1
;;
esac
exit 0


This file is recorded with the filename "testMachine_starter" in folder /etc/init.d. We give the execution permission using "chmod +x /etc/init.d/testMachine_starter". Now, we have to add it to startup with update-rc.d command like this,

ismail@ismail-ThinkPad-T410:~$  update-rc.d testMachine_starter defaults 95


I put a "95" option in command shown below because I want to start the virtual machine after others. This number part is not necessary.


posted @   张同光  阅读(141)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示