Wednesday, May 17, 2006

Adding Additional Hard drive on your Linux Machine


Normally one would ask? how do i add additional harddrive to my linux box.. well we could make use of utilities like fdisk, cfdisk or QtParted but it is fdisk that is im going to discuss below.

Why FDISK.. the answer is simple. since fdisk is the utility that i've been using eversince i've tried linux. :)

Here are the steps:

You must first be able to identify which partion is your new harddrive either though dmesg or using fdisk utility

 # fdisk -l

The output will display the current harddrive informations and which device it is assigned to.
for scsi drive its normally /dev/sda while for IDE drive its /dev/hda

# fdisk /dev/hdc

Command (m for help): _

For a short manual we need to enter the 'm' command:

        Command (m for help): m
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)

Command (m for help):

We need to know just few necessary commands: d,p,n,q,w. Don't be afraid to use them--all your changes will be done only in memory and will only be written to the hard after the 'w' command is entered. If we have an error, we just need to cancel all changes with the command 'q'.

First of all, let's make ourself sure that disk is empty:

        Command (m for help): p

Disk /dev/hdc: 64 heads, 63 sectors, 787 cylinders
Units = cylinders of 4032 * 512 bytes

Device Boot Start End Blocks Id System

Command (m for help):

Often sellers of PCs and hardware will pre-divide disks into partitions. In such cases we can use command 'd' (described below) to delete everything what we do not need.

So, let's create a new parititon (with command 'n'), answering all the questions as we go:

        Command (m for help): n
Command action
e extended
p primary partition (1-4)

Choosing the partition type-- primary or extended--we will enter P for primary.

In choosing number of the partition in this example, we will assign all of the all free space to one partition. Because this will be the first and only existing partition, we will assign the number 1:

        Partition number (1-4): 1

When setting the number of the first cylinder of the partition, we can just use the default value, which is recorded when we just press Enter:

        First cylinder (1-787, default 1):
Using default value 1

Setting the number of the last cylinder of the partition is easy in this example, since we are filling the entire drive with one partition. Again, just press Enter for the default (instead of the number of the cylinder, we can set size of partition in bytes, kbytes, or megabytes):

        Last cylinder or +size or +sizeM or +sizeK (1-787, default 787):
Using default value 787

Command (m for help):

Now, partition is created. We can take a look of new table of partitions with the help of the 'p' command:

        Command (m for help): p

Disk /dev/hdc: 64 heads, 63 sectors, 787 cylinders
Units = cylinders of 4032 * 512 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 1 787 1586560+ 83 Linux

Command (m for help):

If we don't like (for some reason) the location or number of the partition, we can delete it using 'd' command:

        Command (m for help): d
Partition number (1-4): 1
Command (m for help):

If you want to divide the disk into a few partitions, you will need to repeat all these operations a few times. One thing that is important to remember is that if the amount of partitions is greater than four, you'll need to create not primary, but an extended partition across the whole available disk space. Inside this partition you can create as many logical parts as needed.

Remember, please, that logical partitions always should be numbered from 5 upwards; it doesn't matter how many primary partitions were created before (one, three, or none at all).

After a partition has been made. you may want to format it using mkfs command. you could use mkfs.ext3 depending on what type of partiition that you desired.

mkfs.ext3 /dev/hdc1

After formating you may want to mount it to your linux box so that you could use it already

mount /dev/hdc1 /u01

or simply add it on your fstab so that you dont need to remount it everytime your system is restarted.

No comments: