Preparing a Hard Drive from the Command Line

The following are instructions for creating the partitions you want for your hard drive using cfdisk and then also formatting those partitions accordingly so you can install data on to them.

Using cfdisk
Here is a sample of my partition scheme: cfdisk 2.12

Disk Drive: /dev/hda
Size: 120034123776 bytes, 120.0 GB
Heads: 255 Sectors per Track: 63 Cylinders: 14593

Name Flags Part Type FS Type [Label] Size (MB)
------------------------------------------------------------------------------
hda1 Primary Linux swap 509.97
hda2 Boot Primary Linux ReiserFS 98.71
hda3 Primary Linux ReiserFS 3997.49
hda4 Primary Linux ReiserFS 115425.36


[Bootable] [ Delete ] [ Help ] [Maximize] [ Print ]
[ Quit ] [ Type ] [ Units ] [ Write ]

Toggle bootable flag of the current partition

*Note, this is after formatting, so where you currently see "ReiserFS" was previously just called "Linux".
Navigating cfdisk:

up and down arrows toggle the partitions
left and right arrows toggle the options at the bottom (Bootable, Delete, Help, etc)
To create a new partition, use the up/down arrows the highlight the free space, select "New", "Primary" (unless you need to use logical for some reason), "Beginning" and then enter in the amount of space you want to use (it's in mb). Then go to type and enter in the type of partition it will be - basically there are two main choices - 82 is linux swap, 83 is linux. These are general selections right now - keep in mind: CFDISK DOES NOT ACTUALLY FORMAT YOUR PARTITIONS, it just creates a partition table. Do the partitions in an order that makes sense such as - "swap", "boot" (if used), "root" and then anything extra like "home" to be mounted later during the install. Repeat the same steps to create the other partitions, when done, toggle one as bootable. As you can see I have my "boot" (hda2) partition as bootable, but if you do not have boot, you might want to make yours where you created your "root". Otherwise, if you have another install on your partition scheme that is already toggled as bootable, you might want to leave it that way. When done, select "write" and type in "yes" when you are sure it is right and then press enter. *Make a note of what partition number you created each on - you will need to know this!

 
 

Now you will need to format the actual partitions so that data can be store on them. The following are the appropriate commands for formatting several different file systems. It is up to you to decide on which one is best for you, but here are the commands:

ext2 mke2fs
ext3 mke2fs -j
reiserfs mkreiserfs
xfs mkfs.xfs
jfs mkfs.jfs

The commands to actually format these filesystem would go with the following syntax:

mkreiserfs /dev/hda1
Once you have formatted the partitions, one thing you will then need to do is to specify which partition corresponds to where you want to mount it.
For example, for your swap partition the mounting is fairly straightforward and different from your other partitions. For swap, you can do:
mkswap /dev/hda1
then
swapon /dev/hda1
Of course this would be true if your swap was on /dev/hda1.
For your other partitions, you will need to create directories for each of them. Another example is if you want to add a /home/ partition to an existing partition table. Let's say your current setup is as follows:

swap = /dev/hda1
boot = /dev/hda2
root = /dev/hda3
and you want to add a /home partition so you can have your personal settings and saved files on a setup partition than your system or root partition. So, for the entire process (assuming you have the free space and want to use the reiser file system:

cfdisk 2.12

Disk Drive: /dev/hda
Size: 120034123776 bytes, 120.0 GB
Heads: 255 Sectors per Track: 63 Cylinders: 14593

Name Flags Part Type FS Type [Label] Size (MB)
------------------------------------------------------------------------------
hda1 Primary Linux swap 509.97
hda2 Boot Primary Linux ReiserFS 98.71
hda3 Primary Linux ReiserFS 3997.49
Free Space 115425.36


[Bootable] [ Delete ] [ Help ] [Maximize] [ Print ]
[ Quit ] [ Type ] [ Units ] [ Write ]

So, we see that there is quite a bit of free space so we might as well create a partition for it to use. The first thing is to scroll down to where it says Free Space and then select New and then Primary (I prefer to use Primary as long as it's available - remember there are four possible primary partitions to each hard drive). Once it has been selected, you can go to Type and select Linux. When that is done, dont forget to Write the partition table! When writing has completed, press Q for quit and you should be back to your command line.

Now that the Cfdisk steps are done, it is time to create the filesystem on that partition which according to the above partition table would be /dev/hda4. In this example, since the /home directory has already been created and may even be in use right now if you are doing this on the same hard drive, it is better to just format the new partition and then add it into your fstab. So, to format the partition:
mkreiserfs /dev/hda4
when formatting is done, you can just add a line into your /etc/fstab to activate this partition after rebooting. An example of an fstab line you would add in this example would be:
/dev/discs/disc0/part4 /home reiserfs defaults 0 0
so after rebooting, you should be able to do:
df -h
in your terminal and you should see that added partition which should allow you a lot more space to use.
Of course this is just one example, but the same principles can be used in other situations.