Kamis, 02 April 2015

Virtualbox console


The script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash -ex
#######################################################################
#                                                                     #
# Create Virtualbox VM                                                #
#                                                                     #
# This script creates a simple VM on the Digitesters VirtualBox host  #
# - one CPU, max. capacity 75% of host                                #
# - one network card bridged to LAN, cable connected                  #
# - audiocard to be selected in VM settings below (ac97 or none)      #
# - one SATA hard disk                                                #
# - one IDE DVD player                                                #
# - vrdp enabled (remote desktop) with no authentication              #
#                                                                     #
# Edit the VM settings below before running this script               #
#                                                                     #
#######################################################################
 
 
#######################################################################
### Start of VM Settings                                            ###
### note: do NOT put spaces around the equal sign                   ###
###                                                                 ###
#######################################################################
 
 
## The name of your VM
 
vmname="Win7ult32nl"
 
 
## VM operating system and ISO file
## Run the command "vboxmanage list ostypes |more" to find your Guest OS.
## Use the "ID:" as your ostype. Remember that everything is case-sensitive in linux.
 
ostype="Windows7"
isofile="/data/virtual_machines/vbox/iso_files/Windows7_UltimateNL_32bit_SP1.iso"
 
 
## Memory and video memory in MB
 
memory="2048"
vram="32"
 
 
## Hard disk size in MB
 
hddsize="8192"
 
 
## Vrde port range (RDP)
 
vrdeport="5041-5049"
 
 
## Audio card (select one of the following and comment-out the other)
 
#audio="alsa --audiocontroller ac97"
audio="none"
 
 
 
#######################################################################
### End of VM Settings                                              ###
### you shoudn't need to edit anything beyond this line             ###
###                                                                 ###
#######################################################################
 
 
 
#######################################################################
### Start of script                                                 ###
###                                                                 ###
#######################################################################
 
hddfile=/data/virtual_machines/vbox/vbox_guests/${vmname}/${vmname}.vdi
clear
 
# Create the VM
vboxmanage createvm --name $vmname --ostype $ostype --register
 
# Set memory, vram, audio and vdre port range
vboxmanage modifyvm $vmname --memory $memory --vram $vram --acpi on --ioapic on --cpus 1 --cpuexecutioncap 75 --rtcuseutc on --cpuhotplug on --pae on --hwvirtex on
vboxmanage modifyvm $vmname --nic1 bridged --bridgeadapter1 eth0 --cableconnected1 on
vboxmanage modifyvm $vmname --audio $audio
vboxmanage modifyvm $vmname --vrde on --vrdeport $vrdeport --vrdeauthtype null
 
 
# Create and attach HDD and SATA controller
vboxmanage createhd --filename $hddfile --size $hddsize
vboxmanage storagectl $vmname --name "SATA controller" --add sata
vboxmanage storageattach $vmname --storagectl "SATA controller" --port 0 --device 0 --type hdd --medium $hddfile
 
# Create IDE controller and attach DVD
vboxmanage storagectl $vmname --name "IDE controller" --add ide
vboxmanage storageattach $vmname --storagectl "IDE controller"  --port 0 --device 0 --type dvddrive --medium $isofile
 
#######################################################################
### End of script                                                   ###
###                                                                 ###
#######################################################################
Obviously you will need to change the VM settings to suit the VM that you are going to create.
You may also note that there is no decent error handling built in, other than the -ex parameters added to the top line.
  • -e : In this mode any command your script runs which returns a non-zero exitcode – an error in the world of shell – will cause your script to self-terminate immediately with an error.
  • -x : This will run the entire script in debug mode. Traces of each command plus its arguments are printed to standard output after the commands have been expanded but before they are executed.
As I said, I am not a bash guru. Feel free to use and modify the script to make it your own.

Related articles

sbr:http://www.digitesters.com/manage-a-virtualbox-headless-system-create-a-vm-with-a-script/

Tidak ada komentar:

Posting Komentar