Please check out my post here:
https://stackoverflow.com/questions/10725867/forcing-monitor-resolution-in-virtualbox-vm-on-linux-guest/10726041#10726041
#!/bin/bash
# Script to automatically resize virtual monitors in VirtualBox
# Start the server
sudo killall VBoxService
sleep 1
sudo VBoxService
sleep 1
# Start the client service
VBoxClient-all
# Get the modeline information we want for the following resolutions:
# 1680x1050@60.00Hz (Laptop display)
RES0="1680 1050 60"
# 1280x1024@60Hz (External monitor)
RES1="1280 1024 60"
# Setup mappings for physical to virtual monitors
MAP0="VBOX0"
MAP1="VBOX1"
# Generate settings
SETTINGS0=$( gtf $RES0 | grep Modeline | cut -d ' ' -f4-16 )
SETTINGS1=$( gtf $RES1 | grep Modeline | cut -d ' ' -f4-16 )
# Get name of modelines from settings
NAME0=$( echo $SETTINGS0 | cut -d ' ' -f1 )
NAME1=$( echo $SETTINGS1 | cut -d ' ' -f1 )
# Echo settings
echo "Modeline for Display 0 ($NAME0): $SETTINGS0"
echo "Modeline for Display 1 ($NAME1): $SETTINGS1"
# Create the new modelines via xrandr
xrandr --newmode $SETTINGS0
xrandr --newmode $SETTINGS1
# Add the newly created modelines to devices
xrandr --addmode $MAP0 $NAME0
xrandr --addmode $MAP1 $NAME1
# Finally, enable the new modes
xrandr --output $MAP0 --mode $NAME0
xrandr --output $MAP1 --mode $NAME1
# Extra: Attempt to run "auto" mode on the external monitor
# This is out last-ditch effort (which worked in this case) to get it running at
# 1600x1200 instead of 1280x1024 :)
xrandr --output $MAP1 --auto --above $MAP0
You can then just put this in your rc file (kderc, gtkrc-2.0, fvwm2rc) to run and then restart the desktop manager. Everything should look great!
Please note that the only extra bit of code in here is the --above $MAP0
argument, which means that the monitor for MAP0 is physically located above MAP0.