How to add a new drive to a linux system

linux-penguinThere are various ways to add a new hard drive to a linux system. Although you can use GUI based solutions like GParted, we are going to concentrate here on using the command line. Adding a hard drive is such a basic requirement, it's going to be useful to have a standard approach regardless of your chosen linux distribution.


Terminal Session

You initially will need to run the following commands to get info:

$ sudo df -k
$ sudo cat /proc/partitions

Then once you know which disk you want to work on (eg. sdb) run...

$ sudo fdisk /dev/sdb
The number of cylinders for this disk is set to 48641.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)

Issue the p command to print all known partitions on the disk.

Command (m for help): p
Disk /dev/sdb: 400.0 GB, 400088457216 bytes
255 heads, 63 sectors/track, 48641 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System

Issue the n command to create a new partition

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-48641, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-48641, default 48641):
Using default value 48641

Issue the p command again to see the changes

Command (m for help): p
/dev/sdb1 1 48641 390708801 83 Linux

Now write the changes and quit

Command (m for help): w

Now you need to verify you new partition:

$ sudo cat /proc/partitions

Or

$ sudo fdisk -l

Next you need to format the partition with the mkfs command

$ sudo mkfs -t ext3 /dev/sdb1

You will now need to create a mount point directory, to which the new partition will be attached.

$ sudo mkdir /mnt/sdb1

Add a new line in the etc/fstab file so that this partition will mount automatically.

$ sudo vi /etc/fstab
/dev/sdb1 /mnt/sdb1 ext3 defaults 1 2

To mount the new partition now...

$ sudo mount /mnt/sdb1

 

Thanks for visiting.