+ Post New Thread
Results 1 to 14 of 14
  1. #1
    Member level 5
    Points: 707, Level: 5

    Join Date
    Mar 2018
    Posts
    88
    Helped
    0 / 0
    Points
    707
    Level
    5

    editing rc.local how to?

    Hi
    I have a custom power pc board which runs linux and would like to auto start an application at boot up. I found several references such as https://unix.stackexchange.com/quest...n-code-on-boot and https://askubuntu.com/questions/9853...run-on-startup. Please clarify which one to follow? The distro in the board is 2.6.34

  2. #2
    Advanced Member level 5
    Points: 17,233, Level: 31
    Achievements:
    7 years registered

    Join Date
    Nov 2012
    Posts
    3,148
    Helped
    777 / 777
    Points
    17,233
    Level
    31

    Re: editing rc.local how to?

    The first link does not work (unix.stackexchange.com) and the second one is clear enough.

    I usually put my stuff in rc.local which is usually empty (dummied) and you need to put your program before the exit(0).

    It should be easy but you have not given any details.



  3. #3
    Member level 5
    Points: 707, Level: 5

    Join Date
    Mar 2018
    Posts
    88
    Helped
    0 / 0
    Points
    707
    Level
    5

    Re: editing rc.local how to?

    The link goes as follows
    https://unix.stackexchange.com/quest...box-after-boot

    I found another link https://www.engineersgarage.com/embe...n-code-on-boot, which says slightly differently than the first one. Are there different ways to make it work? and what additional details do i have to provide?



    •   AltAdvertisement

        
       

  4. #4
    Advanced Member level 5
    Points: 17,233, Level: 31
    Achievements:
    7 years registered

    Join Date
    Nov 2012
    Posts
    3,148
    Helped
    777 / 777
    Points
    17,233
    Level
    31

    Re: editing rc.local how to?

    Yes, all are valid and are different ways to make your app work.

    I use rc.local because it runs last and after the system has fully booted.

    If you can run it from the command line, it will run from the rc.lcoal without fuss.



    •   AltAdvertisement

        
       

  5. #5
    Super Moderator
    Points: 81,430, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,349
    Helped
    4456 / 4456
    Points
    81,430
    Level
    69

    Re: editing rc.local how to?

    The 'systemd' method can start your program as a service. It is basically a small text file containing a link to your application and a list of dependencies so it can work out whether all the necessary support programs are running and if not, start them. It is probably better suited to programs you want to run in the background rather than ones interacting directly with the user but it can do both.

    'rc.local' as c_mitra explained is just a script that runs after a user is logged in. It is just plain text and contains exactly what you would type at a command prompt achieve the same thing. 'rc.local' lives in '/etc' so to edit it you may need root privileges, for example you might need to use 'sudo nano /etc/rc.local' if nano is the text editor you want to use.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisement

        
       

  6. #6
    Member level 5
    Points: 707, Level: 5

    Join Date
    Mar 2018
    Posts
    88
    Helped
    0 / 0
    Points
    707
    Level
    5

    Re: editing rc.local how to?

    Hi Mitra,

    Since I use powerpc which does not have hard-disk, all I have to do is to rebuild rootfs and do suitable modifications in rc.local as you suggested. Now for the steps, please confirm if the following procedure is valid

    1. I place my application (say hello) in /usr/bin directory
    2. I edit rc.local and add line hello &
    3. rebuild rootfs and fuse it into my target
    4. after rebooting, application should auto start

    Is that ok and any other steps



  7. #7
    Advanced Member level 5
    Points: 17,233, Level: 31
    Achievements:
    7 years registered

    Join Date
    Nov 2012
    Posts
    3,148
    Helped
    777 / 777
    Points
    17,233
    Level
    31

    Re: editing rc.local how to?

    I guess so; in case the executable is not in found or you want to be sure, just add the full path before the executable.



  8. #8
    Member level 5
    Points: 707, Level: 5

    Join Date
    Mar 2018
    Posts
    88
    Helped
    0 / 0
    Points
    707
    Level
    5

    Re: editing rc.local how to?

    Hi mitra
    please excuse me. I am reconfirming this because in several links, they talk about permissions to execute the application, create symlink and so on. So I want to absolutely sure that the method indicated in #7 will actually work. Otherwise my experiment will be iterative one trying to figure out the right method



  9. #9
    Super Moderator
    Points: 29,643, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,863
    Helped
    1115 / 1115
    Points
    29,643
    Level
    41
    Blog Entries
    9

    Re: editing rc.local how to?

    they talk about permissions to execute the application
    I usually put all startup routines at the crontab, adding the @reboot prefix, but this file should not be manually eddited, but called from the command line with the sufix -e. It is worthy to be aware that sometimes it is needed to add the sufix sudo before the program/script that is being called there.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  10. #10
    Advanced Member level 5
    Points: 17,233, Level: 31
    Achievements:
    7 years registered

    Join Date
    Nov 2012
    Posts
    3,148
    Helped
    777 / 777
    Points
    17,233
    Level
    31

    Re: editing rc.local how to?

    I am reconfirming this because in several links, they talk about permissions to execute the application,
    It runs when you execute the program from command line, right? Just to confirm, run it as root and verify (sudo su) that it is going to run as root also. If in doubt, change permissions for all (a+x) so that anyone can run it.

    But I admit that I have never build rootfs for another target.



  11. #11
    Member level 5
    Points: 707, Level: 5

    Join Date
    Mar 2018
    Posts
    88
    Helped
    0 / 0
    Points
    707
    Level
    5

    Re: editing rc.local how to?

    Hi mitra

    The proposed method mentioned in #6 actually works like a charm. Now I would like to exit this infinite loop and come back to login prompt. Is there any way to do it?



  12. #12
    Advanced Member level 5
    Points: 17,233, Level: 31
    Achievements:
    7 years registered

    Join Date
    Nov 2012
    Posts
    3,148
    Helped
    777 / 777
    Points
    17,233
    Level
    31

    Re: editing rc.local how to?

    You need to use keypress as a check in the routine. If any key is pressed then exit the routine. Else you can use Ctrl-C to terminate the program. You can also trap Ctrl-C and do something else.



  13. #13
    Member level 5
    Points: 707, Level: 5

    Join Date
    Mar 2018
    Posts
    88
    Helped
    0 / 0
    Points
    707
    Level
    5

    Re: editing rc.local how to?

    Thanks and one last final question. I have to mknode and insmod custom drivers in rc.local. Any proven method? custom drivers are kernel module. Where should I store them and how do i invoke them in rc.local?



    •   AltAdvertisement

        
       

  14. #14
    Advanced Member level 5
    Points: 17,233, Level: 31
    Achievements:
    7 years registered

    Join Date
    Nov 2012
    Posts
    3,148
    Helped
    777 / 777
    Points
    17,233
    Level
    31

    Re: editing rc.local how to?

    You can store them anywhere you like but you must provide the full path.

    By the way, LSB tells which file should be placed where... (https://en.wikipedia.org/wiki/Linux_Standard_Base)

    The usual place is under /lib/modules/ and you will find lots of directories there. Put it in the most appropriate place. It is supposed to look up the right one...

    Loading the driver is the first of a series of steps before you can use the driver well. But that depends on the exact nature of the device (assuming it is a device driver).

    From the I/O point, all device drivers are files: either character or block based. Writing a driver is easy; but writing a driver that works well is going to cost you many nights.



--[[ ]]--