Pin Me

10 Easy Steps to Install a Second Hard Drive in Linux

written by: Chris Flood•edited by: J. F. Amprimoz•updated: 8/8/2010

When you plug a new hard drive into a computer running Linux, you might not get all the pop-ups and friendly dialogs that Windows or Mac OS X provide to help you through the process of formatting your drive. This article walks through hard drive set-up in Linux in ten easy steps.

  • slide 1 of 3

    Introduction

    When you physically install or plug in a second hard drive on a computer running Linux, you might not get all the automatic installation and set-up dialogs you are used to seeing with Windows or Mac OS X. However, adding a second hard drive is actually quite easy, as this article will show.

    By far the easiest approach for newcomers to Linux is to use GParted, which comes with popular distributions like Ubuntu and Puppy Linux, and provides a graphical interface for creating, formatting, and mounting partitions on your hard drive. If you do not want or are unable to install GParted, you can instead use cfdisk or fdisk from a terminal window to set up your hard drive in no more than ten easy steps.

    Before you get started, you will need to have physically installed or plugged in your new hard drive, opened a terminal window, and know the name of the drive. You can find this by entering "fdisk -l" in a terminal window, which will show you a list of all the drives currently connected to your computer.

  • slide 2 of 3

    Using cfdisk

    The simple text-based utility cfdisk is a bit easier to use than fdisk for the Linux newcomer. You use it entirely within a terminal window and can navigate its clearly labeled options using a keypad. With the instructions below, you will create and mount a partition formatted for Linux on your hard drive. By altering some of the options, you can resize the partition, format it so other operating systems can use it, and delete old partitions.

    1. Enter "cfdisk [disk name]" (ex., "cfdisk /dev/sdb"). The cfdisk utility will load in the terminal window.
    2. Using the arrow keys, select [New] to create a new partition.
    3. Select [Primary] unless you are sure you want to select [Logical].
    4. Enter the size of the partition you want to create. By default, you will fill all the remaining space on the disk.
    5. Select [Type] and enter "83" to create a Linux partition.
    6. Select [Write], enter "yes" and wait for the partition to be written to the disk.
    7. Select [Quit] to return to the command line.
    8. Enter "mkfs.ext3 -b 4096 [partition name]" to create an ext3 filesystem on your partition.
    9. Create a directory where you want to mount your new partition. These are typically in /mnt or /media (ex., /mnt/new_disk).
    10. Enter the command "mount [partition name] [mount point]" (ex., "mount /dev/sdb1 /mnt/new_disk").

    As you will see in the next section, the steps you did in cfdisk mimic those you would take with the command fdisk, but, with cfdisk, you are able to see the most common options laid out before you.

  • slide 3 of 3

    Using fdisk

    Most tutorials for installing a second hard drive in Linux provide instructions for using the command fdisk. While this approach is intimidating for beginners, it can be simpler and more powerful for users comfortable with the terminal. As with cfdisk, these instructions enable you to create and mount a partition formatted for Linux on your hard drive. By altering some of the options, you can resize the partition, format it so other operating systems can use it, and delete old partitions.

    1. Enter "fdisk [disk name]" (ex., "fdisk /dev/sdb"). You will then be asked to choose a command to enact upon the disk.
    2. Enter "n" to create a new partition. You will then be asked to pick an extended or primary partition.
    3. Enter "p" for a primary partition, unless you are sure you want to set up an extended partition.
    4. Enter "1" to assign the number 1 to your new partition (ex., sdb1) or another number if you want.
    5. Hit enter twice to establish the partition across the default space fdisk has chosen for you.
    6. To set up the partition's system ID, enter "t", select the appropriate partition and enter "83".
    7. Enter "w" to write the new partition to the disk and exit. You have now created a partition on your disk!
    8. Enter "mkfs.ext3 -b 4096 [partition name]" to create an ext3 filesystem on your partition.
    9. Create a directory where you want to mount your new partition. These are typically in /mnt or /media (ex., /mnt/new_disk).
    10. Enter the command "mount [partition name] [mount point]" (ex., "mount /dev/sdb1 /mnt/new_disk").

    That's it! You've successfully installed a second hard drive from the command line. If you want to see more details on the steps outlined above, check out this tutorial on Linux Planet, and, for a complete list of fdisk options, look at this page on YoLinux.com.

Installing and Formatting Hard Drives and Partitions in Linux

Setting up a new hard drive or reformatting an old one might not be as intuitive in Linux as it is in mainstream operating systems, but, once you get the hang of it, you will have superior flexibility and power over your data.
  1. 10 Easy Steps to Install a Second Hard Drive in Linux
  2. When and How to Format and Partition a Hard Drive in Linux