Say You want to add a python program to run when booting of Raspberry Pi without any log in even if power goes and then power comes. First to do this check your python program is working properly. So lets see how to do this :
Go to terminal and type the following : sudo nano /etc/rc.local
You will get a window of rc.local. There you type the command before exit 0 to run the python program. It will be as follows :
sudo python /home/pi/name_of_your_program.py
Here you should care about the directory where your program is. For example if the program is in Desktop put the directory as correct.
Then you follow the simple saving of the rc.local.
Now you reboot your computer, you can see your program is running in the black window where you need not do anything.
But what is the drawback here is you cannot easily stop the program by simply using Ctrl+Z or Ctrl+C or with anything. You may thing it is bad but if you think as you are going to set up our product to a normal home user where he cannot do anything with just stopping using Ctrl+Z or with anything. So how can we do this ?
Yes it can be done with some modifications of the cmdline.txt file in the memory card. For this I come later. Easily you can do this when you switch of and switch on the Raspberry Pi, It will as you to recovery press "Shift". Press Shift and you can see an option "Edit config". Click on that you will get a window of Config Editor where you click cmdline.txt and put the following command at the end of previous commands :
init=/bin/sh ( Note : Do not confuse with / and \)
Now you can Exit and you will will be in black window where you type the following command again :
sudo nano /etc/rc.local
you will get the rc.local window which you have edited before for adding auto start. Now remove the line and save it. Then you ave to shut down the Raspberry and start again. To shut down the RPi sudo halt will or other sudo does not work. Type the following : poweroff -f
No power off and power on the RPi again and by pressing Shift remove the init=/bin/sh and exit. Now you can use RPi as normal one. That's all done!
Note : If you want to edit the cmdfile.txt from accessing memory card, You cannot see the file if you are using it in windows. This is because of partition issues. So you have to put the memory card in any Linux operating systems or Mac.