Lenovo t410s - Script to switch graphic card at boot

Solaris, RedHat, FreeBSD and the like
Post Reply
Message
Author
gilnarya
Posts: 3
Joined: Fri Jun 11, 2010 7:57 pm
Location: Lausanne, Switzerland

Lenovo t410s - Script to switch graphic card at boot

#1 Post by gilnarya » Tue Jun 15, 2010 8:12 pm

Hello everybody,

I have a lenovo t410s with internal (intel) and discrete (nvidia) graphic card.
I'm running Ubuntuo 10.04 64 bit.

I know that the switchable graphic card is not enable yet and I cannot switch between the two on the fly, without restarting the X server.
However, I'm looking for a script to switch the graphic card at boot time, according to the card selected in the BIOS setting and enable/disable the related driver.

Is it possible?

Thank you very much!

Superego
Sophomore Member
Posts: 239
Joined: Tue Feb 20, 2007 4:05 pm
Location: Minneapolis, MN

Re: Lenovo t410s - Script to switch graphic card at boot

#2 Post by Superego » Thu Jun 17, 2010 1:53 pm

While switchable graphics is long way off you might want to look at this site:
http://linux-hybrid-graphics.blogspot.com/
Another that gives some background info (not necessarily a solution) is on the Gentoo wiki

I don't know of any "script" (or if it's even possible) to detect your BIOS settings and auto-load the correct module.

What I do is create two GRUB entries, one with the radeon driver (or the NVIDIA module in your case) and the other with the intel module. Then I go into BIOS and choose which card I want to use and when GRUB loads I pick the appropriate entry. If you switch a lot this may be a little annoying, but I tend to use my Intel card 90% of the time (heat and battery issues mainly) so it works for me.

Hope this helps.
W510: i7-820QM / 8GB 1066 RAM/ 1 GB NVIDIA Quadro FX 880M / 500GB 7200rpm / 15.6" HD 1080 / Arch Linux

gilnarya
Posts: 3
Joined: Fri Jun 11, 2010 7:57 pm
Location: Lausanne, Switzerland

Re: Lenovo t410s - Script to switch graphic card at boot

#3 Post by gilnarya » Sat Jun 19, 2010 5:25 pm

Thank you very much for your reply!
This is exactly what I would like to have. I use the laptop to work mostly, however sometime it's nice to play a little bit :)

Just another question, about the two entries in the grub that you suggested. How can I do that? :P
Do you any references or maybe your entries as example?

Thank you again!

Superego
Sophomore Member
Posts: 239
Joined: Tue Feb 20, 2007 4:05 pm
Location: Minneapolis, MN

Re: Lenovo t410s - Script to switch graphic card at boot

#4 Post by Superego » Sat Jun 19, 2010 10:32 pm

gilnarya wrote:Just another question, about the two entries in the grub that you suggested. How can I do that?
I'll help out but understand that I'm running Arch Linux so things are going to be slightly differently; mainly what files to modify...other than that the underlying method is the same. There are basically two parts: creating a custom ramdisk and then editing your GRUB entries. Note: All the steps below wiil require root or sudo.

To make a custom ramdisk you'll want to look at the comman mkinitcpio. The Arch Linux wiki page might help, and you may want to look over similar documentation on the Ubuntu forums.

The first thing you need to do is find out where your current modules are being loaded. In Arch Linux /etc/rc.conf contains this but that's fairly unique to Arch Linux...in Ubuntu you probably want to look at /etc/modules. You need to remove whatever your current video module is (NVIDIA or intel....we're going to load it elsewhere).

Next you need to edit /etc/mkinitcpio.conf. It should be in /etc but you may want to double check....also make a backup of your mkinitcpio.conf (e.g. mkinitcpio.conf.orig). The important part of that file is the line

Code: Select all

MODULES="intel_agp i915"
Yours will probably be empty so you'll want to add the appropriate modules It really doesn't matter which graphics module you load, I just went with the intel (i915) because that's one I use the most. The other module is a chipset module that may or may not be needed, depending on your chipset. You may want to test it or see if it is in /etc/modules.

Now that you've added the module(s) to mkinitcpio.conf you'll need to generate the ramdisk. This is done simply with

Code: Select all

# mkinitcpio -p kernel26
I suggest looking over the mkinitcpio documentation (the Arch link above is good) but I'll give a quick description. The -p flag means that you'll be using a preset configuration found in /etc/mkinitcpio.d. Do not mess with the presets.
You now have two images generated by mkinitcpio, /boot/kernel26.img and /boot/kernel26-fallback.img. These are the standard images that you've been using, just with a few extras modules being loaded.

Next you'll repeat the steps but for the other video module. Copy your /etc/mkinitcpio.conf to another name, e.g., /etc/mkinitcpio-nvidia.conf. Simply replace the video module in the MODULE line of your new mkinitcpio.conf. For example:

/etc/mkinitcpio.conf

Code: Select all

MODULES="intel_agp i915"
/etc/mkinitcpio-ati.conf

Code: Select all

MODULES="intel_agp radeon"
Of course yours should contain the NVIDIA modules, but I don't know what they are. Then you generate another ramdisk, but with a slightly different command:

Code: Select all

 # mkinitcpio -c /etc/mkinitcpio-custom.conf -g /boot/kernel26-custom.img
The -c flags tells mkinitcpio which custom conf file to use and the -g flag gives the name of the image that will be created. Make sure to change the names to match your mkinitcpio.conf, e.g.,

Code: Select all

 # mkinitcpio -c /etc/mkinitcpio-nvidia.conf -g /boot/kernel26-nvidia.img
That's the hard part. Now that you have two different images from mkinitcpio we need to modify your GRUB file. Usually this is /boot/grub/menu.lst, but it may vary (e.g. mine is actually /boot/grub/grub.cfg because I'm using a different version of GRUB). Regardless of the fiel, the syntax should be the same. Before I explain, here is my grub.cfg:

Code: Select all

####################
#### BEGIN MENU ####

set timeout=4
set default="0"
set fallback="1"

# Entry 0 - Arch Linux (Intel)
menuentry "Arch Linux (Intel)" --class "arch" {
    set root=(hd0,1)
    linux /boot/vmlinuz26 root=/dev/disk/by-label/Arch_Root resume=/dev/disk/by-label/Swap radeon.modeset=1 acpi_osi="Linux" ro splash
    initrd /boot/kernel26.img
}

# Entry 1 - Arch Linux (Intel Fallback)
menuentry "Arch Linux (Intel) Fallback" --class "arch" {
    set root=(hd0,1)
    linux /boot/vmlinuz26 root=/dev/disk/by-label/Arch_Root ro
    initrd boot/kernel26-fallback.img
}

# Entry 2 - Arch Linux (ATI Video)
menuentry "Arch Linux (ATI)" --class "arch" {
    set root=(hd0,1)
    linux /boot/vmlinuz26 root=/dev/disk/by-label/Arch_Root resume=/dev/disk/by-label/Swap i915.modeset=1 acpi_osi="Linux" ro splash
    initrd /boot/kernel26-ati.img
}

# Entry 3 - Memtest86+
menuentry "Memtest86+" --class "memtest" {
    set root=(hd0,1)
    linux /boot/memtest86+/memtest.bin
}

####  END MENU  ####
####################
The important parts are the lines initrd /boot/kernel26.img, initrd boot/kernel26-fallback.img and initrd /boot/kernel26-ati.img. Change them to match the names of the images you created earlier with mkinitcpio (after you've backed up your original menu.lst).

That should be it! Reboot and select your desired graphics card in the BIOS, then when GRUB loads pick the appropriate GRUB entry. You can check for your card with the command lspci. There should be a line with something like (this is for my ATI card)
01:00.0 VGA compatible controller: ATI Technologies Inc Mobility Radeon HD 3650
If you chose the Intel card the above line should say something like Intel Grapics Controller.

You can also check that the appropriate modules (ATI here in my case) are loaded with lsmod:

Code: Select all

$ lsmod | grep radeon
radeon                707496  2 
ttm                    46389  1 radeon
drm_kms_helper         23796  1 radeon
drm                   160401  4 radeon,ttm,drm_kms_helper
i2c_algo_bit            5031  1 radeon
i2c_core               17959  6 videodev,i2c_i801,radeon,drm_kms_helper,drm,i2c_algo_bit
and you can check that the other module isn't loaded:

Code: Select all

$ lsmod | grep i915
$
Reboot, switch to the other card, and run the same checks as above.

One thing to note is that if you update your kernle you'll have to run mkinitcpio again. The kernel update should use /etc/mkinitcpio.conf by default so all you need to do is rung the command for the custom image.

If I've missed anything or you have questions let me know.
W510: i7-820QM / 8GB 1066 RAM/ 1 GB NVIDIA Quadro FX 880M / 500GB 7200rpm / 15.6" HD 1080 / Arch Linux

gilnarya
Posts: 3
Joined: Fri Jun 11, 2010 7:57 pm
Location: Lausanne, Switzerland

Re: Lenovo t410s - Script to switch graphic card at boot

#5 Post by gilnarya » Sun Jun 20, 2010 8:11 am

Superego, I'm speechless!
Thank you very much for your great help!!!!!!

I will let you know the results! :)

Thank you!

Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Return to “Linux Questions”

Who is online

Users browsing this forum: No registered users and 3 guests