Saturday, February 12, 2011

Fundamentals of Linux

Fundamentals of  Linux 
In this tutorial I will cover some general technical concepts that relate to Linux. You will need this information to understand and perform an installation, which I will cover in the next article. This tutorial covers some of the major terms used in Linux, as well as the fundamentals of how the system operates. Finally I discuss partitioning and formatting of file systems.Linux is a different than Windows, and therefore a lot of the terminology changes as well. Listed below are some terms that you must know to effectively learn Linux, along with a general definition of each.

    * Unix: Refers to a classification of operating system, not a specific version or vendor’s operating system. Sun Solaris, SCO Unix, FreeBSD, and Linux are all types of Unix.
    * Linux: A specific implementation of Unix, written using open source code and protected under the GPL.
    * Distribution: A specific vendors implementation of Linux. Consists of the core Linux kernel and a collection of utilities and applications provided by the vendor. Many distributions also contain an implementation of XWindows.
    * XWindows: The common name for XFree86.
    * XFree86: A series of programming models and libraries that are used to provide a GUI desktop that runs on Linux. Gnome and KDE are all built on the XFree86 model. A desktop consists of two things – the window manager which provides for the operation of the GUI, and the desktop environment, which is a collection of GUI based tools and provides a look and feel. Gnome and several others use SawFish as the Window manager, KDE provides it’s own, called KWM.
    * Kernel: The core of Linux. The Kernel controls access to the processor and controls the execution of processes on the computer. The kernel is a single file, usually stored in the /boot folder and can be upgraded independently of the Operating System. All distributions of Linux use the same Kernel.
    * Root: The “super-user” account. All Linux systems have a root user account that has unlimited access to the systems resources. It can also refer to the root of the file system, denoted by “/”.
    * Daemon: A service that runs on a Unix computer. Daemons typically listen to a TCP/IP port for network requests and then respond. Servers are collections of daemons. Some examples of daemons include named (Name Daemon or DNS), telnetd (Telnet Daemon), inetd (Internet Daemon), and httpd (Web Server Daemon).
    * Process: An instance of an application that runs on a Unix computer. A server that provides HTTP services and Telnet services has a process for both httpd and telnetd.
    * Shell: A command interpreter, commonly accessible through a text terminal (command prompt). Different shells have different capabilities and limitations. Some examples include the Bourne Shell (sh), the Bourne Again Shell (bash), the Korn Shell (ksh) and the C Shell (tcsh). Most Linux distributions install multiple shells, with bash being the shell activated by default. You can activate another shell by typing it’s name, assuming it’s installed.
    * Shell Script: A series of shell commands saved in a file. Similar to a Batch file in DOS, but with more functionality. Commands available in Shell Scripts are dependant on the shell they are written in. The C Shell allows C language code to be written in Shell Scripts, while bash is limited to basic conditional logic and file manipulation. Many of the core functions on a Linux system are nothing more than complex shell scripts.
    * Open Source: Applications that are open source make the source code freely available for modification and redistribution by anyone. Open source code is protected by the GPL.
    * GPL: General Protection License – mandates that open source code may be freely modified and redistributed provided that all modifications to code are distributed as well. This means that if an organization used open source code in an application, although they many resell the application for profit, they must also provide the source code of the application at no charge.

General Operation of a Linux System

    * In Linux, everything is oriented around the Kernel. In fact, what makes Linux Linux is the fact that is uses the Linux Kernel. The Kernel is a single file that consists of core functions and references to modules and is normally stored in the /boot directory. Modules can be compared to device drivers. In order for a Linux computer to recognize a sound card, for example, the module for that sound card must be registered with the Kernel. Modules are files nested in the /lib/modules directory.
    * The Kernel controls all activity on a Linux system. It co-ordinates all Input/Output functions and acts as an interface to the hardware. The Kernel is developed separately from any specific distribution of Linux and is maintained at www.kernel.org. From there you can download and upgrade you Kernel at will. Normally, there is no reason to do this, as most distributions of Linux release new versions in loose conjunction with Kernel releases.
    * In order to fully understand the operation of a Linux system, you must understand how basic Input/Output is accomplished. Everything in Linux is a file. This is important to understand when we deal with devices (hardware). For example, a typical configuration will have a file name /dev/fd0. This file equates to your floppy drive. When an application wishes to read the floppy drive, or write to the floppy drive, it reads from/writes to the file /dev/fd0. The same is true for all other devices as well. For every piece of hardware on your system, there is a file that corresponds to that device, and those files are mainly stored in the /dev (device) directory. One other example is the file /dev/eth0, which represents your primary network card. When I want to transmit on the network I simply write to the file that corresponds to the network card.
    * Conceptually, this can all be tied to together. When an application wants to transmit data on a network, that application knows that it simply writes the data to the file /dev/eth0. The Kernel has the module that corresponds to the network card loaded, and is monitoring the file eth0. As data is written to the file, the Kernel translates that into something the hardware can understand and instructs the hardware to send the bytes over the network.

