Prob in writting a shell script for creating a VM with OS

Discussions related to using the OSE version of VirtualBox.
Post Reply
Anupambrt
Posts: 16
Joined: 4. Sep 2011, 09:47
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: Ubuntu 11.04, OpenSuse 11.04

Prob in writting a shell script for creating a VM with OS

Post by Anupambrt »

Hello friends,
I know it sounds very stupid but i am a beginner at working with CLI. I have .iso of os and now i want to install it in VM, I want to know what should I do after the instruction below

Code: Select all

#!/bin/bash
#Create vm
VBoxManage createvm --name "Ubuntu12" --ostype Ubuntu --register

#Allocate all appropriate parameters
VBoxManage modifyvm Ubuntu_64 --memory 128 --boot1 dvd --boot2 disk --clipboard bidirectional
VBoxManage modifyvm Ubuntu_64 --vram 64
VBoxManage modifyvm Ubuntu_64 --acpi on
VBoxManage modifyvm Ubuntu_64 --cpus 3 --ioapic on
VBoxManage modifyvm Ubuntu_64 --vram 32
VBoxManage modifyvm Ubuntu_64 --vrde on
VBoxManage modifyvm Ubuntu_64 --vrdeport 3390
VBoxManage modifyvm Ubuntu_64 --vrdeaddress 192.168.0.137
VBoxManage modifyvm Ubuntu_64 --usb off
VBoxManage modifyvm Ubuntu_64 --audio none
VBoxManage modifyvm Ubuntu_64 --nic1 bridged
VBoxManage modifyvm Ubuntu_64 --bridgeadapter1 eth0
VBoxManage modifyvm Ubuntu_64 --nictype1 Am79C973
VBoxManage modifyvm Ubuntu_64 --cableconnected1 on
VBoxManage storagectl Ubuntu_64 --name "IDE Controller" --add ide
VBoxManage createhd --filename ~/.VirtualBox/Ubuntu_64_hdd.vdi --size 4096
VBoxManage storageattach Ubuntu_64 --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium ~/.VirtualBox/Ubuntu_64_hdd.vdi

what I am trying to do is I am writting a shell script because of which a VM with OS is created.... that's why I need this...

thank you in advance...
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Prob in writting a shell script for creating a VM with OS

Post by Sasquatch »

I've made it into a code block so it's easier to read.

So the script is partly done. You just need to load the ISO and start it. What you may have to change is to put the NIC configuration on one line, instead of several. What's also not right is that you first create a VM called Ubuntu12, and modify a VM called Ubuntu_64. Not going to work. If the OS is going to be 64 bit, you need to change the OS type from Ubuntu to Ubuntu_64. That will set a few things right for use of 64 bit Guest OS. Else the VM won't boot because it can't see the 64 bit part.
VRDP address isn't required, if none is given, it will listen to all interfaces and IP addresses on the Host. Useful if the Host has a dynamic address.

Note that with the script you have now, is you create a VM, but you don't install it yet, nor do you start it.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
Anupambrt
Posts: 16
Joined: 4. Sep 2011, 09:47
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: Ubuntu 11.04, OpenSuse 11.04

Re: Prob in writting a shell script for creating a VM with OS

Post by Anupambrt »

Thanks Sasquach for reply...

Code: Select all

#!/bin/bash

#Create vm
VBoxManage createvm --name Ubuntu_$1 --ostype Ubuntu_64 --register


#Allocate all appropriate parameters
VBoxManage modifyvm Ubuntu_$1 --memory 128 --boot1 dvd --boot2 disk --clipboard bidirectional

VBoxManage modifyvm Ubuntu_$1 --vram 64

VBoxManage modifyvm Ubuntu_$1 --acpi on

VBoxManage modifyvm Ubuntu_$1 --cpus 3

VBoxManage modifyvm Ubuntu_$1 --ioapic on

VBoxManage modifyvm Ubuntu_$1 --vram 32

VBoxManage modifyvm Ubuntu_$1 --vrde on

VBoxManage modifyvm Ubuntu_$1 --vrdeport 3390

