VirtualBox on Ubuntu
I recently set up a small cluster consisting of 3 physical low-end machines and containing about 15 virtual ones.
Here are my notes (this is less of a blog post):
Administrating machines with VirtualBox takes some getting used to, so hopefully this will help you getting started.
I recommend (and expect in the following) that you install Vboxtool (http://vboxtool.sourceforge.net/). This will give you a fully automated system that can boot your machines on startup and be administrated through Remote Desktop. But I must admit that I have had some problems during upgrades where I needed to change the vboxtool script myself.
Setting up a new virtual machine (in this case a Windows 2003):
Here I setup a Windows machine with a bridged network adapter. The bridged adapter seemed to give me better performance but YMMV. If you want to use NAT instead you can just omit step 7 and 8.
$ VBoxManage createvm --name "svr1" --register
$ VBoxManage modifyvm "svr1" --memory 1024 --acpi on --boot1 dvd --boot2 disk --hwvirtex on
$ VBoxManage storagectl "svr1" --name "IDE Primary master" --add ide
$ VBoxManage createvdi --filename "svr1_harddrive.vdi" -size 50000 -register
$ VBoxManage storageattach "svr1" --storagectl "IDE Primary master" --port 0 --device 0 --type hdd --medium "svr1_harddrive.vdi"
$ VBoxManage storageattach "svr1" --storagectl "IDE Primary master" --port 1 --device 0 --type dvddrive --medium /home/virtualbox/SW_CD_Windows_Svr_Ent_2003_R2_32-BIT_X64.ISO
$ VBoxManage modifyvm svr1 --nic1 bridged
$ VBoxManage modifyvm svr1 --bridgeadapter1 eth0
$ Now login as a user with root privileges and do...:
sudo vim /etc/vboxtool/machines.conf
Add a line line:
svr1, 3394 (the port is the increment of the one used for the last machine).
Now back to "virtualbox" user.. Run "vboxtool autostart". There is no reason to reboot the machine.
You should be able to connect.
If you need to change the mounted ISO image:
$ VBoxManage openmedium dvd ~/SW_CD_Windows_Svr_Ent_2003_R2_32-BIT_X64.ISO
Remove existing disc:
$ VBoxManage storageattach "svr1" --storagectl "IDE Primary master" --port 1 --device 0 --type dvddrive --medium emptydrive
Add next disk:
$ VBoxManage storageattach "svr1" --storagectl "IDE Primary master" --port 1 --device 0 --type dvddrive --medium ~/SW_CD_Windows_Svr_Ent_2003_R2_32-BIT_X64.ISO
Install additions (will improve performance etc.):
$ VBoxManage storageattach "svr1" --storagectl "IDE Primary master" --port 1 --device 0 --type dvddrive --medium /usr/share/virtualbox/VBoxGuestAdditions.iso
Restart a VM:
$ VBoxManage controlvm svr1 reset
Other useful commands:
$ VBoxManage modifyvm "svr1" --memory 1024 --acpi on --boot1 dvd --boot2 disk --nic1 bridged --hwvirtex on
Find the os type
$ VBoxManage list ostypes
Change the OS type (perhaps to give better compatibility or performance?):
$ VBoxManage modifyvm testubt --ostype Ubuntu
Add an IDE controller (Some scripts use the name "IDE Controller" instead, but it doesn't matter)
$ VBoxManage storagectl "svr1" --name "IDE Primary master" --add ide
And if you need to later remove it again: VBoxManage storagectl svr1 --name "IDE Controller" --remove
Create a hard disk and mount it:
$ VBoxManage createvdi --filename "svr1_harddrive.vdi" -size 6000 -register
$ VBoxManage modifyvm "svr1" --hda "svr1_harddrive.vdi"
If you use Remote Desktop (RDP) it is useful to know that CTRL+ALT+DEL can be faked by entering CTRL+ALT+END. Or windows key + u, or ctrl + shift + esc
Close medium:
$ VBoxManage storageattach svr1 --storagectl "IDE Primary master" --port 0 --device 0 --type hdd --medium none
$ VBoxManage closemedium disk svr1_harddrive.vdi
Reattach medium:
$ VBoxManage modifyvm "svr1" --hda "svr1_harddrive.vdi"
Shutdown:
$ VBoxManage controlvm svr1 poweroff
Close copy / etc...:
1. Copy the harddrive file
2. Create a new virtual machine using VBoxManage or GUI
3. Attach the harddrive
4. Change the mac address?
5. Boot!
Backup:
If you have installed vboxtool. Just run "vboxtool backup" as the virtualbox user.
Network problems:
If you experience problems with network after cloning, then try this:
$ sudo rm /etc/udev/70-persistent-net.rules
Useful references:
Startup script: http://en.gentoo-wiki.com/wiki/VirtualBox#Service
Good scripts link: http://forums.virtualbox.org/viewtopic.php?t=1781
To start / stop services we register them with update-rc deamon
Comments
Post a Comment