raspberry-pi – I have listed exit0 at the end of .profile

Question: Question:

I mistakenly wrote exit 0 at the end of .profile on Raspberry Pi and restarted, but I got into an infinite loop state where I immediately returned to the login screen even after logging in. Is there any way to return to the state of?

Answer: Answer:

For the time being, there are three methods I came up with.

Edit .profile on another machine

Prepare a machine that can mount the Linux partition of the SD card used by the Raspberry Pi.
Connect the SD card to that machine and edit the .profile in question.
(It doesn't have to be a different machine, but you can use the Raspberry Pi if you boot from a different storage than the one in question.)

Boot in single user mode

This is a common recovery method on Linux.
First, start in single-user mode, mount the partition to be modified writably, and work.
The method of booting in single-user mode depends on the boot loader you are using.

In the case of Raspberry Pi, edit cmdline.txt in the SD card boot partition (only this partition is FAT type and can be edited even in Windows etc.), and set it as the kernel boot parameter. It seems common to add init=/bin/sh .

reference:
http://www.programming-knowledge.com/Raspberry_Pi_and_Linux_Tips
http://denki.nara-edu.ac.jp/~yabu/soft/pi.html#50

Work via SSH

If you have already set up to log in with ssh, there are several ways to do it.
for example,

# .profile の読み込みを抑止する
# -t オプションを付けると疑似端末が割り当てられ、画面を制御するコマンドも正常に動くようになるようです
# (metropolis さんのコメント参照)
ssh USER@HOST -t 'bash --noprofile'

# 手元の .profile で上書きする
scp ./.profile USER@HOST:~/.profile

Etc.

Scroll to Top