VBoxManage modifyvm Ubuntu_$1 --vrdeaddress 192.168.0.137

VBoxManage modifyvm Ubuntu_$1 --usb off

VBoxManage modifyvm Ubuntu_$1 --audio none

VBoxManage modifyvm Ubuntu_$1 --nic1 bridged

VBoxManage modifyvm Ubuntu_$1 --bridgeadapter1 eth0

VBoxManage modifyvm Ubuntu_$1 --nictype1 Am79C973

VBoxManage modifyvm Ubuntu_$1 --cableconnected1 on

VBoxManage storagectl Ubuntu_$1 --name "IDE Controller" --add ide

VBoxManage createhd --filename ~/.VirtualBox/Ubuntu_$1_hdd.vdi --size 4096

VBoxManage storageattach Ubuntu_$1 --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium ~/.VirtualBox/Ubuntu_$1_hdd.vdi

VBoxManage storageattach Ubuntu_$1 --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium '/home/anupam/Desktop/ubuntu-11.04-desktop-i386.iso'

VBoxHeadless --startvm Ubuntu_$1


I am able to start desktop through

Code: Select all

rdesktop -a 16 <ip>:port
but my problem is I am not getting OS installation options which I should, right?
I am giving the screenshots ... and basically i don't want to install os through GUI, whenever i run the shell script I must get a vm started with OS installed...
so what should i do?
Thank you in advance n again thank you for reply....
Last edited by Anupambrt on 5. Sep 2011, 11:40, edited 1 time in total.
Anupambrt
Posts: 16
Joined: 4. Sep 2011, 09:47
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: Ubuntu 11.04, OpenSuse 11.04

Re: Prob in writting a shell script for creating a VM with OS

Post by Anupambrt »

This is the screen shot of terminals...
Attachments
This line is missing in screenshot but is there in terminal...<br />VRDE server is listening on port 3390
This line is missing in screenshot but is there in terminal...
VRDE server is listening on port 3390
untitled.PNG (115.67 KiB) Viewed 4807 times
Last edited by Anupambrt on 5. Sep 2011, 11:43, edited 2 times in total.
Anupambrt
Posts: 16
Joined: 4. Sep 2011, 09:47
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: Ubuntu 11.04, OpenSuse 11.04

Re: Prob in writting a shell script for creating a VM with OS

Post by Anupambrt »

this is screen shot after rdesktop command...
Attachments
untitled1.PNG
untitled1.PNG (13.28 KiB) Viewed 4807 times
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Prob in writting a shell script for creating a VM with O

Post by Sasquatch »

Few things I find odd:

Code: Select all

VBoxManage modifyvm Ubuntu_$1 --vram 64
[...]
VBoxManage modifyvm Ubuntu_$1 --vram 32
First you give it 64 MB VRAM, then you change it to 32 MB. Set it once.

Code: Select all

VBoxManage createvm --name Ubuntu_$1 --ostype Ubuntu_64 --register
VBoxManage modifyvm Ubuntu_$1 --memory 128 --boot1 dvd --boot2 disk --clipboard bidirectional
[...]
VBoxManage storageattach Ubuntu_$1 --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium '/home/anupam/Desktop/ubuntu-11.04-desktop-i386.iso'
You create a 64 bit VM, give it only 128 MB RAM and load a 32 bit OS ISO. It's contradicting each other in many ways. A 64 bit Guest usually gets way more RAM than 128 MB and you would not install a 32 bit OS on a 64 bit defined VM.

Code: Select all

VBoxManage modifyvm Ubuntu_$1 --cpus 3
You give it 3 CPU cores, great. But even though you set the Guest to 64 bit, which should already enable hardware virtualisation, you never specify it. If the VM is going to be 32 bit, this needs to be set specifically.
Anupambrt wrote:but my problem is I am not getting OS installation options which I should, right?
Yes, you should, but only if things sum up correctly and they don't.

Before scripting the whole thing, I would first run each command manually on the shell and see what you get. Then when things work, you automate it into a script.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
Post Reply