(OK) Creating_VMs_from_an_existing_VDI_file.txt

来源:互联网 发布:dreamweaver破解版mac 编辑:程序博客网 时间:2024/06/04 19:21


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:~$ VBoxManage createvm --name testMachine --ostype Debian --register
Virtual machine 'testMachine' is created and registered.UUID: e2bfd530-14fb-4b8e-8dc2-8523c9bd045e
Settings file: '/home/support/VirtualBox VMs/testMachine/testMachine.vbox'

support@tester:~$


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

support@tester:~$ VBoxManage showvminfo testMachine

Actually, our virtual machine has just been created but It hasn't got any hard drives and some of those settings may not required. For example, the existing virtual machine memory size is 128 megabytes. Probably you want to increase it. You may not want to use NAT mode ethernet device. Right now, let's change some options on our virtual sample.

3-) Change memory and then check it:

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:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:1a:64:5b:60:2c  
          inet addr:172.28.202.216  Bcast:172.28.202.255  Mask:255.255.255.0
          inet6 addr: fe80::21a:64ff:fe5b:602c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2932762 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1149518 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:936032419 (936.0 MB)  TX bytes:89178513 (89.1 MB)
          Interrupt:17 Memory:da000000-da012800

And I learned that my physical interface's name is "eth0". Right now, I can create a bridge adapter and check with these commands:

support@tester:~$ VBoxManage modifyvm testMachine --bridgeadapter1 eth0
support@tester:~$ VBoxManage modifyvm testMachine --nic1 bridged
support@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-) Create an HDD and attach to virtual machine using following commands:


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:~$ VBoxManage storagectl testMachine --name "SATA Controller" --add sata --controller IntelAhci
support@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:~$ VBoxManage showvminfo testMachine
......
Storage Controller Name (0):            SATA Controller
Storage Controller Type (0):            IntelAhci
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0):  30
Storage Controller Port Count (0):      30
Storage Controller Bootable (0):        on
SATA Controller (0, 0): /home/support/testMachine.vdi (UUID: 970c500d-2476-44ef-b11b-5938b5150c91)
......


Also you can change some of those options on HDD specifications and controller type and all of them. For example, you can select IDE for SATA in my sample. Or size of disk or disk format (VDI, VMDK, VHD) etc.

If you need, you can use "VBoxManage createhd", "VBoxManage modifyhd" or "VBoxManage clonehd" to create a new one, modify the existing one or create a copy of existing one...


6-) We need to mount a cdrom or dvd to our virtual machine to start operation system installation. The following command will download a dvd image from the debian site and do that mounting progress:

support@tester:~$ wget http://cdimage.debian.org/debian-cd/6.0.3/amd64/iso-cd/debian-6.0.3-amd64-netinst.iso

support@tester:~$ VBoxManage storagectl testMachine --name "IDE Controller" --add ide --controller PIIX4
support@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:~$ VBoxManage showvminfo testMachine | grep "IDE Controller"
Storage Controller Name (1):            IDE Controller
IDE Controller (1, 0): /home/support/debian-6.0.3-amd64-i386-netinst.iso (UUID: cbc77834-7434-4a3c-af96-858ae1af1731)
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:~$ VBoxManage modifyvm testMachine --vrde on

support@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:~$


We can boot testMachine but we have only one session right on VRDE. If we connect to virtual machine remote display from more than one clients, we have to change MultiConn option to "on". Also, if the port 3389 is used by another process we have to change it. Let's change the port and the multiConn option and then check it again,

support@tester:~$ VBoxManage modifyvm testMachine --vrdemulticon on --vrdeport 3390

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

VRDE: enabled (Address 0.0.0.0, Ports 3390, MultiConn: on, ReuseSingleConn: off, Authentication type: null)
VRDE property: TCP/Ports  = "3390"
VRDE property: TCP/Address = <not set>
VRDE property: VideoChannel/Enabled = <not set>
VRDE property: VideoChannel/Quality = <not set>
VRDE property: VideoChannel/DownscaleProtection = <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:~$


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

support@tester:~$ VBoxHeadless --startvm testMachine

Oracle VM VirtualBox Headless Interface 4.1.8(C) 2008-2011 Oracle Corporation
All rights reserved.

VRDE server is listening on port 3390.

This command does not release the treminal and if we close terminal window or press "ctrl+c", the virtual machine will be aborted. We will come back to this boot issue again.

9-) Connect to virtual machine via RDP client:

ismail@ismail-ThinkPad-T410:~$ 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" in
start)
     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.


0 0
原创粉丝点击