3

I tried to display the list of startup scripts for the current runlevel at bootup. I wrote the following code.

rl=`runlevel | cut -d " " -f2`
ls /etc/rc.d/rc$rl.d/S* | cut -d "/" -f5
sleep 10

It's working if I put this code in rc.local file.

But it's not working if I put it in rc file or in a separate script file abc in /etc/init.d and by creating softlinks in runlevel directories.

But simple commands like follows are able to run in all the methods.

ls /etc/init.d

Do some commands like runlevel or piping won't work unless some of the scripts have started? Or is there something else?

And if I put my code in rc file, my code runs before and after reboot.

  • So what's the difference between rc, rc.local and rc.sysinit files?
  • Where exactly I need to edit those files?

Also I can find S99local -> softlink for rc.local in 2, 3, 4 and 5 runlevels.

Does it mean that rc.local won't run on runlevel 1?

6
  • rc is typically not used by Linux distributions but is used in BSD
  • rc.local is used to be able to execute additional commands during the startup without having to add symlinks.
  • rc.sysinit seems to be Red Hat specific and is executed very early in the process. It is executed as one of the first scripts while rc.local is executed later.

Also I can find S99local -> softlink for rc.local in 2,3,4 and 5 runlevels. Does it mean that rc.local won't run on runlevel 1?

Correct, that means that S99local which is a symlink to /etc/rc.local will be one of the last scripts executed when entering runlevels 2, 3, 4 and 5. It won't get executed for runlevel 1 as 1 is the single user runlevel, typically used for rescue/maintenance work.

  • rc.sysinit is often specified by /etc/inittab to be the first thing run by init. – MrMas Aug 3 '18 at 20:19
0

rc.sysinit is the first script that is executed by the init process. This script is meant to initialise the system and this includes the following:

  • loading kernel modules
  • Setting the hostname
  • Configures kernel parameters from sysctl.conf
  • initialise serial ports, RAID, LVM
  • checks and mounts filesystems (/proc, /sys, and others in /etc/fstab). This is when it remounts the root filesystem with the options specified in /etc/fstab (remember the root filesystem was mounted at /sysroot as read-only by the kernel before the init process was started)

After rc.sysinit executes, the runlevel scripts will then execute (the scripts inside /etc/rc.d/rc3.d/ if the default runlevel is 3).

After the runlevel scripts are done executing, the /etc/rc.d/rc.local script will then execute and this file is where you can put extra start up stuff if you don't wanna do the whole SysV scripts stuff which involves creating symlinks and naming your scripts in a specific format, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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