2.3. Disk Partitioning

2.3. Disk Partitioning

You have the choice of either partitioning the disk manually or having the installer partition the disk automatically. The choices for automatic partitioning are the following:

  • Remove all Linux partitions on this system Selecting this option will remove only Linux partitions (if there are such from previous Linux installations). No other partitions (such as 32-bit File Allocation Table, or FAT32, and the new technology file system, or NTFS) will be removed.

  • Remove all partitions on this system Selecting this option will remove all existing partitions on your hard disk (or disks, if you have more than one hard disk drive). This option is suitable when the operating system being installed will be the only one on the computer. In this case, the installation program will select how much disk space to allocate to specific operating system components .

  • Keep all partitions and use existing free space If there already is an operating system on this computer that you want to keep and you have released disk space using a partition utility (such as PartitionMagic), you should select this option. The installation program will create disks for Linux based on the amount of free space on the physical disk

2.3.1. Disk Naming

In Linux, the disk-naming method is different from the one used in Windows. There are no disks A:, C:, etc. in Linux. Instead, disks are named as /dev/hdnX, where n is the physical disk letter (assigned as a, b, c, etc.) and X is the primary or extended partition number or the logical disk number. There can be up to four primary partitions or three primary and one extended partitions on a physical disk. Consequently, numbers from 1 to 4 are reserved for the primary and/or extended partitions. Logical disks in the extended partition are given numbers starting with 5.

It may seem complicated at first, but the following example should make it simple. Suppose you have two physical hard disk drives on your system. The first drive is partitioned into a primary partition and an extended partition. Furthermore, you divide the extended partition on the first physical drive into two logical drives . The second hard drive has one primary partition and one extended partition. Linux labels this arrangement as follows :

 /dev/hda  The first physical hard drive     /dev/hdal  The primary partition on the first physical drive     /dev/hda2  The extended partition of the first physical drive          /dev/hda5  The first logical disk on the extended partition of the first  physical drive          /dev/hda6  The second logical disk on the extended partition of the first  physical drive /dev/hdb  The second physical hard drive     /dev/hdb1  The primary partition on the second physical drive     /dev/hdb2  The extended partition on the second physical drive          /dev/hdb5  The logical disk on the extended partition of the second physi-  cal drive 

The first logical disk on the extended partition of the first physical hard drive was assigned the number 5. The number 6 was assigned to the second logical disk on the extended partition of the first physical hard drive. The logical disk on the extended partition of the second physical hard drive was also given the number 5.

2.3.2. Linux File Systems

Now, look at the file systems supported by Linux. This operating system supports various file systems, including the FAT, FAT32, and NTFS Windows file systems. It is advisable, however, to install Linux on its own Ext2, Ext3, or ReiserFS (often shortened to just Reiser) file system. The Reiser file system is the latest development and is based on a concept called journaling. This makes this file system more stable and the after-crash recover process much faster. Thus, it is preferable to install Linux on this file system.

