2.2. Preparing to Install Linux
After you have obtained a distribution of Linux, you're ready to prepare your system for installation. This takes a certain degree of planning, especially if you're already running other operating systems. In the following sections, we describe how to plan for the Linux installation.
2.2.1. Installation Overview
Although each release of Linux is different, in general the method used to install the software is as follows :
People who want to switch back and forth between different operating systems sometimes wonder which to install first: Linux or the other system? We can testify that some people have had trouble installing Windows 95/98/ME after Linux. Windows 95/98/ME tends to wipe out existing boot information when it's installed, so you're safer installing it first and then installing Linux afterward using the information in this chapter. Windows NT/2000/XP seems to be more tolerant of existing boot information, but installing Windows first and then Linux still seems to be the safer alternative.
Many distributions of Linux provide an installation program that will step you through the installation process and automate one or more of the previous steps for you. Keep in mind throughout this chapter and the next that any number of the previous steps may be automated for you, depending on the distribution.
2.2.2. Repartitioning Concepts
In general, hard drives are divided into partitions , with one or more partitions devoted to an operating system. For example, on one hard drive you may have several separate partitionsone devoted to, say, Windows, another to FreeBSD, and another two to Linux.
If you already have other software installed on your system, you may need to resize those partitions in order to free up space for Linux. You will then create one or more Linux partitions on the resulting free space for storing the Linux software and swap space. We call this process repartitioning .
Many Windows systems utilize a single partition inhabiting the entire drive. To Windows, this partition is known as C :. If you have more than one partition, Windows names them D :, E :, and so on. In a way, each partition acts like a separate hard drive.
On the first sector of the disk is a master boot record along with a partition table . The boot record (as the name implies) is used to boot the system. The partition table contains information about the locations and sizes of your partitions.
There are three kinds of partitions : primary , extended , and logical . Of these, primary partitions are used most often. However, because of a limit on the size of the partition table, you can have only four primary partitions on any given drive. This is due to the poor design of MS-DOS and Windows; even other operating systems that originated in the same era do not have such limits.
The way around this four-partition limit is to use an extended partition. An extended partition doesn't hold any data by itself; instead, it acts as a "container" for logical partitions . Therefore, you could create one extended partition, covering the entire drive, and within it create many logical partitions. However, you are limited to only one extended partition per drive.
2.2.3. Linux Partition Requirements
Before we explain how to repartition your drives, you need an idea of how much space you will be allocating for Linux. We discuss how to create these partitions later in this chapter, in "Editing /etc/fstab."
On Unix systems, files are stored on a filesystem , which is essentially a section of the hard drive (or other medium, such as CD-ROM, DVD, or floppy) formatted to hold files. Each filesystem is associated with a specific part of the directory tree; for example, on many systems, there is a filesystem for all the files in the directory /usr , another for /tmp , and so on. The root filesystem is the primary filesystem, which corresponds to the topmost directory, / .
Under Linux, each filesystem lives on a separate partition on the hard drive. For instance, if you have a filesystem for / and another for /usr , you will need two partitions to hold the two filesystems. [*]
Before you install Linux, you will need to prepare filesystems for storing the Linux software. You must have at least one filesystem (the root filesystem), and therefore one partition, allocated to Linux. Many Linux users opt to store all their files on the root filesystem, which, in most cases, is easier to manage than several filesystems and partitions.
However, you may create multiple filesystems for Linux if you wishfor example, you may want to use separate filesystems for /usr and /home . Those readers with Unix system administration experience will know how to use multiple filesystems creatively. In "Creating Filesystems" in Chapter 10 we discuss the use of multiple partitions and filesystems.
Why use more than one filesystem? The most commonly stated reason is safety; if, for some reason, one of your filesystems is damaged, the others will (usually) be unharmed. On the other hand, if you store all your files on the root filesystem, and for some reason the filesystem is damaged, you may lose all your files in one fell swoop. This is, however, rather uncommon; if you back up the system regularly, you should be quite safe.
On the other hand, using several filesystems has the advantage that you can easily upgrade your system without endangering your own precious data. You might have a partition for the users' home directories, and when upgrading the system, you leave this partition alone, wipe out the others, and reinstall Linux from scratch. Of course, nowadays distributions all have quite elaborate update procedures, but from time to time, you might want a fresh start.
Another reason to use multiple filesystems is to divvy up storage among multiple hard drives. If you have, say, 300 MB free on one hard drive, and 2 GB free on another, you might want to create a 300-MB root filesystem on the first drive and a 2-GB /usr filesystem on the other. It is possible to have a single filesystem span multiple drives by using a tool called Logical Volume Manager (LVM), but setting this up requires considerable knowledge, unless your distribution's installation program automates it for you.
In summary, Linux requires at least one partition, for the root filesystem. If you wish to create multiple filesystems, you need a separate partition for each additional filesystem. Some distributions of Linux automatically create partitions and filesystems for you, so you may not need to worry about these issues at all.
Another issue to consider when planning your partitions is swap space. Swap space is a portion of the disk used by an operating system to temporarily store parts of programs that were loaded by the user but aren't currently in use. You are not required to use swap space with Linux, but if you have less than 256 MB of physical RAM, it is strongly suggested that you do.
You have two options. The first is to use a swap file that exists on one of your Linux filesystems. You will create the swap file for use as virtual RAM after you install the software. The second option is to create a swap partition , an individual partition to be used only as swap space. Most people use a swap partition instead of a swap file.
A single swap file or partition may be up to 2 GB. [*] If you wish to use more than 2 GB of swap (hardly ever necessary), you can create multiple swap partitions or filesup to 32 in all.
Setting up a swap partition is covered in "Creating Swap Space," later in this chapter, and setting up a swap file is discussed in "Managing Swap Space" in Chapter 10. For instance, if you want to run fdisk on the first SCSI disk in your system, use the command:
# fdisk /dev/sda
/dev/hda (the first IDE drive) is the default if you don't specify one.
If you are creating Linux partitions on more than one drive, run fdisk once for each drive:
# fdisk /dev/hda Command (m for help):
Here fdisk is waiting for a command; you can type m to get a list of options :
Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help):
The n command is used to create a new partition. Most other options you won't need to worry about. To quit fdisk without saving any changes, use the q command. To quit fdisk and write the changes to the partition table to disk, use the w command. This is worth repeating: so long as you quit with q without writing, you can mess around as much as you want with fdisk without risking harm to your data. Only when you type w can you cause potential disaster to your data if you do something wrong.
The first thing you should do is display your current partition table and write the information down for later reference. Use the p command to see the information. It is a good idea to copy the information to your notebook after each change you have made to the partition table. If, for some reason, your partition table is damaged, you will not access any data on your hard disk any longer, even though the data itself is still there. But by using your notes, you might be able to restore the partition table and get your data back in many cases by running fdisk again and deleting and re-creating the partitions with the parameters you previously wrote down. Don't forget to save the restored partition table when you are done.
Here is an example of a printed partition table (of a very small hard disk), where blocks, sectors, and cylinders are units into which a hard disk is organized:
Command (m for help): p Disk /dev/hda: 16 heads, 38 sectors, 683 cylinders Units = cylinders of 608 * 512 bytes Device Boot Begin Start End Blocks Id System /dev/hda1 * 1 1 203 61693 6 DOS 16-bit >=32M Command (m for help):
In this example, we have a single Windows partition on /dev/hda1 , which is 61693 blocks (about 60 MB). [*] This partition starts at cylinder number 1 and ends on cylinder 203. We have a total of 683 cylinders in this disk; so there are 480 cylinders left on which to create Linux partitions.
To create a new partition, use the n command. In this example, we'll create two primary partitions ( /dev/hda2 and /dev/hda3 ) for Linux:
Command (m for help): n Command action e extended p primary partition (1-4) p
Here, fdisk is asking which type of the partition to create: extended or primary. In our example, we're creating only primary partitions, so we choose p :
Partition number (1-4):
fdisk will then ask for the number of the partition to create; because partition 1 is already used, our first Linux partition will be number 2:
Partition number (1-4): 2 First cylinder (204-683):
Now, we'll enter the starting cylinder number of the partition. Because cylinders 204 through 683 are unused, we use the first available one (numbered 204). There's no reason to leave empty space between partitions:
First cylinder (204-683): 204 Last cylinder or +size or +sizeM or +sizeK (204-683):
fdisk is asking for the size of the partition we want to create. We can either specify an ending cylinder number, or a size in bytes, kilobytes, or megabytes. Because we want our partition to be 80 MB in size, we specify +80M . When specifying a partition size in this way, fdisk will round the actual partition size to the nearest number of cylinders:
Last cylinder or +size or +sizeM or +sizeK (204-683): +80M
If you see a warning message such as this, it can be ignored. fdisk prints the warning because it's an older program and dates back before the time that Linux partitions were allowed to be larger than 64 MB.
Now we're ready to create our second Linux partition. For sake of demonstration, we'll create it with a size of 10 MB:
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (474-683): 474 Last cylinder or +size or +sizeM or +sizeK (474-683): +10M
At last, we'll display the partition table. Again, write down all this information-- especially the block sizes of your new partitions. You'll need to know the sizes of the partitions when creating filesystems. Also, verify that none of your partitions overlaps:
Command (m for help): p Disk /dev/hda: 16 heads, 38 sectors, 683 cylinders Units = cylinders of 608 * 512 bytes Device Boot Begin Start End Blocks Id System /dev/hda1 * 1 1 203 61693 6 DOS 16-bit >=32M /dev/hda2 204 204 473 82080 83 Linux native /dev/hda3 474 474 507 10336 83 Linux native
As you can see, /dev/hda2 is now a partition of size 82,080 blocks (which corresponds to about 80 MB), and /dev/hda3 is 10,336 blocks (about 10 MB).
Note that most distributions require you to use the t command in fdisk to change the type of the swap partition to "Linux swap," which is numbered 82. You can use the l command to print a list of known partition type codes, and then use the t command to set the type of the swap partition to that which corresponds to "Linux swap."
This way the installation software will be able to automatically find your swap partitions based on type. If the installation software doesn't seem to recognize your swap partition, you might want to rerun fdisk and use the t command on the partition in question.
In the previous example, the remaining cylinders on the disk (numbered 508 to 683) are unused. You may wish to leave unused space on the disk, in case you want to create additional partitions later.
Finally, we use the w command to write the changes to disk and exit fdisk :
Command (m for help): w #
Keep in mind that none of the changes you make while running fdisk takes effect until you give the w command, so you can toy with different configurations and save them when you're done. Also, if you want to quit fdisk at any time without saving the changes, use the q command. Remember that you shouldn't modify partitions for operating systems other than Linux with the Linux fdisk program.
You may not be able to boot Linux from a partition using cylinders numbered over 1023. Therefore, you should try to create your Linux root partition within the sub-1024 cylinder range, which is almost always possible (e.g., by creating a small root partition in the sub-1024 cylinder range). If, for some reason, you cannot or do not want to do this, you can simply boot Linux from floppy, use the rescue option of the installation CD or DVD, or boot a Linux live CD like Knoppix.
Some Linux distributions require you to reboot the system after running fdisk to allow the changes to the partition table to take effect before installing the software. Newer versions of fdisk automatically update the partition information in the kernel, so rebooting isn't necessary. To be on the safe side, after running fdisk you should reboot from the installation medium before proceeding.
2.2.4. Creating Swap Space
If you are planning to use a swap partition for virtual RAM, you're ready to prepare it. [*] In "Managing Swap Space" in Chapter 10, we discuss the preparation of a swap file, in case you don't want to use an individual partition.
Many distributions require you to create and activate swap space before installing the software. If you have a small amount of physical RAM, the installation procedure may not be successful unless you have some amount of swap space enabled.
The command used to prepare a swap partition is mkswap , and it takes the following form:
mkswap -c partition
where partition is the name of the swap partition. For example, if your swap partition is /dev/hda3 , use the command
# mkswap -c /dev/hda3
With older versions of mkswap , you had to specify the size of the partition, which was dangerous, as one typo could destroy your disk logically.
The -c option tells mkswap to check for bad blocks on the partition when creating the swap space. Bad blocks are spots on the magnetic medium that do not hold the data correctly. This occurs only rarely with today's hard disks, but if it does occur, and you do not know about it, it can cause you endless trouble. Always use the -c option to have mkswap check for bad blocks. It will exclude them from being used automatically.
If you are using multiple swap partitions , you need to execute the appropriate mkswap command for each partition.
After formatting the swap space, you need to enable it for use by the system. Usually, the system automatically enables swap space at boot time. However, because you have not yet installed the Linux software, you need to enable it by hand.
The command to enable swap space is swapon , and it takes the following form:
After the mkswap command shown, we use the following command to enable the swap space on /dev/hda3 :
# swapon /dev/hda3
2.2.5. Creating the Filesystems
Before you can use your Linux partitions to store files, you must create filesystems on them. Creating a filesystem is analogous to formatting a partition under Windows or other operating systems. We discussed filesystems briefly in "Linux Partition Requirements," earlier in this chapter.
Several types of filesystems are available for Linux. Each filesystem type has its own format and set of characteristics (such as filename length, maximum file size, and so on). Linux also supports several third-party filesystem types, such as the Windows filesystem.
The most commonly used filesystem types are the Second Extended Filesystem , or ext2fs and the Third Extended Filesystem , or ext3fs . The ext2fs and ext3fs filesystems are two of the most efficient and flexible filesystems; they allows filenames of up to 256 characters and filesystem sizes of up to 32 terabytes. In "Filesystem Types" in Chapter 10, we discuss the various filesystem types available for Linux. Initially, however, we suggest you use the ext3fs filesystem.
To create an ext3fs filesystem, use the command
mke2fs -j -c partition
where partition is the name of the partition. (Notice that the same command, mke2fs is used for creating both ext2 and ext3 filesystems; it's the -j that makes it a journalled, ext3 , filesystem.) For example, to create a filesystem on /dev/hda2 , use the command
# mke2fs -j -c /dev/hda2
If you're using multiple filesystems for Linux, you need to use the appropriate mke2fs command for each filesystem.
If you have encountered any problems at this point, see "Running into Trouble," later in this chapter.
2.2.6. Installing the Software
Finally, you are ready to install the software on your system. Every distribution has a different mechanism for doing this. Many distributions have a self-contained program that steps you through the installation . On other distributions, you have to mount your filesystems in a certain subdirectory (such as /mnt ) and copy the software to them by hand. On CD-ROM distributions, you may be given the option to install a portion of the software on your hard drive and leave most of the software on the CD-ROM. This is often called a "live filesystem." Such a live filesystem is convenient for trying out Linux before you make a commitment to install everything on your disk.
Some distributions offer several different ways to install the software. For example, you may be able to install the software directly from a Windows partition on your hard drive instead of from floppies. Or you may be able to install over a TCP/IP network via FTP or NFS. See your distribution's documentation for details.
For example, the Slackware distribution requires you to do the following:
The exact method used to install the Linux software differs greatly with each distribution.
You might be overwhelmed by the choice of software to install. Modern Linux distributions can easily contain a thousand or more packages spread over several CD-ROMs. There are basically three methods for selecting the software package:
Choosing one selection method does not exclude the use of the others. Most distributions offer two or more of the aforementioned selection mechanisms.
It might still be difficult to decide which package to pick. Good distributions show a short description of each package on screen to make it easier for you to select the correct ones, but if you are still unsure, our advice is this: when in doubt, leave it out! You can always go back and add packages later.
Modern distributions have a very nifty feature, called dependency tracking . Some packages work only when some other packages are installed (e.g., a graphics viewer might need special graphics libraries to import files). With dependency tracking, the installation program can inform you about those dependencies and will let you automatically select the package you want along with all the ones it depends on. Unless you are very sure about what you are doing, you should always accept this offer, or the package might not work afterward.
Installation programs can help you make your selection and avoid mistakes in other ways. For example, the installation program might refuse to start the installation when you deselect a package that is absolutely crucial for even the most minimal system to boot (like the basic directory structure). Or, it might check for mutual exclusions, such as cases in which you can only have one package or the other, but not both.
Some distributions come with a large book that, among other things, lists all the packages together with short descriptions. It might be a good idea to at least skim those descriptions to see what's in store for you, or you might be surprised when you select the packages and are offered the 25th text editor.
2.2.7. Creating the Boot Floppy or Installing GRUB
Every distribution provides some means of booting your new Linux system after you have installed the software. In many cases, the installation procedure suggests you create a boot floppy, which contains a Linux kernel configured to use your newly created root filesystem. In order to boot Linux, you could boot from this floppy; control is transferred to your hard drive after you boot. On other distributions, this boot floppy is the installation floppy itself. If your system does not contain a floppy drive any more (like many newer systems), be assured that there are always other ways of booting Linux, such as booting directly from CD.
Many distributions give you the option of installing GRUB on your hard drive. GRUB is a program that resides on your drive's master boot record. It boots a number of operating systems, including Windows and Linux, and allows you to select which one to boot at startup time.
In order for GRUB to be installed successfully, it needs to know a good deal of information about your drive configuration: for example, which partitions contain which operating systems, how to boot each operating system, and so on. Many distributions, when installing GRUB, attempt to "guess" at the appropriate parameters for your configuration. Occasionally, the automated GRUB installation provided by some distributions can fail and leave your master boot record in shambles (however, it's very doubtful that any damage to the actual data on your hard drive will take place).
In many cases, it is best to use a boot floppy until you have a chance to configure GRUB yourself, by hand. If you're exceptionally trusting, though, you can go ahead with the automated GRUB installation if it is provided with your distribution.
In "Using GRUB" in Chapter 17, we'll cover in detail how to configure and install GRUB for your particular setup.
If everything goes well, congratulations! You have just installed Linux on your system. Go have a cup of tea or something; you deserve it.
In case you ran into trouble, "Running into Trouble," later in this chapter, describes the most common sticking points for Linux installations, and how to get around them.
2.2.8. Additional Installation Procedures
Some distributions of Linux provide a number of additional installation procedures, allowing you to configure various software packages, such as TCP/IP networking, the X Window System, and so on. If you are provided with these configuration options during installation, you may wish to read ahead in this book for more information on how to configure this software. Otherwise, you should put off these installation procedures until you have a complete understanding of how to configure the software.
It's up to you; if all else fails, just go with the flow and see what happens. It's doubtful that anything you do incorrectly now cannot be undone in the future (knock on wood).
Practical Guide to Linux Commands, Editors, and Shell Programming, A (2nd Edition)
Linux Network Administrator's Guide
Linux Pocket Guide
Linux in a Nutshell
Learning the vi and Vim Editors
Practical Guide to Linux Commands, Editors, and Shell Programming, A (2nd Edition)
Linux Network Administrator's Guide
Linux Pocket Guide
Linux in a Nutshell
Learning the vi and Vim Editors