1

I have messed up .bashrc & .profile in ubuntu 12.04 LTS. Can I change it back to previous version from safe mode as I am not able to login to my system and I think this might be the issue

Maythux
  • 84,289

2 Answers2

3

You can do that through safe mode, just need to mount the partition in read-write mode with this command : mount -o remount,rw /. This command is necessary because in recovery mode the Ubuntu portion of hard drive is mounted in read-only mode and you cannot make changes to files. rw option tells ubuntu to allow read-write access to Ubuntu part of the disk. And yes, it is needed before running vim /home/yourusername/.bashrc.

You can get to safe mode aka recovery mode, by selecting "Advanced Options for Ubuntu" in the boot menu, then recovery mode (if you have multiple ones there, don't freak out - any of them is OK). Then access the root shell, and run the command I mentioned above. After that you can proceed with editing .bashrc or .profile with a text editor such as nano or vi

Notice also, that in recovery mode, you don't need sudo as in recovery mode you automatically logged in as root. You will also need to navigate to your nome directory to edit .bashrc or .profile by running cd /home/yourusername Notice that if you are logged in as root sudo ~/.bashrc is for root's .bashrc. Tilde expands to current users' home directory, and if you are logged in as root, it will expand to root's home directory. This is why you need to run vi /home/yourusername/.bashrc

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
  • is mount -o remount,rw / needed before using sudo vim ~/. bashrc ? and why ? – Manish Kumar May 22 '15 at 05:56
  • 1
    @Manish see my edits in the answer – Sergiy Kolodyazhnyy May 22 '15 at 06:00
  • i logged my terminal last time i had run sudo vim ~/. bashrc so which .bashrc was that in recovery mode? sudo vim /home/manish/.bashrc or sudo vim ~/.bashrc ? – Manish Kumar May 22 '15 at 06:09
  • @Manish So if you logged in normally, with graphical stuff, and then opened terminal app in there, that's your home, so sudo vim ~/.bashrc was for you, for /home/yourusername. In recovery mode, you're automatically logged in as root, so ~ means /root folder. In recovery mode vim ~/.bashrc means /root/.bashrc and you don't wanna edit that. sudo means run as root, but in recovery you log in as root. It is kinda same as admin account on Windows. – Sergiy Kolodyazhnyy May 22 '15 at 06:13
  • so in recovery mode i should modify vim /home/manish/.bashrc right ? – Manish Kumar May 22 '15 at 06:16
  • @Manish Yes, exactly right. Could you tell us what exactly you modified in .bashrc and .profile ? Not being logged in might or might not be related to it – Sergiy Kolodyazhnyy May 22 '15 at 06:19
  • actually last night i was trying to add android_home and i started felt sleepy so i guess i did something that i dont know when today i was trying to login my login page was bouncing back after giving correct password also. So i guess there might be some changes in those file – Manish Kumar May 22 '15 at 06:27
  • So you can get to your login screen right ? but not past the login screen ? How about pressing Ctrl+Alt+F2 ? does that bring you to a command line ? can you log in there ? ( by the way , you can go back to graphics from Ctrl + Alt + F2 by pressing Ctrl + Alt +F7 ) . – Sergiy Kolodyazhnyy May 22 '15 at 06:29
  • @Manish if you can login there in Ctrl + Alt + F2 (this is called tty , by the way), then can you please run ls -l .Xauthority ? Bouncing login screen is a common problem when this file gets changed by Ubuntu automatically. Tell us what ls -l . Xauthority tells you . If you see -rw------- 1 root root 201 May 21 22:56 .Xauthority, then this is your main problem, not .bashrc – Sergiy Kolodyazhnyy May 22 '15 at 06:30
  • in that case what will be solution? by the way ctrl+alt+f2 doesnt show anything – Manish Kumar May 22 '15 at 06:39
  • If that is the case, you need to look at this: http://askubuntu.com/q/223501/295286 – Sergiy Kolodyazhnyy May 22 '15 at 06:47
  • 1
    Basically if everything is normal, you should see output of ls -l .Xauthority like this: -rw------- 1 manish manish 201 May 21 22:56 .Xauthority . This is correct. -rw------- 1 root root 201 May 21 22:56 .Xauthority is not correct. You need to change ownership of that file to your username. Like this sudo chown manish:manish /home/manish/.Xauthority – Sergiy Kolodyazhnyy May 22 '15 at 06:50
  • but ctrl+alt+f2 doesnt show anything on login screen page – Manish Kumar May 22 '15 at 06:51
  • @Manish That's unusual. What about others ? Ctrl + Alt + F3 or Ctrl + Alt + F4 ? If you dont' see anything there also, then proceed with recovery mode, forget about Ctrl + Alt + F2 for now. You can look at ls -l /home/username/.Xauthority also. By the way, you noticed that dot before X, right ? it's important to include it – Sergiy Kolodyazhnyy May 22 '15 at 06:56
  • @Manish I will need to leave to sleep now, but I will come back later. I'm currious how your problem gets resolved – Sergiy Kolodyazhnyy May 22 '15 at 06:57
  • What you should be seeing when you press Ctrl + Alt + F2 or F3 shoudl look like this: http://www.labtestproject.com/files/linuse/virtual_terminal/virtual_terminal_tty2_b.png – Sergiy Kolodyazhnyy May 22 '15 at 06:58
  • oki will try and let u know – Manish Kumar May 22 '15 at 07:04
  • I just undo all changes made to my .profile & bashrc file by following your discussion – Manish Kumar May 22 '15 at 16:56
  • Everything works now ? Congrats ! How about ctrl + alt + f2 ? – Sergiy Kolodyazhnyy May 22 '15 at 17:30
  • Yah got my system back. I didnt try ctrl+alt+f2. – Manish Kumar May 22 '15 at 17:36
1

First you have to notice that there is nothing called safe mode in Ubuntu. Here we have Recovery Mode.

And if you mean Recovery mode then I could say you yes you can do what you want and you can edit those .profile and .bashrc files.

You have to notice when running in recovery mode the file system usually mounted in read only mode so you have to remount it with rw.

mount -o remount,rw /

Once you do that you can able to edit the files. and note you dont have to use sudo since you'll be using root. So please be careful not to broke your system, for that I prefer you to use live CD

Or you can also use the Live CD to do the same task. Just mount your harddisk when you boot from live cd then navigate to the files and do what you want to do.

Maythux
  • 84,289