my raspberryPi keeps rebooting and I have no idea how to solve this problem other than recovery the image. I haven't backuped for a while so I prefer not to recover it from an old one.


I added two lines of code in rc.local file hoping to run two python scripts at boot. These two python scripts run in indefinite loops. One of them has a condition. if met, then it will run os.system('reboot now')


After I added the lines and started the system to test it out. Both programs were booted successfully and after the condition was met, the system started to reboot. But it just got stuck in the reboot process and I switched the SD card to another Pi and it is doing the same thing.


Is there a way to enter recovery mode maybe? Or any other ways to stop it from rebooting?

Any suggestions will be appreciated!


Here is python script that reboots the PI once the condition is met

beginTime = time.time()
    while True:
        paths = glob("/home/pi/odas/recordings/cSST*.raw")
        # paths might be empty at the very beginning
        if not paths:
            print("cSST files have been not created yet")
            flagTime = beginTime
            latestFilePath = max(paths, key=os.path.getatime)
            latestFileTime = os.path.getatime(latestFilePath)
            flagTime = latestFileTime

        currentTime = time.time()
        delta = currentTime - flagTime

        if delta > 120:
            os.system("reboot now")

except KeyboardInterrupt:
    print("User interrupt")

So this script is monitoring files in a folder. If 2 minutes have passed and there are no new files being generated then reboot the system

  • Show me your python programs.
    – tlfong01
    Commented Sep 5, 2019 at 1:19
  • 1
    If you have no Linux PC to edit the file with, your best bet is to start up in safemode Commented Sep 5, 2019 at 6:36
  • @tlfong01 I pasted the script. sorry for the late reply
    – Yihan Hu
    Commented Sep 5, 2019 at 15:27
  • #Yihan Hu, No problem. I read your program and found it good, and @goldilocks indeed gave a very good answer with helpful troubleshooting tips.
    – tlfong01
    Commented Sep 6, 2019 at 0:42

2 Answers 2


You can repair most such problems on the Pi by rebooting to a root shell.

  1. Append init=/bin/sh at the end of cmdline.txt and reboot. (This needs to be performed by mounting the SD Card on another computer.)
  2. After booting you will be at the prompt in a root shell.
  3. Your root file system is mounted as readonly now, so remount it as read/write mount -n -o remount,rw /

You can then edit files.

NOTE if you are running NOOBS the appropriate cmdline.txt WILL NOT be in the first partition, but one of the other FAT partitions (depends on what you installed).

  • how do I do step 1 if whenever I plug PI to power, it just reboots?
    – Yihan Hu
    Commented Sep 5, 2019 at 15:19
  • Ah I found some other useful sources that teach you how to do that, I will try it!
    – Yihan Hu
    Commented Sep 5, 2019 at 15:20
  • I tried this method and I kept getting can't find PARTUUID=61f5b861-02, any thoughts?
    – Yihan Hu
    Commented Sep 5, 2019 at 16:57
  • I somehow solved it in this question that I just posted: <raspberrypi.stackexchange.com/questions/102257/…>
    – Yihan Hu
    Commented Sep 5, 2019 at 17:42

this script is monitoring files in a folder. If 2 minutes have passed and there are no new files being generated then reboot the system

To debug this you would need to print flagTime and currentTime to a log when they are initialized. If you had done this, I think you would notice that delta is indeed > 120 seconds even though much less time elapsed between the time.time() calls.

The Pi does not have a built-in real time clock, and depends on a system daemon getting the correct time off the network (after which it can keep time easily). This does not happen instantaneously, and may not happen at all; before that point it uses a somewhat arbitrary value from a previous shutdown, but you should not count on this being anything in particular.

When it does get the real time, it sets the time, which is almost certainly a jump forward that occurs during the boot process, or perhaps even afterward, depending on circumstance and how you want to conceptualize "boot process". While rc.local is supposed to be run near or at the end, "run" refers to starting something, and although it may have started after the network time daemon, it may still be starting before that daemon gets the time, hence a jump in system time may occur while your script is running.

I'm not a python user, but the docs for time.time() indicate it returns seconds since the epoch, which is a calendar time value that will vary if the system clock ("calendar time") is changed. If you want to measure the actual elapsed time avoiding this pitfall, you need to use your own timer, or a time function that uses a monotonic clock guaranteed to be consistent.

  • Ok I will see what happens there. I have now successfully retrieved my system back.
    – Yihan Hu
    Commented Sep 5, 2019 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.