Friday, 7 January 2005

Installing a new hard drive in your PC running Linux

If you have brought a brand new hard drive and wish to install it in your computer running linux, these are the steps to follow:

Assuming that you have already physically attached the hard drive into your PC, boot up your machine and when linux loads, log in as root. Since this is your second hard drive, it's device name will be /dev/hdb if it is a IDE drive and /dev/sdb if your hard disk is a SCSI disk. I am assuming that it is an IDE drive which is the most commonly used in home PCs.

You can use the fdisk utility in linux to view the partition information as well as create, modify or delete the existing partitions in the new hard disk. To view the partition information, execute :

root# fdisk -l /dev/hdb
If no partitions are seen, then you have to create them. For that, you can use eaither fdisk itself or another more user friendly program called QTParted.

QTParted creates, deletes, and non-destructively moves and resizes partitions (even NTFS). So, you can make room to copy your data without losing anything.If you have QTParted installed on your machine, then I would recommend using it as it is much safer.

Here I will explain the fdisk way of creating a partition. It is medium safe to play around with fdisk as changes are not written to disk until you give the command to do so. This sequence of commands create a single partition.

root# fdisk /dev/hdb
Type "m" at anytime to display a table of fdisk commands. Then type "n" to create a new partition. Now type "p" to create a primary partition. Your disk can have from 1 to 4 primary partitions. Hit Enter twice to accept the defaults. Or if you don't want to use the whole disk, hit Enter once to accept the default starting point, then select the size you want:

+1000M
Hit "p" anytime to preview the new partition table. When you are satisfied with the partitions created, press "w" to write the changes to disk. By default, fdisk creates a type 83 partition, which means linux partition. To see a list of partition types, press "l". To change the partition type, press "t". To delete an existing partition, press "d" and follow the prompts.

After you have created the partitions and exited fdisk, the next step is to format the disk for the file system of your choice. This is done with the mkfs utilities.For example, if you want to create an ext2 filesystem on the newly formated hard disk, execute the command:

root# mkfs.ext2 -c /dev/hdb1
Note: Since I have created only one partition on the entire hard disk, the partition is named /dev/hdb1. If you had created another primary partition, then the second partition would have been /dev/hdb2 and so on. And if instead of a second primary partition, you had created a logical partition, it would have been named /dev/hdb5.

If instead of an ext2, you wanted to create an ext3 partition, then execute the command:

root# mke2fs -j -c /dev/hdb1
-j specifies journaling support. To create a reiser filesystem:

root# mkreiserfs /dev/hdb1
I hope you are getting the idea. Now the last step is to mount the partition so that you can start saving data in your new hard disk. For that execute the command :

root# mount -t ext3 -o rw /dev/hdb1 /mnt/hdb1
The above command mounts the /dev/hdb1 partition on the mount point /mnt/hdb1. The "-t" flag says that the partition is of type ext3 and the -o flag specifies that it has to be mounted as "rw" read-write.

To unmount the partition, type the command:

root# umount /mnt/hdb1
Now each time when you boot into linux, if you want the new hard disk to be mounted by the OS automatically, then you have to include (add) the following line in your /etc/fstab file:

#File: /etc/fstab

/dev/hdb1 /mnt/hdb1 ext3 auto,users,exec 0 0
The above line mounts the partition at mount point /mnt/hdb1 as type ext3.

Now you have finished installing the new hard disk in your linux machine.



No comments:

Post a Comment