# [Solved] Boot option to run fglrx or mesa?

## tipp98

I've recently started using softlevels for booting alternate environments, such as console only, or booting up with NetworkManager as an alternate to using the more static /etc/init.d/net.*. Now, as the open source ati drivers are improving, I'd like to be able to toggle between the two depending on my needs or wants. I understand I'll probably need two separate kernels, separate xorg.conf's, and the mysterious eselect opengl. I can deal with these issues on a downward slope. 

1) The kernel will be easy. Just need two.

2) Mesa with run with no xorg.conf but fglrx needs one. Instead of creating a boot script to copy or delete xorg.conf as needed I'd prefer to run with a sole xorg.conf.fglrx and ask gdm to start x with the xorg.conf.fglrx file depending on my runlevel. The variable $XORGCONFIG should be able to accomplish this but I don't know where to put it. I tried XORGCONFIG=xorg.conf.fglrx in /etc/conf.d/xdm.fglrx, but that didn't work.

3) I have no idea what eselect opengl does. Could someone explain this?

Any insight on doing this would be awesome.

KyleLast edited by tipp98 on Thu Jan 27, 2011 1:02 am; edited 1 time in total

----------

## dE_logics

I think XORGCONFIG=xorg.conf.fglrx should be placed in /etc/profiles. Then do an env-update.

What that eselect module does... even I would love to know.

----------

## Fitzcarraldo

Explanation of what eselect opengl set ati|nvidia|xorg-x11 does:

http://www.thinkwiki.org/wiki/Problems_with_fglrx#Gentoo

Symlinks libGL.so.* to either the X.Org OpenGL libraries or closed-source OpenGL libraries.

----------

## tipp98

Thanks for the link Fitz. eselect takes so long I thought it did more.

So now I've got this whipped. Setting XORGCONFIG in /etc/profile does not work because it is blocked out by start-stop-daemon. /etc/init.d/xdm calls /etc/X11/startDM.sh, which does source /etc/profile, but then runs start-stop-daemon to start the display manager. The --env option must be used to pass variables to the executed binary. 

I decided to edit /etc/init.d/xdm instead of creating a separate script, or two. I did this because I was not finding a way to prevent the script from running if xdm was already started. The upside to editing this system script is that it eliminates the need for runlevel configuration as the setup is done based on which kernel is running. A couple caveats here though...

1) The video driver must be built as a module as /proc/modules is used for detection. I'm sure there is a better way of doing this to support in kernel drivers, but this is as smart as I could get. I thought about using /proc/fb, but that requires a frame buffer to be in use.

2) Care must be taken that startx not be run under the wrong setup while in a console only environment.

addition to /etc/init.d/xdm...

```

...

setup_x() {

        DRIVER=$(cut -d" " -f1 /proc/modules | grep -E 'fglrx|radeon')

        ebegin "Setting userspace to use driver $DRIVER"

        case $DRIVER in

        fglrx)

        save_options "xconfig" "XORGCONFIG=xorg.conf.fglrx"

        test "`ls -l /usr/lib/libGL.so|grep ati`" || (eselect opengl set ati)

        ;;

        radeon)

        test "`ls -l /usr/lib/libGL.so|grep xorg`" || (eselect opengl set xorg-x11)

        ;;

        *)

        echo "No driver module detected, check that video drivers are built as modules and that they are defined in /etc/init.d/xdm"

        false

        ;;

        esac

        eend $?

}

#start() {

#        local EXE NAME PIDFILE

#        setup_dm

        setup_x

...

```

and to /etc/X11/startDM.sh

```
...

#export SVCNAME=xdm

#EXEC="$(get_options service)"

#NAME="$(get_options name)"

#PIDFILE="$(get_options pidfile)"

XORGCONFIG="$(get_options xconfig)"

start-stop-daemon --start --env ${XORGCONFIG} --exec ${EXEC} \

${NAME:+--name} ${NAME} ${PIDFILE:+--pidfile} ${PIDFILE} || \

eerror "ERROR: could not start the Display Manager"
```

EDIT: So, I was making the links to libGL manually for speed, but decided using eselect was the more bullet proof method. Also, this may be better off as a separate script run before xdm, but I like it like this. startDM.sh still needs preserved anyway. Hope this is useful to someone else.

Cheers,

Kyle

----------

