Tuesday, June 13, 2006

Getting into the shell

One of the components of Linux that many Windows users might not be ready for is the shell. The shell, as you might recall from an earlier column, is the layer of the operating system that fits between the desktop and the kernel. It allows you to directly interact with the various components of your computer without going through the graphical interface.

Of course, there are several graphical interfaces, or desktops, available for Linux -- KDE and Gnome are chief among them. These desktops allow you to accomplish even very complex tasks pretty easily. However, there is no easier way to get a lot accomplished quickly than by using the shell -- once you get used to it.

Windows, of course, used to have a real shell -- the DOS window. In the DOS window, you could easily view, load, copy, and erase files, format hard drives, and even reconfigure parts of the computer. As Windows progressed through 98 to XP, DOS became less and less powerful. Now, you have to jump through hoops to get to a real DOS window from Windows.

With Linux, however, the "DOS" window reappears, in the form of a "console", or shell window. From the shell, you can do all of the tasks you once c0uld perform from the DOS window. Of course, you can still use the graphical interface to do many of these tasks, but the console window can let you do it faster. You can generally find an icon to open up a console window on one of the menus within your desktop environment.

Users accustomed to DOS have some adjustments to make, though. Many of the commands ("dir", "copy", etc.) have new equivalents in Linux ("ls", "cp", etc.). Rather than catalog all of the shell commands here, I'll run through some of the most helpful:

ls -- list files
cp -- copy file(s)
mv -- move file(s); use this instead of "rename"
rm -- remove file(s)
tar -- compress or decompress files
man [command] -- display help file associated with [command]
more -- display contents of a file one screen at a time

One of the handiest features of the shell is the wildcard. If you want to list all the files in a directory that start with "amy", for example, you can type "ls amy*". Try that with your desktop. There are plenty of resources available to help you learn to use wildcards to your advantage. They are one of the best reasons to jump into a console from time to time.

You can also run most software from the shell, by typing the name of the program. For example, to run the Email program "Evolution", you can type

evolution

from the console prompt. When you do this, though, your console will be completely occupied with running the software until you exit it. You may want to run it as a background task -- allowing the console to do other things (including taking other commands from you) while it runs it. Add an ampersand (&) to the end of the command.

evolution &

The "Superuser"
From Windows, you'll recall the concept of having different users logging into the same computer, each having access to private (user-only) and shared files. Linux continues this concept -- you can add users ad infinitum. One user always remains the same -- the root user. This "user" has access to every file on the machine.

As a regular user, when you log into the desktop or use the shell, you'll only have access to your own files and any files that other users are sharing. Even if you're the only user on your computer, the operating system will automatically limit your ability to get to system and protected files. This is for your own protection, so you don't accidentally disrupt things that will make your operating system not work anymore. In order to access, change, or delete system files, you will have to log in as the root.

This is not as much of an issue with the graphical interface, because you should never log into the desktop as the root user. Really. We mean it. The root restrictions are the most powerful protection your computer has against viruses and against your own bad behavior. If you log into the desktop as root, both of these protections are gone. When you're logged into the desktop as a regular user, you (and any virus you may contract) can only destroy your personal files, but the system will live on no matter what.

There are reasons to log into the shell as the root user, though. If you need to look at or copy files in the protected area of the system, which you might from time to time, you'll need to log in as root to do so. You'll also need to log in as root to install software or reconfigure your system.

Be very careful, though. You can make your system completely unusable by deleting even one critical file. Don't even think about using wildcards to delete multiple protected files unless you really know what you're doing -- this is a recipe for disaster. In general, until you know what's what, you should not log in as root unless people who know what they're doing tell you to.

To log in as the root user from the shell, type

su

from the command prompt. You will then be asked for the "root password" you created when you installed the system. When the prompt reappears, you will have access to every file on your system. Only this window, however, and any program you run from this window, will have root access. On your desktop, you'll still be logged in as yourself, a regular user. You can then go about your business. When you're done, you can close this window, and the root access will disappear. You can also type

su [username]

to log back in as yourself. It's probably safer, though, to simply close out the window.

Once you get comfortable with the shell, you'll probably find yourself popping in and out of it to perform certain tasks, rather than spending lots of time working within it. But it's handy when you need it.

Regards.

Sunday, June 04, 2006

Partition Perdition

