Add a hard drive in Linux

 

Steps:

 

1) Check to see how many drives are installed: 

Use the  fdisk command to verify how many drives are mounted. 

 

[root@linux]# fdisk -l | grep '^Disk'

The output should be similar to the following:

Disk /dev/sda: 500.1 GB, 500107862016 bytes
Disk /dev/sdb: 500.1 GB, 500107862016 bytes

 

2) To partition the disk - /dev/sdb, enter:

[root@linux root]# fdisk /dev/sdb

For help option and switches, use 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)


partitions using the command “p”:

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048   968615935   484306944   83  Linux

/dev/sda2       968617982   976771071     4076545    5  Extended

/dev/sda5       968617984   976771071     4076544   82  Linux swap / Solaris

 

3) To create a new partition, issue the command “n” and then select “p” for primary and 1-4 depending on which partition on the drive this is (first, second, third, or fourth):

n(creates a new partition)

p(creates a primary partition)

1(the number 1 denotes the partition will be /dev/sdb1)

Command (m for help):

  e   extended
   p   primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-6081, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-6081, default 6081): 6081
To save the partition, use the “w” command:

Command (m for help): w

                The partition table has been altered!

                Calling ioctl() to re-read partition table.

                Syncing disks.

                [root@default root]#

4) Format the new disk using mkfs.ext4 command:

To format Linux partions using ext3fs on the new disk, issue the following command:

[root@default]#mkfs.ext4 /dev/sdb1

5) Mount the new disk using the mount command: 

First, you'll need to create a mount point. We'll use /disk1. This is where we'll mount /dev/sdb1. Enter the following commands:

[root@default]# mkdir /disk1
[root@default]# mount /dev/sdb1 /disk1

[root@default]# df -H

6) Edit /etc/fstab so the new drive will automatically mount to /disk1 on reboot