Partitioning

Partitioning

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:

/dev/hda1 * 1 222 1783183+ 7 HPFS/NTFS /dev/hda2 223 229 56227+ 83 Linux /dev/hda3 230 882 5245222+ 83 Linux /dev/hda4 883 9963 72943132+ f Win95 Ext’d (LBA) /dev/hda5 883 1078 1574338+ 82 Linux swap /dev/hda6 1079 2384 10490413+ 83 Linux /dev/hda7 2385 3037 5245191 c Win95 FAT32 (LBA) /dev/hda8 3038 3168 1052226 83 Linux /dev/hda9 3169 6811 29262366 83 Linux /dev/hda10 6812 7072 2096451 83 Linux /dev/hda11 7073 7725 5245191 83 Linux

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:

SUSE Linux YAST – Hard disk partitioning

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 Create button, you reach the following screen:

SUSE Linux YAST – Partition and file system configuration

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:

fdisk /dev/hda

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:

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won’t be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

With a never version of fdisk (fdisk v2.12q, run in August 2006), I got different output:

Command (m for help): p Disk /dev/hda1: 1825 MB, 1825979904 bytes 16 heads, 63 sectors/track, 3538 cylinders Units = cylinders of 1008 * 512 = 516096 bytes This doesn’t look like a partition table Probably you selected the wrong device. Device Boot Start End Blocks Id System /dev/hda1p1 ? 7571 1693696 849806598+ 72 Unknown Partition 1 does not end on cylinder boundary. /dev/hda1p2 ? 1383568 2105988 364099898 72 Unknown Partition 2 does not end on cylinder boundary. /dev/hda1p3 ? 166444 166444 0 45 Unknown Partition 3 does not end on cylinder boundary. /dev/hda1p4 2804720 2804772 25947 0 Empty Partition 4 does not end on cylinder boundary. Partition table entries are not in disk order

With an even later verion of fdisk (disk v2.12q, run in August 20090), I got output similar to the first:

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xab611276. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won’t be recoverable.

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 m at this point, you get the following “menu”:

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)

To look at the existing partition partitions you input p, which gives you something like this:

Disk /dev/hda: 81.9 GB, 81964302336 bytes 255 heads, 63 sectors/track, 9964 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/hda1 * 1 222 1783183+ 7 HPFS/NTFS /dev/hda2 223 229 56227+ 83 Linux /dev/hda3 230 882 5245222+ 83 Linux /dev/hda4 883 9963 72943132+ f Win95 Ext’d (LBA) /dev/hda5 883 1078 1574338+ 82 Linux swap /dev/hda6 1079 2384 10490413+ 83 Linux /dev/hda7 2385 3037 5245191 c Win95 FAT32 (LBA) /dev/hda8 3038 3168 1052226 83 Linux /dev/hda9 3169 6811 29262366 83 Linux /dev/hda10 6812 7072 2096451 83 Linux /dev/hda11 7073 7725 5245191 83 Linux

(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 n, which then prompts me for a start cylinder:

First cylinder (7726-9963, default 7726):

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:

Command action e extended p primary partition (1-4)

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 t option to specify the type. Next you would input the number of the partition (so we might input 12 if we were adding a new partition) and then the hex code of the desired type. If you are not sure, you can input L and you will be shown a table of possible partition types:

0 Empty 1e Hidden W95 FAT1 80 Old Minix be Solaris boot 1 FAT12 24 NEC DOS 81 Minix / old Lin bf Solaris 2 XENIX root 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 5 Extended 41 PPC PReP Boot 85 Linux extended c7 Syrinx 6 FAT16 42 SFS 86 NTFS volume set da Non-FS data 7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 8 AIX 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs f W95 Ext’d (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT 10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/ 11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b 12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor 16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT

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 w 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.