Once you've chosen a distribution to install, the actual installation process is relatively easy. One question that will confront you (for which you may not be prepared) relates to partitioning. By partitioning your hard disk(s), you will decide how much space to dedicate to Windows, and how much to dedicate to Linux.

File System Wisdom
One of the tasks of the operating system is to move information to and from your hard drive. Every time you copy, delete, move, or save a file on your computer, the operating system tells the computer how to handle the information. Windows and Linux have entirely different ways of doing this. Predictably, they do not share the same space on a hard disk very well. Instead, to allow them to coexist peacefully, you will have to construct two separate spaces on your hard disk -- one for Windows, and one for Linux. This process is called partitioning.

Most likely, your computer came pre-installed with Windows, meaning you never had to break out the Windows installation disk to get your computer up and running. Even if you did install the operating system yourself, you probably never dealt with the issue of partitioning your hard drive. When Windows was installed, it claimed all of the available space on the hard disk, whether it needed it or not.

Since Linux will need its own space to operate in, you will need to "repartition" the hard disk to make room. Most of the Linux distributions are fully capable of repartitioning your hard disk. You will simply have to decide how much space to leave for Linux. Most distributions these days will happily install in a 10 gigabyte partition (give or take a few gigabytes), but you may want to leave more room for data.

Before you repartition your hard disk, you must back up the information on the disk. There is a chance your data could become corrupted during the partitioning process. This is not optional. Really. I did it, and so can you.

To repartition the disk, your distribution's installation software will have to read your Windows files and move them all to one part of the hard disk. Some distributions do a better job at this than others. But all of them are doing very little better than you would do reading a foreign language you learned in high school. You might do a passable job, but you may miss some things here and there. So make a backup. You've been warned.

If you choose, you can leave the partitioning to software like Norton Partition Magic. This does not keep you from having to back up your Windows data, but you might have a bit more confidence in it. It can read a few types of Linux file systems, and even create Linux partitions for your installation program to use.

If you have any discomfort with the partitioning process, don't install Linux. You can work off the Live disk, or ask one of your computer-expert buddies to help. Partitioning hard disks is not for the timid.

Choosing a file system
When you partition the hard disk, you'll have to choose a file system for Linux to use. Just as Linux offers any number of kernels, shells, and desktops, it also offers different ways to store information on the hard disk. The two principal systems are Reiserfs and ext3. Other file systems may be available, but you should probably choose one or the other of these unless your installation software recommends otherwise.

For practical purposes, there is little to recommend one file system over the other. Technical types will find advantages and disadvantages of each. My experience leads me to believe that ext3 is a bit more widely used, and Reiserfs is a bit of a bias of SuSE. I've also found my ext3 partitions to be a bit more stable and somewhat easier to recover when errors occur, but you may have a different experience. If your installer has default file system options, you're probably best off agreeing with them.

Reading Foreign Systems
After you've installed Linux and it's up and running, the first thing you'll likely want to know is where all of your old data have gone. Your Windows data will be in your Windows partition. You won't necessarily be able to run your Windows software (although we'll discuss in the future some ways to cheat and run it anyway). However, many of your Windows files can still be read by Linux software. For example, your word processing documents and spreadsheets can probably be opened by Linux software such as Openoffice.

Many distributions will read data from your Windows partition from within Linux pretty easily. Windows, however, uses a few different file systems. The main ones these days are NTFS (Windows 2000 and XP) and FAT32 (older versions of Windows). You don't necessarily need to know what file system your Windows software used in order to read the documents you stored on the Windows partition. However, Linux cannot write very well to NTFS -- so if you happen to have used this format, you will need to copy these files over to your Linux partition to edit them. With many distributions, this is as simple as dragging the file over to the desktop, just as you used to in Windows.

There are some "experimental" ways to write to NTFS partitions from Linux (allowing you to edit and save files there). There are just as many horror stories from people who've wiped out their entire Windows life in mere moments by doing so. For now, it might be best to stay away from these methods.

If you need to share data between Windows and Linux, you can create a single FAT32 partition for both to use. Both Windows and Linux can read and write these partitions. The file size is somewhat limited (4 gigabytes), but you shouldn't notice any significant problems unless you're working with really huge files (such as multimedia presentations, which are going to be more challenging to share between Windows and Linux anyway). If you have files that are "mission-critical", you probably should not plan on sharing them -- just in case.

Regards