To help choosing the optimal file system, consider the basic operating principles of the main file systems. With the Ext2 file system, the data are cached first and only then written to the disk, which makes file operations highly efficient. However, if there is a power outage or the system crashes, some of the data in the cache may not have been written to the disk and the file system will become corrupted. The next time the operating system boots, it will detect that the integrity of the file system has been corrupted and will run the fsck (a rival of the Windows' scandisk) disk-checking utility to detect and correct any potential damages. This will restore the disk's operability but not the data. Moreover, the scanning process takes a long time, which adversely affects the speed, with which the server is put back into operation. Consequently, be prepared for the system to take a longer time to boot after a crash.

With the Reiser file system, data are also cached before being written to the disk. But unlike with Ext2, after the data were written to the disk, their integrity is checked and only if the write was successful is the cache cleared. In case of a crash or power outage, upon the next boot, the journal record is used to detect corrupted data and to "back out" these data, thereby preventing most data corruption and restoring the disk operability more rapidly than with other file systems.

The Reiser file system has another advantage over other file systems. Data are usually written to the disk in blocks. Assume that the size of a block is 1 KB. Then, for example, a 100-byte file written to the disk in FAT32 will occupy the whole block, with 90% of the block space being wasted . Consequently, the amount of data that can actually be stored on a disk will be slightly less than the disk size; if lots of small files are stored on the disk, the waste will be even greater. The Reiser file system provides more efficient use of the disk space.

Disk waste in Windows can be demonstrated by opening a file's Properties window (Fig. 2.3). Take note of the Size and Size on disk parameters. The former is the file's size and the latter is the disk space the file occupies. The size of a disk cluster is 4 KB, or 4,096 bytes. The file is 973 bytes larger than the cluster size, so another cluster is allocated to store these 973 bytes. No more data can be stored in the second cluster, resulting in more than 75% of its storage space being wasted.

image from book
Figure 2.3: The file Properties window

When 1,024 100-byte files are written to the disk, each of the files is allocated a 4-KB cluster. This will result in 4 MB of disk space used to store only 100 KB of data: a waste of almost 95%.

The Reiser file system provides more efficient use of the disk space by allowing several small files to be written to one cluster.

The Ext3 file system is another journaling file system, which is analogous to the Reiser file system. Currently, it is the default file system in most modern Linux distributions. It is difficult to compare the performance of the Reiser and the Ext3 files systems, but from the reliability standpoint I advise you to agree with the developers and use the latter.

2.3.3. Manual Partitioning

If you intend your machine to be a server, I urge you to partition the disk manually. By default, the installation program creates only two partitions for Linux: the root partition and the swap partition to use as virtual system memory. This arrangement is far from efficient and can prove unsafe. Select the Manually partition with Disk Druid item. This will open the Disk Setup dialog window (Fig. 2.4).

image from book
Figure 2.4: The Disk Setup dialog window

The large panel in the lower right part of the window contains the list of disks, including the free disk space. In this case, there is only one disk: /dev/sda. Below the disk name , there usually is the table of the disk partition. As can be seen in Fig. 2.4, there are no partitions on this disk.

To create a partition in the free disk space, click the New button. This will open the Add Partition dialog window (Fig. 2.5).

image from book
Figure 2.5: The Add Partition dialog window

Select the file-system type in the File System Type dropdown list. As was already stated, the most preferable file system for Linux is Ext3, and this is the type of the file system I recommend that you select.

The size of the new partition is set in the Size ( MB ) list box, either by typing it into the entry field or by using the scroll buttons .

The type of partition is selected from the Mount Point dropdown list.

The list of partitions that can be created, and their functions are listed in Table 2.1. The exact list varies for different distributions.

Table 2.1: Linux Partitions

Partition

Description

/

Root partition. While in Windows a path starts with the name of the disk, in Linux the path starts with the root (depicted with a slash).

/bin

System's main executable files.

/boot

Files necessary to boot the system.

/dev

Represents the devices attached.

/etc

Stores system configuration files.

/home

User files.

/lib

Contains binaries to support executables.

/opt

Optional software packages.

/proc

Files used for mounting the virtual file system.

/sbin

Executable files of the main (root) user.

/tmp

Temporary files.

/usr

Stores system files.

/var

Log, spool, or lock files.

swap

Swap file.

Note that, with the exception of the first and the last partitions in the table (root and swap, respectively), the names of all partitions start with a slash. This is because the root and the swap partitions are mandatory, while the rest of the partitions can be represented as folders in the root partition.

The swap partition always has to be a separate partition with its own file system. It cannot be represented as a folder in the root. The size of the swap partition should be at least that of the installed system memory. I recommend making the swap partition at least 3 times the size of the installed system memory: It is possible that the memory will be extended in the future, but changing the size of the swap file is a little complicated, requiring you to edit the /etc/fstab file or use disk partitioning tools, such as fdisk.

Linux requires at least two actual partitions: the root partition (denoted as /) and the swap partition. The root partition can have any file type except the swap file type. The swap partition can only have the swap file-type system. The root partition is used to hold all files, and the swap partition is used as virtual memory to supplement the system memory. The rest of the partitions listed in Table 2.1 do not have to be created as actual disk partitions but can be represented as folders in the root partition.

At first, all of this may seem complicated, especially if you have only worked with Windows before. But the capability to house numerous operating-system files in their own partitions is a powerful one. Two partitions are enough when you have only one physical hard drive on a home computer. If you have two physical hard drives, you will benefit from creating three partitions as follows:

  • / On the first physical hard drive to hold all system files

  • swap On the first physical hard drive

  • /home On the second physical hard drive to hold user files

It is advisable to connect the disks to separate controllers; this will allow the system to work with them practically in parallel. In this way, the performance of the operating system may be raised significantly, because Linux can work with the system and user files simultaneously .

If you are setting up a server, the /home and /var folders are better to set up on separate physical hard drives. Placing these folders on logical disks will not produce the results desired.

How large should you make the partitions? The size of the swap partition should be set depending on the amount of system memory installed, as was mentioned earlier. If the /var and /home partitions are placed on separate physical drives, 4 GB will be enough for the root partition, although it can be made larger.

It is better not to economize on the size of the /var partition; make it 10 GB. This partition stores the log, World Wide Web (WWW), and FTP files. These files grow in size rapidly, and if they fill up the entire available space, the system may crash or even become inaccessible. Hackers sometimes take advantage of this circumstance when organizing DoS attacks. I will consider various aspects of these attacks more than once in this book. Some security specialists recommend placing this partition on the largest physical disk, where most often the /home partition is also located. Following this advice, however, will affect the performance adversely. Placing logs on a separate physical disk makes it possible to write to them concurrently with servicing the rest of the partitions. This means that while on one physical disk the user is working with his or her files in the /home partition, on the other physical disk the system is storing all information about the user's activity. If both partitions are on the same physical disk, they cannot be accessed in parallel.

If necessary, the /var and /home partitions can be placed on the same, the largest, physical disk. But, in this case, allocate to the /home partition all disk space left after other partitions. This partition is used to store user data, which usually become voluminous. Economizing on the space here will soon result in users complaining about not being able to save results of their games on the server. But if the technical characteristics of your system allow this, place the /var and /home partitions each on an individual physical hard disk, as large as you can afford, and you will have no problems.

For a test system, the simplest arrangement, with two partitions (the root and the swap), will suffice.

After partitioning the disk, the new partitions have to be formatted. Some especially smart distributions will carry out this operation without asking any questions.



Hacker Linux Uncovered
Hacker Linux Uncovered
ISBN: 1931769508
EAN: 2147483647
Year: 2004
Pages: 141

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net