Thursday, February 9, 2012

Install a Second Hard Drive on Linux

Installing a second hard drive is easy if you know how. I needed to do this on my computer and below is the steps, please follow this.

I assume that you have installed the hard drive in your PC, and you have rebooted your machine. In this example our primary hard drive is located at /dev/hda and our second, new hard drive is located at /dev/hdc (replace according to your system)

Partitioning your new drive
Next up we need to partition our drive with this command :
cfdisk /dev/hdc

The cfdisk controller will load up and here you can create a new partition on your drive. From the menus at the bottom I selected the following :
1. New >> Primary >> Size in MB
2. Once done select Write
3. Select Quit
Your new partition has been created at /dev/hdc1

Format the new disk
Now that we have a new partition at /dev/hdc1 we need to format it for usage by the system. From a Linux shell type :
mkfs.ext3 /dev/hdc1
This will now format our partition with the ext3 filesystem which should work fine for your Debian system.

Mount your new drive
Now that we have partitioned the drive and formatted it we can now mount the drive to begin using it. From a shell run:
mkdir /new-disk
mount -t ext3 /dev/hdc1 /new-disk
The above commands create a new directory for the drive to be mounted in and then we mount the drive to this directory. To check that the drive has been mounted run the following:
ls -lsa /new-disk
You should see the following:
# ls -lsa /new-disk
total 24
 4 drwxrwxrwt  3 root root  4096 2007-01-29 01:57 .
 4 drwxr-xr-x 22 root root  4096 2007-01-29 01:58 ..
16 drwx------  2 root root 16384 2007-01-29 01:57 lost found
Adding to fstab
Everything is now up and running however we need to add our new drive to /etc/fstab so that it will be mounted automatically when we reboot the machine. First let's edit fstab :
vim /etc/fstab
At the end of the file add the following line:
/dev/hdc1       /new-disk            ext3    defaults,errors=remount-ro 0       1
Save the file and you're done.

No comments: