Installing and formatting a 2nd HDD for on an ubuntu server

Installing, formatting and using another hdd in linux (asside from the OS drive) is unfortunately not quite as simple as the plug and play’ness of Windows and Macs.

In Ubuntu (and pretty much all unix based os’s) a drive must be “mounted” to be used. To be able to mount a drive the HDD must be in the correct format.

1 – Check the drive is visible to the os

Which should spit out something like this (note the different drive names in red):

Notice that the second hard drive (/dev/sdb: 500.1 GB) doesn’t show any partitions like the first drive does. (/dev/sda: 41.1 GB)

2 – Partition the 2nd HDD on the command line (you can use gparted if using the desktop version of ubunutu)

Before the drive can be used there must be at least one partition. fdisk is the tool for the job. Run fdisk on the new drive

Fdisk will display the following menu:

For now I only want to create new a single partition for the whole hdd so hit ‘n’ and enter.

We want a primary partition so hit ‘p’ then enter.

If this is a new drive then just choose 1 when asked for the Partition Number. If this is not a new HDD you may want to remove all other partiions first, ie delete them.

Now choose option “w” to write the partition table to the disk. Type “w” and enter.

3 – Format the new partition

Format the new partition by passing the following command (this may take a while depending on the drive size):

NB the 1 at the end there represents the partition number.

4 – Create a “mount  point” for your new hdd

Now that the drive is partitioned and formatted, you need to choose a mount point. This will be the location from which you will access the drive in the future. I would recommend using a mount point with “/media”, as it is the default used by Ubuntu. For this example, we’ll use the path “/media/2ndhdd”

5 – Tell ubuntu to auto mount the drive to your mount point when the system loads up

You can choose to have the drive mounted automatically each time you boot the computer, or manually only when you need to use it. ‘Fstab’ is a file that is read when your os loads, and in turn loads any drives it is told to.

Add this line to the end of the fstab file:

Your new drive will now be available in the ‘/media/2ndhdd’ the next time your os reboots.

To get the system to read the fstab file now run:

To manually mount just use the following:
mount:

unmount: