Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

I run Virtualbox in Headless mode (no screen, all through the command line)

 

With the release of Virtualbox 3.1.* they completely changed the way you create machines, hard drives, disks etc...

 

I wrote a couple of simple bash scripts to help me, thought I would share in case anyone else might find them useful:

 

1) Sata HDD and IDE CD-Rom, Sharing the host network card

 

#!/bin/bash
echo Create New VirtualBox Machine Helper
echo ------------------------------------
echo
echo -n "Enter a name for your machine: "
read MACHINENAME
echo -n "How much RAM should it have? (eg 512): "
read RAM
echo -n "How big HD to create? (eg 10000 = 10gb): "
read HDSIZE
echo -n "Do you need to register a new .iso? (Y/N): "
read REGISO
       if [ "$REGISO" = "Y" ] || [ "$REGISO" = "y" ]; then
               echo -n "Enter .iso file to register, including full path: "
               read NEWISO
               echo Registering new .iso ...
               VBoxManage registerimage dvd $NEWISO
       fi
echo -n "Enter .iso file to use for boot, including full path: "
read ISO
read -p "Press any key to start creating the Virtual Machine "
echo Creating machine...
VBoxManage createvm -name "$MACHINENAME" -register
echo Setting specs...
VBoxManage modifyvm "$MACHINENAME" --memory "$RAM" --acpi on --boot1 dvd --nic1 hostif --hostonlyadapter1 eth0
echo Creating HD Controller..
VBoxManage storagectl "$MACHINENAME" --name "SATA Controller" --add sata --controller IntelAhci
echo Creating HD...
VBoxManage createhd --filename $MACHINENAME --size $HDSIZE --format VDI
echo Registering HD...
VBoxManage storageattach "$MACHINENAME" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium $MACHINENAME.vdi
echo Creating IDE controller for CD/DVD
VBoxManage storagectl $MACHINENAME --name "IDE Controller" --add ide
echo Setting Boot CD...
VBoxManage storageattach $MACHINENAME --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium $ISO
echo All Done...
echo
echo To start the new Virtual machine:
echo "VBoxHeadless -startvm $MACHINENAME"

 

2) IDE Disk IDE CD-Rom, Sharing the host network card

#!/bin/bash
echo Create New VirtualBox Machine Helper
echo ------------------------------------
echo
echo -n "Enter a name for your machine: "
read MACHINENAME
echo -n "How much RAM should it have? (eg 512): "
read RAM
echo -n "How big HD to create? (eg 10000 = 10gb): "
read HDSIZE
echo -n "Do you need to register a new .iso? (Y/N): "
read REGISO
       if [ "$REGISO" = "Y" ] || [ "$REGISO" = "y" ]; then
               echo -n "Enter .iso file to register, including full path: "
               read NEWISO
               echo Registering new .iso ...
               VBoxManage registerimage dvd $NEWISO
       fi
echo -n "Enter .iso file to use for boot, including full path: "
read ISO
read -p "Press any key to start creating the Virtual Machine "
echo Creating machine...
VBoxManage createvm -name "$MACHINENAME" -register
echo Setting specs...
VBoxManage modifyvm "$MACHINENAME" --memory "$RAM" --acpi on --boot1 dvd --nic1 hostif --hostonlyadapter1 eth0
echo Creating IDE HD Controller..
VBoxManage storagectl $MACHINENAME --name "IDE Controller" --add ide
echo Creating HD...
VBoxManage createhd --filename $MACHINENAME --size $HDSIZE --format VDI
echo Registering HD...
VBoxManage storageattach $MACHINENAME --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium $MACHINENAME.vdi
echo Setting Boot CD...
VBoxManage storageattach $MACHINENAME --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium $ISO
echo All Done...
echo
echo To start the new Virtual machine:
echo "VBoxHeadless -startvm $MACHINENAME"

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...