[SOLVED] Broken Root? .bashrc not loading


Kosmos

Member
Joined
Apr 10, 2012
Messages
228
IT made me notice that a Root Terminal from NAND gives a # as a prompt but booting to my SD does not when I 'su' in terminal.


I tried creating a .bashrc in /home/root/ but this does not seem to be read. I can not setup root Aliases or custom prompt.

This doesn't seem to be firmware related either, probably something with your SD setup?

OK, Any Ideas on what is broke or how I get a su root to read the .bashrc and give me a custom root environment? I did this with my IRLP Node which runs CentOS 4.8 CLI only. It helps me keep track of who and where I am at the time.


My final solution is post #11 Below...
 
Last edited by a moderator:
Generally (and I'd assume for the Pandora) the root environment is stored in /root/.bashrc, not /home/root/.bashrc. I think the old timey reason behind it is that often on systems you have separate / and /home partitions, so if /home gets borked, you can still do root stuff.


Also, you can type 'source name_of_rc_file' to load a custom config file whenever. Useful if you make a change to /root/.bashrc and want to see the results in the same session.
 
I know that was true of my Centos and Debian systems but wondered where it was. I see no /root on my NAND or SD install. Yet I get a proper # when I su root from NAND but not from the SD.


Where oh where is that little root gone!
 
Thanks. .home/root is correct.


I have a .bashrc in that directory. When I su root I get to root in what ever my current directory is. But the CL prompt does not change unless I manually enter.


source /home/root/.bashrc


On my CentOS and Debian &PCLinuxOS the Root bashrc file is automatically loaded whenever I get to a root cli.


This is useful to see a # at the cli to not do something regretful. among other uses. Like setting up useful aliases.


How do I track down why bashrc is not loading automatically? At least now I know it works.
 
Ok, start from the beginning. How are you getting a root? From the description I am guessing that you created a root password and you are typing "su root" to get a root terminal, correct? This doesn't source any files, it just upgrades you to super user. It's also somewhat dangerous (according to some) to have a root password. A better way of doing it is to run "sudo su". This will source your file and set the command prompt and also uses your current user password instead of the root password which is (supposedly) safer.
 
Yes, that is what I was doing. Here is the catch. If I boot to the NAND I can su to root and I DO get a # prompt until I exit. If I boot to the SD this does NOT happen.


I just tried 'sudo su' and it still does not source .bashrc. I still have to type source /home/root/.bashrc but NOT if I boot to NAND.


I can remove the passwd but I still dont know why this works fine on NAND and not on SD.


I appreciate you helping and am listening.. And enjoying the experience.
 
My guess is a broken install and there is simply a setting missing somewhere. Oh well, someone may have a idea later...


Thanks for your other help though.
 
OK I had an idea. I checked this


$ cat /etc/passwd | grep -i root


root:x:0:0:root:/home/root:/bin/sh


I think that my problem is that the shell is not set to Bash so the bashrc will never be read.


I tried "usrmod -s /bin/bash root" but there is no usrmod command.


What is the Angstrom alternative. And does this seem like the right track?
 
<Well, I still would like to know the angstrom/Pandora alternative to usrmod >


But here is the manual method to fix this.


-------------------------------------------


So my Root was broke and would not source the bashrc file and customize my prompt....


Start by checking the shell type for the user. In my case 'root' was not source-ing the profile when I 'su' to root from a terminal.


I ran the following to check the shell.


$ cat /etc/passwd | grep -i root


and got this:


root:x:0:0:root:/home/root:/bin/sh


AH, could it be? Now is the time to wish you had learned 'vi'


HINTS:


i - enters insert mode to edit the file.


esc - exits insert mode


:wq to save and exit


:q! to just exit


Now to change your shell you must edit the /etc/passwd file and the secret files. But they must be locked out during editing to prevent corruption by other theoretical users.


The best way to edit /etc/passwd, or shadow or group file is to use vipw command. Traditionally (under UNIX and Linux) if you use vi to edit /etc/passwd file and same time a user try to change a password while root editing file, then the user's change will not entered into file. To avoid this problem and to put a lock while editing file, use vipw and vigr command which will edit the files /etc/passwd and /etc/group respectively. If you pass -s option to these command, then they will edit the shadow versions of those files i.e. /etc/shadow and /etc/gshadow, respectively.


The main purpose of locks is to prevent file corruption. Do not use vi or other text editor to edit password file. Syntax:


vipw -s : Edit /etc/passwd file


vigr -s : Edit /etc/group file


This will avoid /etc/shadow file corruption.


Change /etc/passwd 'root' info to this:


root:x:0:0:root:/home/root:/bin/bash


exit and close all terminals. opn a new terminal and su to root. See new prompt!


========================================


Check your files first [see examples below]. mine were also missing!


# ~/.profile: executed by Bourne-compatible login shells.


if [ -f ~/.bashrc ]; then


. ~/.bashrc


fi


# ~/.bashrc: executed by bash(1) for non-login shells.


export PS1='\h@\w/# '


The discovery of vipw was here:


http://www.cyberciti...roup-files.html


The Application and solution to my problem was all here!
 
Last edited by a moderator:
Hmmm, I guess that works. Still seems odd. My root has /bin/sh as its shell and I have no problems getting the # prompt.
 
Well, now that I know aa bit more. I am always game to change it back to /bin/sh and investigate further. But it was a good hack. Maybe someone will have an idea, and maybe not. Eventually I will upgrade the firmware and it will be fixed that way and nothing left to investigate.


Until then, I have my # and a fun day of hacking 'round my system learning. My goal is learning Linux. So things like this are just opportunities for fun. It also makes up for the -not-so-successful attempts at compiling apps from source that ran into sever python problems. Even posting for help did not solve that. So these little successes are a good exchange.
 
It's not really a hack, but a legit modification that i also do after a fresh installation. Although I can't remember having problems with the prompt. I was just too lazy to use "sudo bash" everytime instead of "su". The earlier is the 'normal' way of ending up in a Bourne-again-shell [bash] (in opposite to the Bourne-shell [sh]) when switching to root with sh being the standard-shell.


Also i modified the look of my prompt, because i prefer to see as which user i am logged in on which host, followed by the working-directory and the "#". To do that you must add the following line to your .bashrc (for both: user and root):



Code:
export PS1='\u@\h:\w\$ '


You can set up your own prompt as well. The syntax is described in the "Prompt"-section of the bash-man-page. On a full linux-installation you can read that by running "man bash", but unfortunately the manpages do not exist on the Pandora for some reason (maybe due to size). Still you can search the web for "man bash" (or any other command with "man <command>") in order to read them. They are very helpful while learning Linux, but also may confuse the reader. Especially the bash-man-page is quite massive and holds more information than you can soak up. Learn in small steps.


In this context you still want to read the section about INVOCATION or search the web for the differences between ".bashrc", ".bash_profile" and ".profile".


Maybe something was wrong with your ".profile" that caused the prompt-issue. But all these different files confuse me too. So I'm not sure. I wouldn't be too concerned about it, now that it works for you.


As as sidenote: there's also a difference between running "su" and "su -" (which is explained in the man-page of "su").
 
Last edited by a moderator:
Thanks, that is helpful and I have some books from Oreilly just ordered. It is a trip for a Windows guy having a VOIP running CenntOS and an NAS running Debian. Now the Pandora. Still trying to break out of XP and change my way of doing things. Except for those items that I can only do on XP.


But it is more fun learning by doing. I will check those man pages. It would be nice if Man was installed but I looked at others attempts, Maybe down the road.


I agree with the prompt displaying login info. As my VOIP system can only be maintained from a remote shell so that I made my first change with the prompt so I could keep track of where and who I was.


I am one of those guys that hated to see DOS disappear and Windows became less configurable. Linux gives back the power that was locked behind those gates....


Thanks again.
 
locked behind those gates....

You mean locked behind this Gates? ;)

I picked Those as hoping to be past-tense. that what my Pandora is for. I got Wifi to stop locking up last night. Seems that my 2 routers channels were too close. My laptops had no problem but the Pandora was not separating the signals well. So, I moved the channels further from each other and boosted the power a tad.


So far so good and each day is something new.
 
Well I was hoping that upgrading to SZ 1.5 on my SD would fix this but it seems that the default shell for root is still 'sh' and requires applying the fix above.


Glad I saved it ;-) Cause I had to do it again today! I prefer a red-prompt with a # for my root access as a warning from doing something regretful!
 
Back
Top