Thursday, August 2, 2007

What is Linux?

Linux is an operating system that evolved from a kernel created by Linus Torvalds when he was a student at the University of Helsinki. Generally, it is obvious to most people what Linux is. However, both for political and practical reasons, it needs to be explained further. To say that Linux is an operating system means that it's meant to be used as an alternative to other operating systems like MS-DOS, the various versions of MS Windows, Mac OS, Solaris and others. Linux is not a program like a word processor and is not a set of programs like an office suite.
A brief history of Linux

When Linus Torvalds was studying at the University of Helsinki, he was using a version of the UNIX operating system called 'Minix'. Linus and other users sent requests for modifications and improvements to Minix's creator, Andrew Tanenbaum, but he felt that they weren't necessary. That's when Linus decided to create his own operating system that would take into account users' comments and suggestions for improvements.
Free Software pre-Linux
This philosophy of asking for users' comments and suggestions and using them to improve computer programs was not new. Richard Stallman, who worked at the Massachusetts Institute of Technology, had been advocating just such an approach to computer programming and use since the early 1970's. He was a pioneer in the concept of 'free software', always pointing out that 'free' means 'freedom', not zero cost. Finding it difficult to continue working under conditions that he felt went against his concept of 'free software' he left MIT in 1984 and founded GNU. The goal of GNU was to produce software that was free to use, distribute and modify. Linus Torvalds' goal 6 years later was basically the same: to produce an operating system that took into account user feedback.
The kernel

We should point out here that the focal point of any operating system is its 'kernel'. Without going into great detail, the kernel is what tells the big chip that controls your computer to do what you want the program that you're using to do. To use a metaphor, if you go to your favorite Italian restaurant and order 'Spaghetti alla Bolognese', this dish is like your operating system. There are a lot of things that go into making that dish like pasta, tomato sauce, meatballs and cheese. Well, the kernel is like the pasta. Without pasta, that dish doesn't exist. You might as well find some bread and make a sandwich. A plate of just pasta is fairly unappetizing. Without a kernel, an operating system doesn't exist. Without programs, a kernel is useless.
1991, a fateful year

In 1991, ideal conditions existed that would create Linux. In essence, Linus Torvalds had a kernel but no programs of his own, Richard Stallman and GNU had programs but no working kernel. Read the two men's own words about this:

Linus: "Sadly, a kernel by itself gets you nowhere. To get a working system you need a shell, compilers, a library etc."

RMS: The GNU Hurd is not ready for production use. Fortunately, another kernel is available. [It is called] Linux.

So combining the necessary programs provided by GNU in Cambridge, Massachusetts and a kernel, developed by Linus Torvalds in Helsinki, Finland, Linux was born. Due to the physical distances involved, the means used to get Linus' kernel together with the GNU programs was the Internet, then in its infancy. We can say then that Linux is an operating system that came to life on the Internet. The Internet would also be crucial in Linux's subsequent development as the means of coordinating the work of all the developers that have made Linux into what it is today.
Linux is introduced
Late in 1991, Linus Torvalds had his kernel and a few GNU programs wrapped around it so it would work well enough to show other people what he had done. And that's what he did. The first people to see Linux knew that Linus was on to something. At this point, though, he needed more people to help him. Here's what Linus had to say back in 1991.

"Are you without a nice project and dying to cut your teeth on an OS you can try to modify for your needs?... This post might just be for you."

People all over the world decided to take him up on it. At first, only people with extensive computer programming knowledge would be able to do anything with that early public version of Linux. These people started to offer their help. The version numbers of Linux were getting higher and higher. People began writing programs specifically to be run under Linux. Developers began writing drivers so different video cards, sound cards and other gadgets inside and outside your computer could use Linux. Nevertheless, throughout most of first part of the 1990's Linux did not get out of the 'GURU' stage. GURU is a term that has evolved to mean anyone who has special expertise in a particular subject. That is, you had to have special expertise in how computers worked to be able to install Linux in those days.
Linux, at first, not for everybody

Other popular software companies sold you a CD or a set of floppies and a brief instruction booklet and in probably less than a half an hour, you could install a fully working operating system on your PC. The only ability you needed was knowing how to read. Those companies had that intention when they actually sat down and developed their operating systems. Linus Torvalds didn't have that in mind when he developed Linux. It was just a hobby for him. Later on, companies like Red Hat made it their goal to bring Linux to the point where it could be installed just like any other operating system; by anyone who can follow a set of simple instructions, and they have succeeded. For some reason, though, Linux hasn't completely lost its 'Gurus only' image. This is largely because of the popular tech press' inability to explain in a meaningful way what Linux is. The truth is that few tech reporters have real life experience with Linux and it is reflected in their writing.
Linux Today

