I had made a script and I wanted it to run on startup so I included it in /etc/rc.local. But I had forgotten that at the end of the script I have it set to shut the pi completely. And so now whenever I turn on the pi, it runs through the script and shutdown. I need to make a change to the code, is there any way for me to access the script via the sd card rather than actually turning it on. Or can I bypass the startup script? Thanks in advance.
-
3Does this answer your question? Autorun Script Now Automatically Shuts Down– Steve RobillardCommented Feb 23, 2022 at 21:26
-
2Another alternative would be to put the SD card in a Linux machine (including a live DVD version or another Pi) and edit the file.– Steve RobillardCommented Feb 23, 2022 at 21:28
1 Answer
Requirements
- Another computer running Linux OR another MicroSD card to boot the Raspberry Pi with.
- MicroSD card reader
Steps
- Shutdown the Raspberry Pi (Done!)
- Pull out the boot media, in this case the MicroSD card.
- Put the card in another computer running Linux using the MicroSD card reader.
This can be another Raspberry Pi with an USB MicroSD card reader. In this case, boot your Raspberry Pi with the second MicroSD card that does not have the script. Put the first MicroSD card (with script) into the USB card reader and plugin the USB card reader into your Raspberry Pi.
- Mount the
ext4
partition in the MicroSD card to a suitable mount point, if the partitions in the card is not mounted automatically. - Navigate to
/media/username/A_bunch_of_letters_and_numbers/etc/rc.local
and edit (and save) the script. - Unmount or "Eject" the card so that it can be safely removed.
Done.
Note, if you only have a Windows 10/11 computer, the same thing can be done with Windows Subsystem for Linux (WSL). However, mounting the MicroSD card partitions in WSL is not simple.
A Note on Temporarily Running Linux on your PC
Most current Linux installation USBs allow running the OS without installing it into the internal disks. Here I will use the example of Raspberry Pi OS for PC as you should be familiar with its interface.
- Download Raspberry Pi OS for PC from https://www.raspberrypi.com/software/raspberry-pi-desktop/
- See https://www.techrepublic.com/article/how-to-run-raspberry-pis-raspbian-os-on-a-pc/ for how to create an installation USB from the downloaded file.
- Use the Run Without Persistence option to start the OS directly from the USB without installing. Do not choose Graphical Install if you don't want to install the Pi OS on your computer.
Note, you can also use the Run With Persistence option. For this purpose it does not matter.
Follow the steps above.
Hope this helps
-
1Thank you! This seems like something that could work. One additional question though if you don't mind. Would Kali Linux be a suitable option for this procedure?– MohammadCommented Feb 24, 2022 at 0:05
-
1@Mohammad Any current version of Linux distribution should work. Choose the one you are most familiar with. If you have Kali installed use it. You can even use the Raspberry Pi OS for PC. I mention "Raspberry Pi OS for PC" because I assume you are familiar with its desktop user interface. Commented Feb 24, 2022 at 12:28