Configuring a Linux System

    * In Windows, the Registry is an all in one database that contains the system configuration. You cannot simply run an application by copying the files to a given location. The application must first register itself with the system to function, and this registration information is stored in the registry. Linux is based entirely on files, and the simple presence or absence of files means a great deal. Linux uses a method of operation known as Late Binding. What this means is that applications generally do not require that things be present until they are needed. When an application runs, and needs configuration information, it simply looks in a preconfigured place for a preconfigured file, and if the file is there, and contains the information required, the application runs. If the file is not then the application does not run.
    * All configuration of a Linux system is manipulation of text files, either directly or indirectly. Many current distributions have collections of utilities that provide a graphical front end to file modification commands. Many installation programs run wizard like scripts that prompt you for information that is simply fed into file modification commands.
    * A simple example of this is the file /etc/fstab. This text file stands for “file systems at boot” and contains a list of the file systems that are stored on the computer and which directory then can be accessed from. When a change is made to the disk configuration this file needs to be updated. There are two ways this can be accomplished. First of all you can run a graphical disk administration utility that will modify your file systems and then write all changes to the appropriate places, or secondly, you can make command prompt based modifications, and manually edit the fstab file. Either way accomplishes exactly the same thing
    * Another example of this is the configuration of XWindows, your GUI. When the setup wizard prompts you for information on your monitor, video adapter and desired screen settings. All this information is saved to a text file that is read when XWindows is booted and from there your GUI is displayed. A simple edit in this file can adjust the display of XWindows. For those of you that are more familiar with Windows, you can compare the general setup of Linux to a system based on .INI files.

File Systems, and Partitions
The methods employed by Unix to construct a file system which consists of file systems, partitions and directories can be confusing when viewed for the first time. First of you must understand some simple facts:

    * A computer can only have 4 “real” partitions, called primary partitions.
    * If a system requires more than 4 partitions, then one of the 4 primaries must be converted to an extended partition.
    * An extended partition cannot directly contain files; it can only contain links to other logical partitions whose sum total size cannot exceed that of the extended partition.
    * Each partition in Linux can be identified by a file that corresponds to the partition; these files follow a specific naming convention, which I will address in a later article.

    * In Unix, primary partitions are always numbered 1 through 4, this number included your extended partition as well. Any logical partitions that are created within the extended partition are numbered 5 and up. For example, a system with 2 primaries and an extended that contains 2 logical partitions would have partitions 1, 2, 3, 5, and 6. Another system with a single primary, and an extended containing 1 logical partition would have partitions 1, 2, and 5. Note that when you partition a Linux system you have the ability to choose the numbers of your partitions. For example, the same system with 1 primary and a logical partition in the extended could have partitions 2, 4, and 5. You cannot control the numbering of logical partitions.
    * When partitions are created, they must be created to hold a specific type of data, or for a specific type of operating system or file system. This is done by using a code to denote the partition type. Many utilities do this for you. DOS FDisk for example, is only able to create partitions that are FAT16, or FAT32. Below is a screen shot of a partition type listing from the Linux FDisk utility. Note the various types of partitions and the corresponding hexadecimal codes.
    * On Linux, you will commonly use partition types 82, 83, and 85. When you are installing Linux, you will use this utility to create partitions and set types.
    * Finally you must place a file system on a partition. File systems and partition types are independent of each other – sort of. The type of partition you create does not force you to use a specific type of filesystem, but it does limit your choices as the partition must support the file system you wish to place on it. For example, partition type 83 – Linux can contain several different file systems including Ext2 and the newer Ext3, but cannot contain the FAT file system. You place the file system on the partition when you format it.

I hope you find it useful for you