Showing posts with label LINUX BASIC. Show all posts
Showing posts with label LINUX BASIC. Show all posts

Saturday, 21 November 2015







A runlevel is one of the modes that a Unix -based operating system will run in. Each runlevel has a certain number of services stopped or started, giving the user control over the behavior of the machine. Conventionally, seven runlevels exist, numbered from zero to six.
After the Linux kernel has booted, the init program reads the /etc/inittab file to determine the behavior for each runlevel. Unless the user specifies another value as a kernel boot parameter, the system will attempt to enter (start) the default runlevel.



Standard run levels for Red Hat based distributions
Run Level
Mode
Action
0HaltShuts down system
1Single-User ModeDoes not configure network interfaces, start daemons, or allow non-root logins
2Multi-User ModeDoes not configure network interfaces or start daemons.
3Multi-User Mode with NetworkingStarts the system normally.
4UndefinedNot used/User-definable
5X11As runlevel 3 + display manager(X)
6RebootReboots the system
Most Linux servers lack a graphical user interface and therefore start in runlevel 3. Servers with a GUI and desktop Unix systems start runlevel 5. When a server is issued a reboot command, it enters runlevel 6.

Init scripts

Init (short for initialization) is the program on Unix and Unix-like systemsThe Init is the parent of all processes with PID # 1.
The /etc/inittab file is used to set the default run level for the system. This is the runlevel that a system will start up on upon reboot. The applications that are started by init are located in the /etc/rc.d folder. Within this directory there is a separate folder for each run level, eg rc0.d, rc1.d, and so on.


Linux Find Out Current Run Level Command

Type the following command:
$ who -r

Linux Change Run Level Command

Use the init command to change rune levels:
# init 1On most Linux server system default run level is 3 and on most Linux Desktop system default run level is 5. The default run level is defined by the initdefault line at the top of /etc/inittab file under CentOS / Fedora / Redhat / RHEL / Debian Linux. To change the default run level, edit /etc/inittab file, and edit entry initdefault:
# vi /etc/inittab
Set initdefault to 5, so that you can boot to X next time when Linux comes up:
id:5:initdefault:
Save and close the file. Reboot the system to see changes:
# reboot

Identifying Services that Start at Each Runlevel

There are number of ways to identify which services get started without having to delve into the /etc/rc.d sub-directories. The command line tool chkconfig (usually located in the /sbin directory) can be used to list which services get started at boot time. To list all service settings run the following command:
/sbin/chkconfig --list



First we Need To Know About Inodes   
Hard links and soft link is an important concept in the Linux file system, which relates to the index node in the file system (inode). Inode is one of the four basic concepts in Linux virtual file system (VFS). Through the analysis of the relation and the difference between hard links and soft links, we can better understand Linux VFS.
We know that the file has file name and data, which is divided into two parts: user data and metadata. The user data, namely the file data blocks (data block), data block is a place that store the real content. metadata is additional properties of file, such as: file size, created time of file, owner information of file. In Linux, the inode in the metadata, (inode is a part of the file metadata but which do not contain a file name, inode, namely the inode number) is uniquely identifies of the file rather than the file name. The file name is only for memory and is convenient for people to use. through the inode number, system can find the correct file data block. The below figure shows how the program obtain the contents of the file by file name.
open file
In order to solve the problem of file sharing, Linux system introduce two links: hard link (hard link) and soft link (also called a symbolic link). A link will resolve file sharing for the Linux system. If a inode is correspond to multiple file name, said these files as hard links. In other words, a hard link is the same file with multiple aliases. Hard links can be created by the command link or ln.
Soft link is a common file, there is only a little special for the content of data block. A soft link has its own inode number and the user data block , pls see the below figure. So soft link is created without many restrictions similar with hard links:
  • A soft link has its own file attributes and authority
  • You can create a soft link to the file or directory does not exist
  • A soft link can cross file system
  • Soft links can be created to the file or directory
  • Create a soft link, link count i_nlink does not increase
  • Removing the soft link does not affect the pointed file, but the original file if it is to be deleted, then the soft links is called the dead link
hard_soft_link





Q. What is the one line answer to the question “What is the main difference between hard links & soft links” ?
A. A softlink will have a different Inode number than the source file, which will be having a pointer to the source file but hardlink will be using the same Inode number as the source file.
Q. How can I find all the Soft Links in my system ?
A. Use this command for the same “find /etc -type l -exec ls -li {} \;”
Q. How can I find all the files having Hard Links in my system ?
A. Use this command for the same “find / -links +2 -type f -exec ls -li {} \;”
Q. How to find whether a file is a softlink ?
A. Simply using this command “ls -l” will tell you whether a file is pointing to some other file or not.
Q. How to check whether a file have any softlink pointing to it ?
A. Till now, I am not aware of any way to do that. If I will find any, I will surely update my post.
Q. How can I find out the source file of a hard link ?
A. No, you can’t find out the source file of a hard link. Once hard link is created, there is no way to tell which was the first file created.
Q. Can I make a Soft link to a Hard link and Vice Versa ?
A. Yes, both soft links and hard links acts as normal files of the file system, so you can do both.