Today, Linux is enjoying a favorable press for the most part. This comes from the fact that Linux has proven to be a tremendously stable and versatile operating system, particularly as a network server. When Linux is deployed as a web server or in corporate networks, its down-time is almost negligible. There have been cases when Linux servers have been running for more than a year without re-booting and then only taken down for a brief period for routine maintenance. Its cost effectiveness has sold it more than anything else. Linux can be installed on a home PC as well as a network server for a fraction of the cost of other companies' software packages. More reliability and less cost - it's ideal.

If you're reading this, you're obviously here to learn how to use Linux. Any learning experience means opening up to new ideas and new ways of doing things. As mentioned before, Linux is in the UNIX family of operating systems. UNIX is primarily designed to be used by professionals. You will have to learn some UNIX concepts in this lesson, but that doesn't mean that Linux is a professionals-only operating system. In fact, most major versions of Linux are designed to be as user-friendly and as easy to install as any other operating system on the market today.

Now that you know what Linux is and how good it is, there's one more thing we have to do - install Linux!

Installing Linux

Some preliminary considerations.
There are many different versions of Linux. Unlike other commercial operating systems that are controlled by one company, Linux is free to distribute and use. So, in the Linux world, there is a situation unlike what occurs in the proprietary operating system world: a number of companies, organizations and individuals have developed their own "versions" of the Linux operating system, known as distributions. There are versions of Linux that were developed to be installed on computers that receive heavy traffic, so to speak, like webpage servers. Some were developed to be used in networks where security is a priority; where sensitive information should only be accessed by a privileged few. There are versions of Linux that are meant to be installed on top of an existing operating system like Windows so people can try out Linux under familiar conditions. There are versions of Linux that are designed to be installed on platforms like Macintosh. There are versions of Linux with funny names like "Chainsaw Linux" (no kidding) and "Tutti-Frutti Linux" (yes, it's a joke)
What Linux is right for me?

This is a very difficult question to answer. To use an analogy, if I were going mountain climbing, I would need specific clothes to protect me from scrapes, the cold, wind, rain and other adverse climactic conditions. If I were going to a formal dinner, I would need a tuxedo. If I were going about my daily routine, I would wear "normal" clothes. There are computer world equivalents of mountain climbing and formal dinners as well as just sitting around the house. Linux has been fit into all those environments and more. There is even the equivalent of a swimsuit in Linux - a very scaled down version - just to cover the essentials.

Most PC users probably just need the everyday version. This kind of Linux has been widely available for some time now. Since Microsoft makes its living selling people "ordinary" operating systems, they have a lot to lose if Linux ever gets popular with the masses. For this reason they have done everything in their power to "warn" the public that Linux is something that you probably don't want and don't need. But in reality, Linux is just as easily installed and supports just as wide a range of hardware as Microsoft Windows does. The PR department at Microsoft is coming up with fewer and fewer reasons not to use Linux.
Linux on PCs containing Intel-based CPUs
It would be impossible to cover all of the different types of Linux so this lesson will only deal with standard versions of Linux that are meant to be installed on PCs with Intel-based CPUs. You may have heard of some of the companies and organizations that have created distributions for this platform, like Debian, Mandrake, Red Hat and SuSE . There are others as well. There are even versions of Linux that offer documentation and install programs in languages other than English. We should say here that it is not our intention to endorse the products of the companies we have mentioned here nor do we want to slight those companies that we haven't mentioned.

Linux Online maintains a list of all kinds of distributions. We invite you to consult that list before deciding on installing any version of Linux.
Prepare your manuals
As we mentioned before, the major versions of Linux have perfected their products to such a degree that they are very easy to install. Well designed programs will take you through the process of installation step by step so that you will be able to get Linux up and running in a relatively short period of time without any headaches. But even commercial operating systems that are billed as being the most user-friendly in the world can't guarantee a 100% problem-free installation.

The best thing to do before attempting to install Linux is to get the manuals that came with your PC out of the closet and dust them off. Major distributions of Linux have taken into account most standard hardware such as video cards, modems and sound cards, but as we said before, nobody can guarantee a problem-free installation for any operating system. Though you probably won't need them, they may help to track down a problem or prevent a future one. Now, go get those manuals, and we'll meet you in the next lesson!

Partitioning

Your hard disk is like a pie. You can divide it into sections. Unlike a pie, after you've divided it, you can't give a piece to the dog. My dog did try to eat my hard disk once and he really relishes the floppies I leave lying around, but alas, I digress. For example, if you had two partitions, popular operating systems would generally call them C and D. You can call them Ginger and Fred, or Ginger and Marianne or even the Professor and Marianne if you like. I just use these bad jokes as a way of saying that C and D are naming conventions that belong to other operating systems. Linux doesn't use them. Linux may call them /hda3 and /hda5 for example. We'll get to that in a minute. Then you will need another partition known as a 'swap' partition. This 'swap' partition is just a way that Linux uses to get more memory so that you don't run out of it.

The classic way of partitioning your hard disk is with a program called 'fdisk' The program comes with a lot of whistles and buzzers and flashing messages that say "Danger, Will Robinson". There's a version for Linux but it doesn't mention Will Robinson. We want to say here that this is the SWAT team method of doing it - the scorched-earth policy of partitioning. If you have that important term paper on your hard disk, or pictures of that dream vacation to Hawaii that you haven't shown to your Aunt Betty yet or your best DOOM scores, you'll need to make back-up copies of them. The re-partioning using this method will get rid of them - forever! [cue ominous organ music].

But installing Linux isn't dangerous and if you choose to install you may not need such a drastic solution to your partition problem. As we mentioned before, If you're fortunate enough to have a hard drive with more than one partition (the old C: and D: routine), then it may be just a question of moving some files around. Unfortunately this lesson can't take into account everybody's individual circumstances.

There's a tool called FIPS that comes with major Linux versions. This will re-arrange your hard drive so you can install Linux. There are also other commercial products that will do the same. That may be an option for you, unless you've got a hard drive that's bursting at the seams. You should know that any decent working Linux system - and by decent, I mean, having the programs that will let you do anything you did with your Windows system- will take at least 2 gigabytes. Please keep that in mind. And if you want those photos of Hawaii on there, I'd plan for a bit more

To talk about where Linux and other operating systems should go. In any situation where you've got two things sharing the same space, like two people sharing the same apartment, one person will always exert his rights over the other. Other operating systems usually want to be the only ones in the computer, so even though it's really not going to be this way, you have to install them in the first 'primary' partition, and that way it thinks it's the only one there. That means installing it in /hda1 in Linux speak. So remember, if you've chosen to go the fdisk route, the other operating system should be re-installed first. When you've got that re-installed, you are free to install Linux in what's left. Once you've installed Linux, you can actually see the other system's partition, sort of like those phony mirrors at the supermarket. We'll talk more about that in another lesson.

Plumbing with "pipes" in Linux

In this lesson, we're going to do a little plumbing. Plumbing with a computer? Well, Linux is so flexible that it even allows you to do plumbing with it. Well.... actually, it's just a little witticism of mine because the command we're going to learn in this lesson is called 'pipe', and plumbers work with pipes. To use the pipe command, you don't type: pipe. You press the '|' key. The location will vary on keyboards from country to country. This symbol is like two vertical slashes, one on top of the other.

This is the first time that we're going to see a command that's meant to be used with other commands. That means that the pipe will separate two commands so that they will be done one after the other. Let's try some plumbing.

For example, if you looked at the contents of your /proc directory with:

ls -l /proc

it would be too big to fit in one screen. So if we typed

ls -l /proc | more

you could scroll down with the ENTER key and see it all.

Actually, ls -l /proc | less is a better solution because you can scroll up and down with the arrow keys. Remember that in a previous lesson we said: "Less is more than more".

You're probably going to end up using this a lot. You're personal directory in /home will fill up and pretty soon 'ls -l' will overflow in your terminal or x-terminal window.

There's a little short cut if you've forgotten to use the pipe. You can also scroll up and down in a terminal with the SHIFT-PAGE UP / SHIFT-PAGE DOWN keys.

The 'grep' command

In the last section we talked about the 'find' command which finds files. Now we'll talk about the 'grep' command which finds words in files. Your windows manager may have this incorporated into its find tool but then again, the beauty of Linux is having alternatives.
What does 'grep' mean?

'grep' is a Vulcan word that means "find". Actually it isn't, but it sort of looks like it, doesn't it?

Kirk: "Find the solar system L10J, Mr. Spock."
Spock: "Grepping now, Captain." *

* Star Trek stuff copyright Paramount Pictures

Let's have a little practice session with 'grep'. The best way is learning by doing, so let's do it.
A 'grep' mini-tutorial

With 'pico' or any Linux text editor, create a file called 'mary1.txt'

pico mary1.txt

Then type:

Mary had a little lamb

Press CTRL-X in 'pico' (if you're using that) and it will prompt you to save.

Then create: mary2.txt and enter the text Mary had a little cow.

Save that and create the file: mary3.txt and type: Mary had a little too much to drink. Now we know what Mary was doing when she wasn't watching her lambs! Now save that file.

OK, now we're ready to try out 'grep', so phasers on stun and let's go.

Type the following command:

grep Mary mary*.txt

Let's explain this a little. 'grep' looks for the word "Mary" in any text file that is called "mary(something).txt". You've created three files that start with 'mary', so the asterisk makes sure that 'grep' will look for the word 'Mary' in all three.

You should get this output:

mary1.txt Mary had a little lamb
mary2.txt Mary had a little cow
mary3.txt Mary had a little too much to drink

The word 'Mary' is in all of those files, so you'll get this output.

If you type grep little mary*.txt you'll get the same output because the word "little" is also in each of those files. But if you type the word "cow", you'll get this output:

mary2.txt: Mary had a little cow

because the word "cow" is only in mary2.txt.

Typing grep drink mary*.txt will get us more or less the same, only that mary3.txt will show up instead of mary2.txt.

Well, there's 'grep' in a nutshell. It's been a pleasure 'grepping' with you!

Commands to control your system

ps

'ps' will give you a list of the processes running on your system.
If you happen to forget what your name is, you can type ps -u. This is the user mode and your user name will appear in the first column. Actually, there's more than that. There will be other columns about memory usage, the time you started running the processes and others.

You can see other users processes if you type ps -au. If you're not using a networked computer, you will see yours and root's processes. If you're into detective work, you can type just ps -a and try to guess who's using the process.

The information that you'll probably be most interested in is the column that shows the "process ID" or "PID". We'll get into why these are so important in the next part of the lesson.

File systems in Linux

This is a beginner's course and one of the concepts that newcomers to Linux find different is the idea of a file system in Linux. That is to say, the way data is stored and managed in Linux.

MS-Windows and Mac users are used to clicking on an icons and dragging the files they want copied to a floppy or another part of the hard drive. Linux users that use KDE or GNOME can also copy files in that way to different parts of the hard drive. However, if you would like to use floppies, we should talk here a bit about the type of file system Linux uses.

MS-Windows, from Windows 95 on up uses a file system called 'vfat' Linux uses a different system called 'ext2'. There are also other types of file systems out there. You may have chosen to have both Windows and Linux installed in your computer. At one point, you might have to access files in the Windows partition of your hard drive. You would use a command called 'mount' to do that. You would also have to indicate as an option in that command that the file system you want to access or "mount" is a Windows 'vfat' file system.

On the same idea, though floppies are becoming somewhat obsolete, you may want to store some files on a floppy or access data on a floppy that someone has given to you. You would also have to use the command 'mount' before you copied data to or got data from a floppy disk. If that person is a Windows user, then you would have to indicate once again that the file system is 'vfat'. If you want to copy data from your Linux partition to a floppy, you would have to format and then "mount" the floppy as a Linux 'ext2' file system.
Formatting a floppy for Linux

Most floppies sold on the market are pre-formatted for MS-Windows. You can copy data from Linux to a Windows formatted floppy with no problem. If you want to copy Linux files to a floppy to be used in another Linux machine or to be used by you later in Linux, then it might be better to format the floppy for Linux's ext2 file system.

We should also say now that this is considered an administration task. You have to be working as 'root' to be doing this. As you get more familiar with Linux, you can use commands such as 'su' to do the work of root on certain occasions when you're not actually working as root. We'll explain this command in later lessons.

To create a linux floppy "by hand", you would place a floppy in the drive and type:

mke2fs /dev/fd0

The command is an abbreviated way of saying "make an ext2 file system". The other part is the device, your floppy drive, which is known to Linux as "fd0" (floppy drive 0). As we mentioned in the first part of the course, everything is a file in Linux, including your floppy drive.

You will hear the customary noise of the floppy drive (some are louder than others - some older ones that I've heard sound like a chain saw) and you will get some output like this:

Linux ext2 filesystem format

and some other information about the size of the floppy etc.

You now have a Linux formatted floppy. You may want to run this command to check if the floppy has defects

e2fsck /dev/fd0

Some windows managers have a nice program to do both the formatting and the checking of the disk at the same time.