Thursday, June 14, 2012

Changing RunLevel



Two sets of init scripts are involved in switching runlevels: K-scripts from the runlevel on which we are currently running and S-scripts from a new (target) runlevel. It is important to understand that there are two runlevels involved in switching:
  • runlevel from which we switch. Let's call it l_from
  • runlevel to which we switch. Let's call it l_to
Simplifying the rc script which is responsible for changing runlevels performs the following two operations.
  1. All K-scripts that exist on the current runlevel l_from are processed. For each K-script for which S-script does not exists at the target runlevel l_to, the  K-script froml_from is executed.
  2. Each S script that exist at target runlevel l_to is executed
In other words when you change the runlevel first stop scripts of the current runlevel are launched, closing down some daemons running on the current runlevel that are not necessary on a new runlevel (do not have S-script defined for them). Then all start scripts of the new runlevel are run in the order defined by their numeric priorities (lexographic order).
For example, the following occurs when changing from runlevel 3 to 5:
  1. The administrator (root) enter the command init 5 which tells init to change the current runlevel to 5. 
  2. The init consults its configuration file (/etc/inittab) and determines it should start /etc/init.d/rc with the new runlevel as a parameter.
  3. Now rc calls all the stop scripts of the current runlevel, but only those for which there is no start script in the new runlevel. In this example, these are all the scripts that reside in /etc/init.d/rc3.d (old runlevel was 3) and start with a K. The number following K specifies the order to start, because there are some dependencies to consider.
  4. The last things to start are the start scripts of the new runlevel. These are, in this example, in /etc/init.d/rc5.d and begin with an S. The same procedure regarding the order in which they are started is applied here.
When changing into the same runlevel as the current runlevel, init only checks /etc/inittab for changes and starts the appropriate scripts. 

Q & A

What CPU(s) is the system running on?
less /proc/cpuinfo

How much RAM does it currently use?
less /proc/meminfo

How much swap space do you have?
free

How many hours has the system been running?
uptime

How will you see all mount points?
cat /proc/mounts

Which filesystems are known by your system?
cat /proc/filesystems

What drivers are loaded?
cat /proc/modules

View all users and groups
cat /etc/passwd
cat /etc/group

Where is the time zone information kept?
cat /etc/sysconfig/clock

Which version of bash is installed on this system?
bash --version

sub-directories of / directory


Directory Content
/bin Common programs, shared by the system, the system administrator and the users.
/boot The startup files and the kernel, vmlinuz. In some recent distributions also grub data. Grub is the GRand Unified Boot loader and is an attempt to get rid of the many different boot-loaders we know today.
/dev Contains references to all the CPU peripheral hardware, which are represented as files with special properties.
/etc Most important system configuration files are in /etc, this directory contains data similar to those in the Control Panel in Windows
/home Home directories of the common users.
/initrd (on some distributions) Information for booting. Do not remove!
/lib Library files, includes files for all kinds of programs needed by the system and the users
/lost+found Every partition has a lost+found in its upper directory. Files that were saved during failures are here.
/misc For miscellaneous purposes.
/mnt Standard mount point for external file systems, e.g. a CD-ROM or a digital camera
/net Standard mount point for entire remote file systems
/opt Typically contains extra and third party software.
/proc A virtual file system containing information about system resources. More information about the meaning of the files in proc is obtained by entering the command man proc in a terminal window. The file proc.txt discusses the virtual file system in detail.
/root The administrative user's home directory. Mind the difference between /, the root directory and /root, the home directory of the root user.
/sbin Programs for use by the system and the system administrator
/tmp Temporary space for use by the system, cleaned upon reboot, so don't use this for saving any work!
/usr Programs, libraries, documentation etc. for all user-related programs.
/var Storage for all variable files and temporary files created by users, such as log files, the mail queue, the print spooler area, space for temporary storage of files downloaded from the Internet,or to keep an image of a CD before burning it.

you were thinking "sh" was the only shell?

sh or Bourne Shell
bash or Bourne Again Shell
csh or C Shell
tcsh or Turbo C Shell
ksh or Korn Shell and much more...

run cat /etc/shells to see the various shells available on your linux installation..

Commonly used commands from shell...

find, grep, which, locate, file, ls, Ctrl+R, echo, export, df, ln, man, pwd,quota, wc ..

chmod - change file permissions
id - displays current user, groups
newgrp - change the group
umask - display standard file permisssion
chown, chgroup - change ownership and group
<command> & - command
bg, fg, kill, jobs - various commands to control job/process
pstree, ps, top - viewing process related commands
fdisk -l | grep Disk - see harddisk size

Running a command at a specified time, using the "at" command. Execution of the job(s) depends on
system time, not the time of submission. atq, atrm, batch
Regularly running a command on a monthly, weekly, daily or hourly basis, using the "cron" facilities

More ways to view file content from shell..

cat, pg, less, more, head, tail ... explore n have fun !

sticky bit mode, suid, sgid - special bit modes on files besides "rwxrwxrwx"

ebook on intro to linux

Read this ebook on getting started..it covers even basics of stuff, but covers some important concepts that need to be understood..
http://tldp.org/LDP/intro-linux/intro-linux.pdf

Tuesday, June 5, 2012

Virtualization Rocks!!


I wanted to try out ubuntu, slitaz and opensuse for some hands on experience.

Oracle Virtual VM box (https://www.virtualbox.org/wiki/Downloads ) helped me a lot. My laptop has good config of RAM and hard disk space and VM box helped me to set up these several instances. Its cool to switch to whichever OS i want to set up and play with.

Virtualization Rocks!!

Boot Linux from USB

Its awesome experience to install slitaz cooking.iso on usb. Set your machine boot device to USB. There you go! The entire process took hardly 10 mins!