Virtualization: VirtualBox

Headless setup

by ross at 07:24:00 on October 28, 2011

Step 1. Create user.

# pw useradd vbox -g vboxusers -m -s /bin/tcsh
# su -l vbox

Run all the other commands as this user. As vbox user doesn't have a password you must run su as root (or via sudo).

To see syntax of any command below, type it without parameters. For example, type «VBoxManage createvm».

Step 2. Create virtual machine.

> VBoxManage createvm --name "win7" \
                      --ostype Windows7_64 \
                      --register \
                      --basefolder /home/vbox

To list ostypes available type «VBoxManage list ostypes».

See the machine parameters:
> VBoxManage showvminfo "win7"
Change some of them:
> VBoxManage modifyvm "win7" --memory 1024 \
                             --cpus 2 \
                             --nic1 bridged \
                             --bridgeadapter1 re1

With this command I increased memory size to 1GB, allowed use of both of my CPU cores and set network card to bridged mode using host's re1 interface. You can replace the last two lines with «--nic1 nat» if NATed mode is enough for you.

If you do use NATed mode then you probably will need to redirect some ports into the guest. You can do it like this:

> VBoxManage modifyvm "win7" --natpf1 rdp,tcp,,3389,,3389

This will redirect connections on port 3389 of host to port 3389 of guest. Run VBoxManage modifyvm to see all the parameters.

Step 3. Create virtual hard drive.

> VBoxManage createhd --filename "/share/vbox/win7.vdi" \
                      --size 30000 \
                      --variant Fixed

As you can see virtual disk can be stored in some other place than the machine. Size is in megabytes. I chosed fixed-size variant here.

Step 4. Initialize VM's storage subsystem.

> VBoxManage storagectl "win7" --name "SATA Controller" \
                               --add sata \
                               --sataportcount 2 \
                               --controller IntelAHCI
> VBoxManage storageattach "win7" --storagectl "SATA Controller" \
                                  --port 0 \
                                  --device 0 \
                                  --type hdd \
                                  --medium /share/vbox/win7.vdi
> VBoxManage storageattach "win7" --storagectl "SATA Controller" \
                                  --port 1 \
                                  --device 0 \
                                  --type dvddrive \
                                  --medium /full/path/to/install.iso

With the above we created SATA controller with two ports: HDD and DVD.

If later you decide to insert another DVD repeat the last command. Guest additions ISO is here: /usr/local/lib/virtualbox/additions/VBoxGuestAdditions.iso.

You might also want to disable host I/O caching:

> VBoxManage storagectl win7 --name "SATA Controller" --hostiocache off

Destroy the virtual machine when you don't need it anymore.

Stop it if it's running:
> VBoxManage controlvm "win7" poweroff
Delete the machine:
> VBoxManage unregistervm "win7" --delete

 

Comments