If you have an existing operating system that takes up the whole disk, you will have to backup and reinstall the existing system to make room for Linux. You need to be careful because you may make partition too small for all the files that were there before!
A couple of tools are available on the Internet that will reformat a DOS partition with an existing system (assuming there is enough free space). I have never used such a tool, although I have read messages on the Internet from people who have done it successfully.
During the installation, you will have a chance to either install on an existing partition or repartition the drive. As with other PC-based OSs, use the fdisk tool to partition the drive. Nost modern distributions have full-screen, menu-driven versions, but they all perform the same functions, such as creating, deleting, and making partitions active.
However, the Linux fdisk can do much more than that. For example, it can change the partition type, which is helpful when you need to have a system with several different OSs. DOS and older Windows can only create a single primary and a single extended partition. I have used Linux to create all of the necessary partitions and then DOS/Windows to recognize them correctly.
Another useful thing is that the Linux fdisk will do what you tell it. Some time aog, I have wanted to delete an entire extended partition on a Windows system, but couldn’t because logical partitions were there. Linux will do that for you.
As with other operating systems, Linux fdisk will see that other partitions are there, even though it may not know what type they really are. Linux is very good at recognizing the type, although there are a few cases in which I have seen it off the mark (but not by much). The reason is that all fdisk versions just read the partition table, which is in a common format.
Warning: I have seen a number of Linux certification prep books that claim you can only have four primary partitions or three primary partition and one extended partition which is further broken down into four logical partitions for a total of seven (7) partitions. He is the partition layout of one hard disk on one of current systems:
The first three partitions (hda1, hda2, and hda3) are all primary partitions. The extended partition (hda4) is devided into eight (8) or twice the number these books claim. This is very outdated information, but it still may appear on the Linux certification like this.
Note also that depending on how old the book is, it might tell you that there is a limit of 128 MB of swap. This is no longer true with Linux 2.2.x and later kernels. The current limits (Aug 2006) are approximately 2 GB on x86,MC680x0 and PowerPC, 512 MB on MIPS, 128 GB on Alpha, and 3 Terabytes on UltraSparc.
As you can see in the example above, the logical partitions start number at 5. This is true whether or not you are using up all of the primary partitions and is the same for IDE as well as SCSI drives.
During the installation of Linux, you will typically have a choice of doing an automatic or manual installation, and in some cases a combination of the two. If you chose a manual installation you will probably be allowed to defined the partition layout of your hard disks. On SUSE linux you have an “expert” mode which looks something like this:
Note that this what is displayed here is what you get when you start YAST after the system is installed, so what you see during the installation will probably look different. You can see that the start cylinder of the first partition is 0. However in the text output above, the starting cylinder is 1. In fact, if you compare the two they are essentially identical except that the values differ by 1. So, you need to be careful if you are using values taking from fdisk (as above) and want to input them into YAST.
When you select the
button, you reach the following screen:
Here you are defining various parameters for this partition and the associated filesystem. In some cases, it is logical not to format the partition (i.e. create a filesystem). For example, if you are recovering from a crash where the partition table was destroyed, you can usually recover the filesystem fully if you simply input the appropriate values for the starting cylinder, ending cylinder and mount point.
Be careful when you specify the size of the partition but always specify the ending cylinder. This is because the size is not an exact value. You might think that the correct value is (for example) 4.3 GB, but because of the technical aspects of one of your hard disks it is closer to 4.26 GB. Inputting 4.3 GB might round down to only 4.28 GB on another disk, which is larger than you want. However, if you specify the ending cylinder, you always have the correct value.
For the most part this is not an issue, as you typically do not really care if the drive is 4.26 or 4.28. However, if you setting up a RAID system, having the drives the same size is obviously important.
The options that are provided when creating the filesystem will differ depending on the filesystem type you choose. For example, if you choose a type swap there are no options. If you choose and EXT3 filesystem, you can choose (for example); the block size, such as 1024, 2048, or 4096 bytes per block. If you select auto then the block size is determined by the file system size. Other filesystem have different options which appear in the left-hand frame when you choose the respective file system type.
Partitioning by hand using fdisk uses the same basic concepts. However, instead of showing all of the partitions on all of you hard disks, you need to specify the device node for the hard disk you which to partition (assuming you have more than one). For example, to partition the first IDE hard disk, the command might look like this:
Be careful that this is the device node of the entire hard disk and not an individual partition like /dev/hda1. If you should specify an individual partition, you will end up with a message like this:
With a never version of fdisk (fdisk v2.12q, run in August 2006), I got different output:
With an even later verion of fdisk (disk v2.12q, run in August 20090), I got output similar to the first:
If you made changes and then decided to write the partition table, it will not do what you expect and you probably have lost all the data on the partition. Note that when you run YAST it warns you about only making changes if you know what you are doing. I can only add: Heed the warning!
Notice the warning about the number of cylinders. This is usually only an issue when booting the system and loading the kernel. Typically, I have by /boot directory on a separate file system that is one of the first two partitions. I make sure that the this partition ends below cylinder 1024 to ensure that there are no problems when booting. As with the GUI version (shown above), you can specify the ending cylinder so you don’t have to do any calculations yourself in figuring out how big the partition is.
If you press
at this point, you get the following “menu”:To look at the existing partition partitions you input
, which gives you something like this:(Note that this is the same table as above)
If you take a close look, you will see that the extended partition (/dev/hda4) goes up to cylinder 9963. However, the last partition only goes up to cylinder 7725, thus there is a fair bit of free, unpartitioned space on this drive. If I want to create a new partition, I input , which then prompts me for a start cylinder:
Since there is already three primary partition and one extended partition, you can only create a new logical partition. If some of these partitions were missing, you would be prompted to select the kind of partion with a prompt like this:
Note that the start (first) cylinder is always 1 more than the last cylinder of the previous partition. If you then input 7726 (or simply press return) you are prompted to input either the size of the partition or the end/last cylinder. The default is the last available cylinder. Note that the calculation of the partition size is not exact if your specify the size. The fdisk command will fit the size to cylinder boundary and thus it is typically a smaller less than you expect.
By default, fdisk will create a standard linux partition (as you can see in the last two columns). If you want to create a diffent kind of partion, you would input the option to specify the type. Next you would input the number of the partition (so we might input if we were adding a new partition) and then the hex code of the desired type. If you are not sure, you can input and you will be shown a table of possible partition types:
Note that the table you have might look different as different partition types are added.
Most of the partition types listed are once that you probably never have heard of, let alone need. Looking at the fdisk output above, I only use a small fraction of these and have only ever needed a couple of others. Still, there are valid reasons to use any of the them.
At this point the partition table has not yet been changed. The changes are only in memory. It not until you input
to write the partition table and quit.Unlike when you use the YAST or another GUI, you are still not done. Unless you created a swap or other type of “administrative” partition, you cannot use the partition as it because it needs as file system. Creating a filesystem is comparable to formating a partition under DOS, the details of which can be found here.
The type of applications you are going to run on your server should guide you when deciding how you want to partition your system. As discussed previously, partitions are often created for /boot, /usr, /var, /opt, and /home. It is also common that data or files related to your application are stored on a seperate partition. For example, on a database server, the database files are often stored on an seperate partition. It is also common to store these files on a seperate hard disk, which typically improves performance because the work is spread acrosss multiple disks.
Another consider here is to consider putting the data on the fastest drive you have. If your applications do a lot of logging, you might also want to consider putting /var on a faster disk. Keep in mind that if both data and log files are on the same disk, you might be shooting yourself in the foot because the disk is so busy that it eliminates any benefits from the extra speed.
- Database server
- Application server
- Web server
- Mail Server
Choosing the right hard disk is just as important as choosing the right partitioning.