How file is deleted having hard links:

So, as it’s pretty clear from the above article that hard links are just the reference to the main file location, and even if you delete one link, the data will still be intact. So, to remove a hard link, you need to remove all the links, which are referring to the file. Once the “link count” goes to “0”, then the inode is removed by the filesystem, and file is deleted.

When to use Soft Link:

  1. Link across filesystems: If you want to link files across the filesystems, you can only use symlinks/soft links.
  2. Links to directory: If you want to link directories, then you must be using Soft links, as you can’t create a hard link to a directory.

When to use Hard Link:

  1. Storage Space: Hard links takes very negligible amount of space, as there are no new inodes created while creating hard links. In soft links we create a file which consumes space (usually 4KB, depending upon the filesystem)
  2. Performance: Performance will be slightly better while accessing a hard link, as you are directly accessing the disk pointer instead of going through another file.
  3. Moving file location: If you move the source file to some other location on the same filesystem, the hard link will still work, but soft link will fail.
  4. Redundancy: If you want to make sure safety of your data, you should be using hard link, as in hard link, the data is safe, until all the links to the files are deleted, instead of that in soft link, you will lose the data if the master instance of the file is deleted.

Hard Links in Linux

Soft Links on Linux


PRACTICAL:


Symbolic links are created with the “ln” command in linux. The syntax of the command is:
$ ln -s
-s = This flag tells to create a symlink (if you don’t use this it will create a hard link, which we will talk about soon).
For Example, if you want to create a soft link of one fo your favorite application, like gedit, on your desktop, use the command like this:
$ ln -s /usr/bin/gedit ~/Desktop/gedit
I hope now the concept of Soft Links should be clear.

You can create a hard link with the same command “ln” like this
# ln
So, to create a hard link of gedit program on your desktop, you will use the command like this:
# ln /usr/bin/gedit ~/Desktop/gedit
Now, the bigger question is, who will decide what is better and when to use soft link or hard link
NOTE: The only information not included in an inode, is the file name and directory. These are stored in the special directory files.

Monday, 2 November 2015







• Red Hat Enterprise Linux (Refer previous lesson)
• Fedora Linux (Refer previous lesson)
• Ubuntu: Ubuntu is considered to be the most popular Linux distributions and it was first announced in September 2004. The brain behind Ubuntu is Mark Shuttleworth who is a South African technocrat.
Ubuntu web site: http://www.ubuntu.com/
Pros: Great community of users and developers, great documentation, up to date packages, fast release cycle.
Cons: Some of Ubuntu's own software are proprietary.
• SuSE Linux (Now under Novell): SUSE (Software und System Entwicklung) project was started in 1992 by four German Linux enthusiasts Roland Dyroff, Thomas Fehr, Hubert Mantel and Burchard Steinbild.
SUSE web sites: SUSE web site: http://www.novell.com/linux/ and http://www.opensuse.org/
Pros: Up-to-date, easy to use, good looking, stable.
Cons: Speed and performance.
• Mandriva (Before Mandrake): Mandriva Linux was launched by Gael Duval in July 1998 under the name of Mandrake Linux. At first, it was just a re-mastered edition of Red Hat Linux with the more user-friendly KDE desktop, but the subsequent releases also added various user-friendly touches. Mandriva headquarters is located at Paris.
Mandriva web site: http://www.mandriva.com
Pros: Highly up-to-date, easy to use, good looking desktop, good community support.
Cons: Unstable, releases are initially reserved to mandrivaClub members and then made public after several weeks.
• Debian: Debian is one of the oldest and stable GNU/Linux distributions. It was created in 1993 by Ian Murdock who named it after the combination of his own name and his girlfriend Debra.
Pros: Open-Source philosophy, non-commercial project, strong community, huge selection of packages and supported architectures, one of the best package management, excellent documentation, extremely stable and well-tested releases, modular, fast.
Debian web site: http://www.debian.org/
Cons: Slow release cycle, text-based installer, lack of configuration tools
• CentOS: CentOS is a community project (launched in 2003) with the goals of rebuilding the source code for Red Hat Enterprise Linux (RHEL) into an installable Linux distribution and to provide timely security updates for all included software packages. We can say CentOS is a clone of RedHat Enterprise Linux.
CentOS web site: http://www.centos.org/
Pros: Extremely well-tested, stable and reliable; free to download and use; comes with 5-years of free security updates; prompt releases and security updates
Cons: Lacks latest Linux technologies.
• Knoppix (Live CD): Knoppix is a live CD version of Linux. Knoppix can be run in a machine with out installing it.
Knoppix web site: http://www.knoppix.net/
Pros: Live Distribution, If the hardware is atleast 4 years old, then knoppix is a viable choice of installing and using Linux.
Cons: Knoppix is optimized for use as a live distro. So when installed on the hard-disk will boot up a bit slower than other distributions.

