HOWTO: Create a boot option for easy dual to single display switching
Contents |
Purpose
So the first question you might have is what is the point of this? Well, this procedure that will be outlined below is intented for laptop users who use their laptop in multiple setups. For instance, I am a Grad student at my local university and I have some lab space where I set my laptop up to have an additional monitor. But in all other locations that I use my laptop I will generally use just the laptop display. Instead of having to go to my nvidia-settings and changing it through that utility everytime I can just select the appropriate boot option in grub and let the script do that tedious bit of work.
Note
Although doing this procedure has a relatively low risk factor, you are doing this AT YOUR OWN RISK. Be smart back up important files.
Runscript
Below is the runscript that will be used in this procedure. It will be given the file name "xdisplay"; however, you can name it whatever you like so long as it does not overwrite an existing file in your /etc/init.d/ folder
#!/sbin/runscript
# To be placed in /etc/init.d/
# Run Command: rc-update add xdisplay boot
depend()
{
need localmount
before xdm-setup
before xdm
before alsasound
}
start()
{
cmdline_display_mode_exist=$(cat /proc/cmdline | grep "display=")
display_mode_dual_exist=$(ls /home/aether/conf/xorg/ | grep "xorg.conf.dual")
display_mode_single_exist=$(ls /home/aether/conf/xorg/ | grep "xorg.conf.single")
cmdline_display_mode=$(cat /proc/cmdline | awk -Fdisplay= '{print $2}' | awk '{print $1}')
if [ -n "$cmdline_display_mode_exist" ]; then
if [ -n "$display_mode_dual_exist" ] && [ -n "$display_mode_single_exist" ]; then
#Choose the xorg file to be copied over
if [ "$cmdline_display_mode" == "dual" ]; then
ebegin "Configuring X display in TwinView mode"
cp /home/aether/conf/xorg/xorg.conf.dual /etc/X11/xorg.conf
else
ebegin "Configuring X display in Standard mode"
cp /home/aether/conf/xorg/xorg.conf.single /etc/X11/xorg.conf
fi
sleep 5
eend 0
else
ebegin "Xorg file missing. Exitting"
eend 0
fi
fi
}
Procedure
So here is what you will need to do to get this to work. This procedure assumes you are currently root.
STEP 1
Make a file that contains the above code. I called this file "xdisplay"
STEP 2
Make two versions of your xorg.conf file; one for single display and one for dual display configuration.
These should be named "xorg.conf.single" and "xorg.conf.dual" respectively.
If you don't know how, best read up cause this isn't the topic of discussion.
STEP 3
Place these in some logical place on your local disk.
In my case, I place them in ~/conf/xorg/
STEP 4
Edit the file that contains the above code to point to those two files.
I.e. Replace all occurances of this path:
/home/aether/conf/xorg/
with the path where those two xorg.conf files are located.
An easy command can do this for you, replacing <YOURPATH> with the full path to the two xorg.conf files you just created:
sed -i "s_/home/aether/conf/xorg/_<YOURPATH>_g" xdisplay
STEP 5
Now, as root, move xdisplay (if not already) to:
/etc/init.d/
STEP 6
Add this to rc-update list. Use the following command as root:
rc-update add xdisplay boot
STEP 7
As root edit your grub menu.lst
vim /boot/grub/menu.lst
or
gedit /boot/grub/menu.lst
STEP 8
Add two more sabayon sections. Just make two copies of your existing one that you normally boot from.
In one case you add the flag:
display=dual
In the other case you add the flag:
display=single
Technically it doesn't matter what you have after "display=" in this case as it default to single if dual is not satified
STEP 9
I suggest you keep your existing section you boot from as the default that way it only bothers copying the xorg files when you need to change modes.
Grub
Here is an example of my menu.lst after configuration
# grub.conf generated by the Sabayon Linux Installer # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,4) # kernel /kernel-genkernel real_root=/dev/VolGroup00/LogVol00 # initrd /initramfs-genkernel #boot=sda default=0 timeout=30 splashimage=(hd0,4)/grub/splash.xpm.gz title Sabayon Linux (genkernel-x86_64-2.6.27-sabayon) (music) root (hd0,4) kernel /kernel-genkernel-x86_64-2.6.27-sabayon music root=/dev/ram0 ramdisk=8192 real_root=/dev/VolGroup00/LogVol00 dolvm quiet init=/linuxrc splash=silent,theme:sabayon CONSOLE=/dev/tty1 vga=0x369 resume=swap:/dev/mapper/VolGroup00-LogVol01 initrd /initramfs-genkernel-x86_64-2.6.27-sabayon title Sabayon Linux (genkernel-x86_64-2.6.27-sabayon) (verbose) root (hd0,4) kernel /kernel-genkernel-x86_64-2.6.27-sabayon root=/dev/ram0 ramdisk=8192 real_root=/dev/VolGroup00/LogVol00 dolvm quiet init=/linuxrc splash=verbose,theme:sabayon CONSOLE=/dev/tty1 vga=0x369 resume=swap:/dev/mapper/VolGroup00-LogVol01 initrd /initramfs-genkernel-x86_64-2.6.27-sabayon title Sabayon Linux (genkernel-x86_64-2.6.27-sabayon) (verbose) (dual) root (hd0,4) kernel /kernel-genkernel-x86_64-2.6.27-sabayon display=dual root=/dev/ram0 ramdisk=8192 real_root=/dev/VolGroup00/LogVol00 dolvm quiet init=/linuxrc splash=verbose,theme:sabayon CONSOLE=/dev/tty1 vga=0x369 resume=swap:/dev/mapper/VolGroup00-LogVol01 initrd /initramfs-genkernel-x86_64-2.6.27-sabayon title Sabayon Linux (genkernel-x86_64-2.6.27-sabayon) (verbose) (single) root (hd0,4) kernel /kernel-genkernel-x86_64-2.6.27-sabayon display=single root=/dev/ram0 ramdisk=8192 real_root=/dev/VolGroup00/LogVol00 dolvm quiet init=/linuxrc splash=verbose,theme:sabayon CONSOLE=/dev/tty1 vga=0x369 resume=swap:/dev/mapper/VolGroup00-LogVol01 initrd /initramfs-genkernel-x86_64-2.6.27-sabayon title Sabayon Linux (genkernel-x86_64-2.6.27-sabayon) (safe mode) root (hd0,4) kernel /kernel-genkernel-x86_64-2.6.27-sabayon root=/dev/ram0 ramdisk=8192 real_root=/dev/VolGroup00/LogVol00 dolvm init=/linuxrc CONSOLE=/dev/tty1 resume=swap:/dev/mapper/VolGroup00-LogVol01 nox acpi=off ide=nodma vga=normal initrd /initramfs-genkernel-x86_64-2.6.27-sabayon title Microsoft Windows Vista Ultimate rootnoverify (hd0,2) makeactive chainloader +1 title Dell Diagnostics rootnoverify (hd0,0) makeactive chainloader +1 }
Optional Wallpaper Feature
If you'd like, you can also create a nice little script to accompany the above runscript. The script below automatically changes the wallpaper based off of which boot entry was chosen. When you log into gnome/kde (or other DE), this script will be run (by adding it to your "SESSIONS" Startup Programs in gnome, or "Autostart" folder in KDE). Just change the "src1" and "src2" variables to be equal to the path where the wallpapers are stored. Make sure you chmod this file as root issuing the command:
chmod 775 myWallpaper.sh
#!/bin/bash
cmdline_display_mode_exist=$(cat /proc/cmdline | grep "display=")
cmdline_display_mode=$(cat /proc/cmdline | awk -Fdisplay= '{print $2}' | awk '{print $1}')
dest="/desktop/gnome/background/picture_filename"
src1="/home/aether/conf/wallpaper/sabayonlinux-widescreen-plain-dual.png"
src2="/home/aether/conf/wallpaper/sabayonlinux-widescreen-plain.png"
if [ -n "$cmdline_display_mode_exist" ]; then
#Choose the wallpaper
if [ "$cmdline_display_mode" == "dual" ]; then
gconftool-2 -t str --set $dest $src1
else
gconftool-2 -t str --set $dest $src2
fi
fi
Hope this is useful to some. Enjoy.
Optionally you can go to [[1]] to see a forum discussion on this or post problems or concerns.
-Aether