Linux Fdisk

Although most distros now will have their own graphical disk partitioning tools, it never hurts to be familiar with fdisk. Turbo Linux, for example, says that cfdisk is easier to use, but then adds that if it doesn't work, try fdisk.

So, we will make an example. Say we have one hard disk, of 10 gigs, with Windows installed in the first partion, which is 2 gigs. We now want to make Linux partitions. Even though most versions of LILO can now boot beyond the 1024th disk cylinder, for practice, we'll make ourselves a small boot partition.

We're going to keep this simple, so we're going to do it this way. We'll make a swap file, boot partition and one more Linux partition to hold the rest of our installation.

So, first, to see what we have, we type

fdisk /dev/hda

This will start the fdisk program. Now, to see what is already there, type


The p stands for print, and will show you what exists. At present, you should only have one partition, the one that is holding Windows. (I've found that Windows seems to partition disks differently--with Slackware, for example, I also get a warning that the partition doesn't end where it should--however, it hasn't caused me problems, so, I shrug it off.)

Next, I type m for help. (In this case, I assume it stands for manual). It will show me the possible commands.

Firstly, I want to create my swap partition. The reason I put it first is because I once read, though I've never verified it, that putting the swap partition first puts it towards the outside part of the drive, which enables more area to be read as the drive rotates.

One could make a new primary partition, but I don't find it necessary so, I type


I'm then asked do I want a primary partition or extended partition. I'm told to type p for primary or e for extended. I choose e for extended. Next I'm asked for a number for the partition, usually given the choice of 1-4. I pick 2 as it's the next partition.

It will then ask for the first cylinder, showing the default, which is the next cylinder next to the already existing Windows partition. Hit enter to accept the default. Then it asks for the last cylinder--the default is the end of the drive and again I hit enter to accept it.

I then again type p to verify that I did what I wanted. Hopefully it is showing me what I asked for.

Now I type n again for a new partition. This will be my swap partition. I'm asked do I want to make a primary one or a logical one. As you might guess, I'm told to type p for primary and l for logical. I choose l, as Im making a partition within the extended partition.

I'm then informed that the numbers will begin at 5. I'm then asked for the first cylinder--again I choose the default, which is the first cylinder available.

I'm then asked for the last cylinder--however, I'm also given the option of specifying my size in Megabytes by typing + (desired size)M. I want my swap partition to be 128 Megabytes so I type


I hit enter. One could type p again to verify that it's going the way you want it to, that's up to you. Doing that, I find that this 128 Meg partition is Linux native, which I don't want, I want Linux swap. So, I then type


It will ask me which partition's type do I want to change. I pick 5, which is my first logical partition. (I can also discover this with the p command--the partition will be /dev/hda5). I'm then asked for the type, and told I can type L for a list of hex codes. I already know that swap is hex code 82, so I type 82.

Now, I'm making my boot partition. This can be of various sizes--RH recommends 16 Megs, so I make it 20 Megs just in case. So, I begin by typing


Again, I'm presented with the choice for logical or primary and choose logical. Again I'm given the default 1st cylinder, which I accept and again asked for the last cylinder, with the option to specify size in Megabytes.

I type


This gives me a 20 meg partition to use as boot. It might be slightly different, as like the fdisk found in DOS (though probably more efficiently) fdisk will determine cylinder boundries and adjust accordingly.

Once again I type p to see what I have. I now see one Windows partition, and one extended partition. The extended partition has one 128 meg logical partition as Linux swap and a 20 meg Linux native partition.

So, once again, we type n to create the final partition. (If you were making separate partitions for /usr, /home, etc you could make more--however, we're keeping it simple here.

Again, I'm asked to choose between logical and primary and choose logical. I'm asked for the first cylinder, with the default being the first unused one, which I accept by pressing enter--I'm then asked for the last cylinder, with the default being the last cylinder on the disk. Once again I press enter to accept it.

Lastly, I press


This writes the changes to disk--there are various warnings and messages. In most cases, you're done. In others, you might be told that you have to reboot for the changes to take place.

Usually, in the distros I'm familiar with, you then go on to the next step of choosing target partitions--RH,for instance, will then show you the partitions and ask you to choose mount points for the Linux native partitions--it assumes that the swap partition is being used for swap. Slack will choose the swap partition, then, at least with 7.1 ask you where you want to put your root partition. Be careful here. Remember, in the example, it was /dev/hda7. Slack will see two Linux partitions, /dev/hda6 and /dev/hda7. If you try to put your / partition on that small /dev/hda6 partition that we made for /boot, you will have problems.

After formatting the / partition, Slack will then ask for a mount point for the remaining partition--this is where you can enter /boot.

Each distro varies in how they handle this, but it's usually straightforward. One can also avoid that problem by skipping the /boot partition and simply making two partitions for Linux--swap and the main one.

As you can see, fdisk isn't that difficult to use.