KERNAL - SHELL CONCEPT






The UNIX operating system is made up of three parts; the kernel, the shell and the programs.

The kernel

The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs and handles the filestore and communications in response to system calls.
As an illustration of the way that the shell and the kernel work together, suppose a user types rm myfile (which has the effect of removing the filemyfile). The shell searches the filestore for the file containing the program rm, and then requests the kernel, through system calls, to execute the program rm on myfile. When the process rm myfile has finished running, the shell then returns the UNIX prompt % to the user, indicating that it is waiting for further commands.

The shell

The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell. The shell is a command line interpreter (CLI). It interprets the commands the user types in and arranges for them to be carried out. The commands are themselves programs: when they terminate, the shell gives the user another prompt (% on our systems).
The adept user can customise his/her own shell, and users can use different shells on the same machine. Staff and students in the school have thetcsh shell by default.
The tcsh shell has certain features to help the user inputting commands.
Filename Completion - By typing part of the name of a command, filename or directory and pressing the [Tab] key, the tcsh shell will complete the rest of the name automatically. If the shell finds more than one name beginning with those letters you have typed, it will beep, prompting you to type a few more letters before pressing the tab key again.
History - The shell keeps a list of the commands you have typed in. If you need to repeat a command, use the cursor keys to scroll up and down the list or type history for a list of previous commands.



What is Linux Shell ?

Computer understand the language of 0's and 1's called binary language.
 
In early days of computing, instruction are provided using binary language, which is difficult for all of us, to read and write. So in Os there is special program called Shell. Shell accepts your instruction or commands in English (mostly) and if its a valid command, it is pass to kernel.

Shell is a user program or it's environment provided for user interaction. Shell is an command language interpreter that executes commands read from the standard input device (keyboard) or from a file.
Shell is not part of system kernel, but uses the system kernel to execute programs, create files etc.
Several shell available with Linux including:



how i can find the available shells in my linux machine?

>>> $ cat /etc/shells









UNIX development was started in 1969 at Bell Laboratories in New Jersey. Bell Laboratories was (1964–1968) involved on the development of a multi-user, time-sharing operating system called Multics (Multiplexed Information and Computing System). Multics was a failure. In early 1969, Bell Labs withdrew from the Multics project.
Bell Labs researchers who had worked on Multics (Ken Thompson, Dennis Ritchie, Douglas McIlroy, Joseph Ossanna, and others) still wanted to develop an operating system for their own and Bell Labs’ programming, job control, and resource usage needs. When Multics was withdrawn Ken Thompson and Dennis Ritchie needed to rewrite an operating system in order to play space travel on another smaller machine (a DEC PDP-7 [Programmed Data Processor 4K memory for user programs). The result was a system called UNICS (UNiplexed Information and Computing Service) which was an 'emasculated Multics'.
The first version of Unix was written in the low-level PDP-7 assembler language. Later, a language called TMG was developed for the PDP-7 by R. M. McClure. Using TMG to develop a FORTRAN compiler, Ken Thompson instead ended up developing a compiler for a new high-level language he called B, based on the earlier BCPL language developed by Martin Richard. When the PDP-11 computer arrived at Bell Labs, Dennis Ritchie built on B to create a new language called C. Unix components were later rewritten in C, and finally with the kernel itself in 1973.
Unix V6, released in 1975 became very popular. Unix V6 was free and was distributed with its source code.
In 1983, AT&T released Unix System V which was a commercial version.
Meanwhile, the University of California at Berkeley started the development of its own version of Unix. Berkeley was also involved in the inclusion of Transmission Control Protocol/Internet Protocol (TCP/IP) networking protocol.
The following were the major mile stones in UNIX hostory early 1980's
• AT&T was developing its System V Unix.
• Berkeley took initiative on its own Unix BSD (Berkeley Software Distribution) Unix.
• Sun Microsystems developed its own BSD-based Unix called SunOS and later was renamed to Sun Solaris.
• Microsoft and the Santa Cruz operation (SCO) were involved in another version of UNIX called XENIX.
• Hewlett-Packard developed HP-UX for its workstations.
• DEC released ULTRIX.
• In 1986, IBM developed AIX (Advanced Interactive eXecutive).

Popular Posts

Recent Posts

Unordered List

Categories

Text Widget

Powered by Blogger.

Home - PageNavi (show/hide)

Ads

Pages