Tuesday, 12 April 2011

Root's bash profile not working when su

A reaccuring annoyance for me is getting root's bash_profile to work, and everytime I fix it, I promptly forget what I did, so here's a post for me to refer to if noone else!

Things like the users PATH and other environment variables can be set up in a file in their home directory called .bash_profile. If they're using the Bourne Again Shell then this file gets read when they login, and any commands in it are run to set up their environment. But in my experience it never works for root.

There's a difference between root and other users though, I almost never login as root, I login as another user and then 'su' to root. Turns out that an 'su' doesn't count as a login, and '.bash_profile' only gets read and run for login shells. If other types of shell get started up, say by being launched from a program or whatever, then another file '.bashrc' is read instead. So, if I put the same commands in /root/.bashrc that I normally would in /home/user/.profile, then they will work when I 'su'.

Finally there are 'global' bashrc and profile files that can be put in /etc, and these will be run for all users before any profile or bashrc in their home directory is run. Note that these files don't have the leading '.', so instead of /home/user/.bashrc, it's /etc/bashrc. And for the profile, it's /etc/profile instead of /etc/bash_profile as you might expect! Oh, and finally, these global files don't seem to work for /root.

So, to get the PATH and prompt etc set for everyone, create /etc/profile for all users but root, and then copy it to /root/.bashrc, and /root/.bash_profile and that should cover 'su' and 'login' shells for root too.

Monday, 4 April 2011

Nvidia drivers fail without 'smp_lock.h'

If you install a very recent kernel from www.kernel.org, and then try to install the NVIDIA graphics drivers, you may find that the driver install fails. The NVIDIA installer actually compiles the drivers against your kernel source tree, but recent kernels seem to have dropped a file that's called 'smp_lock.h'. Unable to find this file that it expects to have, the NVIDIA driver compile process fails.

A quick and dirty solution that worked for me was to simply locate 'smp_lock.h either under /usr/include/linux, or in an old kernel source tree, and drop it into the include/linux directory of your new kernel source tree. If you can't get a copy of a the file, then try making an empty file with the same name, I think even that will probably work. You should then find that the NVIDIA install process gets by that hurdle at least. It worked for me!