Lesson 4

Date: 2/12/2009
Start-up and Run Levels. Scheduled jobs (at, cron)
Linux for Engineering and IT Applications


Practical Exercises with run levels


Note, during this exercise, you won't be able to run the browser when changing the run levels so you'd better to print out this page. If you like, you can setup CUPS utility on your desktop to print on the Unisys lab printer - follow the printing HOWTO

  • Remove gdm and xserver-xorg-input-wacom from the startup
    update-rc.d -f gdm remove
    update-rc.d -f xserver-xorg-input-wacom remove
    


  • Switching between run levels.

    Create /etc/inittab with the following entries
    id:5:initdefault:
    
    to boot into default Run Level 5; reboot the system using /sbin/init 6 command. When the system boots up, there will be no desktop manager. Login to the system, become root (sudo -s), and verify the current run level with command
    /sbin/runlevel
    
    Change sequentially to Run Levels 3, 2, and 1 using command
    /sbin/init N 
    
    where N is the next Run Level. Run /sbin/runlevel command in every Run Level.

  • Adding and removing system services from the startup

    Remove portmap, nfs-common, nfs-kernel-server, and exim4 from the startup. Note, you can use apt-get install to install them on your system.
    update-rc.d -f portmap remove 
    update-rc.d -f nfs-common remove 
    update-rc.d -f nfs-kernel-server remove 
    update-rc.d -f exim4 remove 
    

    Add portmap, nfs-common and nfs-kernel-server to the startup to start in Level 3 and stop in Levels 0 1 2 6:
    update-rc.d portmap start 20  3 . stop 80  0 1 2 6 .
    update-rc.d nfs-common start 21  3 . stop 79  0 1 2 6 .
    update-rc.d nfs-kernel-server start 21  3 . stop 79  0 1 2 6 .
    

    Add exim4 to the startup to start in Level 2 and stop in Levels 0 1 3 6:
    update-rc.d exim4 start 20 2 . stop 80 0 1 3 6 .
    

    Enter Run Level 3 and check which of the above services are running.
    ps -ef | grep exim
    ps -ef | grep portmap
    ps -ef | grep rpc
    
    Enter Run Level 2 and check which of the above services are running.

  • Creating startup scripts.

    Copy the script from the lecture, sample.sh, in /etc/init.d directory; make it executable; try to run it:
       
       cd /etc/init.d
       wget http://linuxcourse.rutgers.edu/lessons/lesson4/sample.sh
       chmod 755 sample.sh
       /etc/init.d/sample.sh
       /etc/init.d/sample.sh start
       /etc/init.d/sample.sh stop
    
    Create symbolic links of the script to various /etc/rcN.d directories:
       ln -s /etc/init.d/sample.sh /etc/rc1.d/K99sample  
       ln -s /etc/init.d/sample.sh /etc/rc2.d/S01sample  
       ln -s /etc/init.d/sample.sh /etc/rc3.d/K99sample  
    
    Init to Run Levels 1, 2, and 3 and notice if the init runs S01sample and K99sample scripts: check the updated content of file /var/log/sample.log Remove the links. Set the script to "stop" at run level 1, 3, and 5 and "start" at Run Levels 2 and 4:
    update-rc.d sample.sh start 20  2 4 . stop 80  1 3 5 .
    

    Check what kind of links with sample.sh have been created in /etc/rc1.d /etc/rc2.d, /etc/rc3.d, /etc/rc4.d and /etc/rc5.d
    Remove the log file
    rm /var/log/sample.log  
    
    Enter Run Levels 1, 2, 3, 4, and 5. Check the content of file /var/log/sample.log.


  • Take me to the Course Website