Skærmopløsning på virtuelle Linux installationer.
Skærmopløsning på virtuelle Linux installationer.
Hvis Open Source versionen af VMware Tools, VMware's propritære version, eller Guest Addition til VirtualBox, ikke er istand til at ændre den virtuelle Linux's skærmopløsning, så skærmen udnyttes maksimalt, så vil disse to bash script formentlig klare opgaven.
Vær venlig at læse og forstå indholdet før de anvendes, for ikke at risikere sort skærm i den virtuelle Linux.
Der er to scripts. Det første med argumenter (ønsket skærmopløsning) til script 2. Script 2 udfører commands til 'xrandr', der styrer opløsningen i den virtuelle Linux.
Før du begynder, skal du køre 'xrandr' (uden flag) fra terminalen på hosten, for at læse den fysiske skærms opløsninger. Vælg de parametre du ønsker den virtuelle Linux skal have, og erstat dem med de angivede nederst i script 1.
Script 1 kan navngives valgfrit. Script 2 bør navngives 'xrandr.sh' for ikke at ændre i koden. Begge script skal befinde sig i samme mappe 'change-res', og igen, for ikke at ændre koden, i '~/progs/change-res/'. Disse to mapper skal du selv oprette i 'home' på den virtuelle Linux.
Script 1 skal tilføjes til den virtuelle Linux's 'Opstart program'. Det medfører at scriptet køres under Logon, og vil derefter ændre skærmopløsningen til det ønskede.
Gør begge scripts executable, enten fra terminalen: sudo chmod +x 'filename' eller fra GUI.
Når du er færdig, genstart den virtuelle Linux.
#!/bin/bash
# Script 1 - Needed to be added to the Linux upstart app (whatever it's called), so it's starting during Logon.
# This bash script specifies the argument to the 'xrandr.sh' script, which changes the xrandr screen resolution to fit a screen with an unusual resolution on a Virtual Linux.
# The path must be adapted according to where both scripts are located. Here it is in a 'change-res' folder which is in a 'progs' folder, placed within 'home' on the virtual machine.
# Note that you must not change to a screen resolution that is not supported by the physical screen. If you do, you risk a black screen.
# The argument below '1600 900 59.88' is probably not the same as yours.
# Run 'xrandr' with no flags on the host, to show the supported resolutions on your physical screen. Then change the arguments to fit your physical screens supported resolutions within the virtual Linux.
# The called script is here named 'xrandr.sh'.
# NOTE: Change the resolution below, according to the preferably from running 'xrandr' on the host.
cd ~/progs/change-res/
./xrandr.sh 1600 900 59.88
--------------
#!/bin/bash
# Script 2 - xrandr.sh
# If no argument is specified, ask for it and exit
if [[ -z "$@" ]];
then
echo "An argument is needed to run this script";
exit
else
arg="$@"
# Basic check to make sure argument number is valid. If not, display error and exit
if [[ $(($(echo $arg | grep -o "\s" | wc --chars) / 2 )) -ne 2 ]];
then
echo "Invalid Parameters. You need to specify parameters in the format \"width height refreshRate\""
echo "For example setResolution \"1600 900 59.88\""
exit
fi
# Save stuff in variables and then use xrandr with those variables
modename=$(echo $arg | sed 's/\s/_/g')
display=$(xrandr | grep -Po '.+(?=\sconnected)')
if [[ "$(xrandr|grep $modename)" = "" ]];
then
xrandr --newmode $modename $(gtf $(echo $arg) | grep -oP '(?<="\s\s).+') &&
xrandr --addmode $display $modename
fi
xrandr --output $display --mode $modename
# If no error occurred, display success message
if [[ $? -eq 0 ]];
then
echo "Display changed successfully to $arg"
fi
fi
- Log in to post comments
Kommentarer