![]() |
|
|
|
|
|
Fdisk for partitioning
By Mayank Sarup <mayank @freeos.com>
As you, by now, have realized that partitioning the hard drive is essential part of Linux usage. Partitioning data provides us with logical blocks for effective separation of data. Also, it's quite common to see multi-os machines these days, which require you to partition your hard drive. Fdisk is the tool you use for this purpose. Here we bring you a howto on fdisk for Linux, which mind you, is separate from the fdisk for Windows that most of us are familiar with. This is a matter of confusion for most rookies. For apart from sharing a name, there’s a world of difference between the two. Currently, most distributions offer nicer GUI front-ends. These not only hide much of the complexity but also lack the power that fdisk brings. Although it seems difficult at first, fdisk becomes a lot easier as you continue working with it.
Fdisk is started by “fdisk device”. The device will be the hard drive that you want to partition. You have to be the root. # fdisk /dev/hda You will now find yourself at the fdisk command-prompt. A “m” will bring up the available commands. Command (m for help): The first command that you give is “p”, to list the partitions on your drive. Disk /dev/hda: 255 heads, 63 sectors, 4963 cylinders Device Boot Start End Blocks Id System Lets now look at the naming convention used by Linux to represent the various partitions. You will encounter three kinds of partitions--primary, extended and logical. Historically, the partition table, which stores the size and location of partitions, was limited to four partitions. These were the primary partitions. As hard drives grew in size, so did the need for more partitions. And this gave rise to the extended partition, which is a primary partition with the capability of being split into an infinite number of partitions (actually, 63 partitions for IDE disks and 15 for SCSI) using a different kind of partition table storage. The extended partition is the container for logical partitions. Logical partitions, thus, are just partitions within the extended partition. The four primary partitions are numbered from 1-4 and the logical partitions start from 5 onwards. So, ‘hda1-hda4’ would represent the primary partitions. Extended partitions, essentially primary partitions, take up the numbers from 1-4. Regardless of the number of primary partitions, logical partitions will always start from 5, i.e hda5, hda6 etc. From the above extract/ we see that there are three primary partitions, one extended and three logical partitions defined. Also that there are some start and end values, which are the starting and ending cylinder values for the partition. The next columns show the blocks in use. The number of blocks should mirror the space allocated, in KB, for that partition. The next two columns are the numeric id of the partition and the partition type.
What should be your partition structure? Well, there are a couple of points you will need to consider when partitioning your drive. For example, Windows only boots off a primary partition. Linux doesn't have any such compulsions but LILO does have problems if your /boot partition lies beyond 1024 cylinders. This issue has been addressed in recent LILO releases, but most distributions carry the old problematic LILO. Newer releases of distributions are including the new LILO. The other solution is to create a small 15MB partition that lies before 1024 cylinders. You'll need a swap partition. Linux uses a separate partition for swap. You can use a swap file but be prepared for lost performance. We suggest you create your swap partition of the required size before you create your other partitions, as you might get carried away in creating Linux partitions, and be left with insufficient space for swap.
Partition creation is fairly easy. To create a new partition, press “n”. Now you will be asked whether you want to create a primary or an extended partition. Generally, you'll have three primary partitions and an extended partition that occupies the rest of the space available. Finally, you will create logical partitions within this extended partition. Command (m for help): n The above prompt is what you will see after you select the partition you want to create. Either enter a starting cylinder value here, or just press enter to use the first available cylinder (here 3925). Most of you will take the second option. Last cylinder or +size or +sizeM or +sizeK (3925-4963, default 4963): In case you're feeling really brave and want to enter the last cylinder for the partition, we suggest, you specify a size for the partition. Just pressing enter here will mean that all the free space available will be used for the partition. Enter the size in bytes--KBytes, Megabytes or Gigabytes. Prefix a “+"”to the size you want to allocate to the partition followed by a K, M or G to specify KByte, MByte or Gbyte. 2048M=2G. By default, fdisk creates a partition of type Linux with ID 83. This is incorrect, if you're trying to create a partition of type swap. You can change the partition type using the command “t”. Command (m for help): t You will be prompted for the partition number of the type you want to change and will be followed by: Hex code (type L to list codes): Each partition type has a number assigned to it. For the most part, the hex codes of the partition ID's are unique. In some cases, there are conflicts - Solaris partitions and Linux swap share the same ID. If unsure of the Partition ID, use “L” to check. As you can see, fdisk supports a wide variety of partitions from FAT to BSD to BEOS. We select 82 for Linux swap. Hex code (type L to list codes): 82 That was about creating partitions. But, what if you want to delete. Just press “d”. Command (m for help): d Key in the partition number and press enter. You will not get a confirmation message but you'll find yourself back at the prompt. Oops! That wasn't the partition that was to be deleted. /dev/hda7 was to go and not /dev/hda8. What do you do? Don’t panic. Just press “q” and exit without saving your changes. You will be dropped back at the prompt. Get back into fdisk and you will see that your partitions are intact. No changes you make to your disk partition will be committed until you explicitly use “w” to write changes to the partition table before exiting. Just check the partition list before doing so. Command (m for help): w Calling ioctl() to re-read partition table. Warning: If you have created or modified any DOS 6.x partitions, please see the fdisk manual page for additional information. Now that you have the partitions you want, go ahead and create a filesystem on them. There is one more option that's useful in “a”, which sets a partition as bootable. The bootable tag is useful because at boot, if no boot manager is running, control is transferred to the partition with the bootable flag set.
A friendlier interface can be seen with cfdisk. This is not just fdisk wrapped in a ncurses interface. And, it's not just a prettier interface. It's actually more competent than fdisk and some of the experiences that we've had with cfdisk, do bear these statements out. Why are we writing about fdisk then? Well, fdisk is what most distributions - Debian is one notable exception - provide as the alternate to their own front-ends. Red Hat and SuSE both give you only fdisk as the other option to their own partitioning tools. In most cases, you will want to use cfdisk. Cfdisk also supports most of the commands that fdisk does, so most of the above is applicable there too. There's also a sfdisk for macho freaks. It's totally command-line driven and is supposed to be the most powerful tool of the lot. We've not used this very often and luckily never faced a situation requiring sfdisk. Our thought when we see sfdisk -- "HELP". After this cursory look at fdisk you will agree that using it is not very difficult. All it needs a little getting used to. And as they say, ‘Practice makes Perfect’.
Other articles by Mayank Sarup
Current Rating: [ 7.11 / 10 ]
Number of Times Rated: [ 120 ]
|
|
|
© 1998-2004 FreeOS Technologies (I) Pvt. Ltd. All rights reserved.
[Privacy Policy]
![]() |