How To Add A New Hard Disk To Ubuntu Linux Desktop

Hard diskUbuntu has a large user base with millions of users across the globe. Some of them are geeks, while others are general users using it as a general purpose daily usage operating system on their home PC. Adding new hardware to a Linux desktop has always been a challenging task for an average user, no matter which flavor or brand he is using. General users are often scared of shell commands and restrict themselves in fear of breaking down the entire system. But with little reading and testing, you can have a good command over shell-based system and maintenance commands needed for properly maintaining the desktop. In fact, you'll enjoy exploring new things when you start using the shell environment. Today, we are going to learn about adding a new hard disk to your Ubuntu desktop. I'm assuming that you've already installed Ubuntu on the sole hard disk installed on your desktop. This tutorial will help you install an extra hard disk to the system.

Hard disk

This procedure has been tested on Ubuntu 12.04 LTS. I cannot guarantee that it will work seamlessly on older versions. So let's get started.

Physically install your hard drive

The first obvious step is to physically attach your hard drive with all the cables in place. Boot your PC and go to BIOS settings to confirm whether it has been successfully detected or not. Once you see the BIOS entry of your new hard drive, you can move ahead booting the system.

Decide on the filesystem to be used

Linux systems fly on ext3/ext4 filesystems and that should be your preference when installing a storage device on your Ubuntu desktop. If you're going to use it both in Windows and Linux, you should choose fat32/ntfs filesystem. For simplicity's sake, we will not consider the dual usage of the new disk with two different operating systems.

Check and note down important drive information

The next step involves noting down important information related to your new hard disk so that you can use that information for partitioning and mounting (activating) the hard disk. Make sure you run these commands from an administrator account. The following command will retrieve all the information Ubuntu has gathered about your new hard disk and the path it has been assigned.

sudo lshw -C disk

The command given above will display the following record containing all the information about your new hard disk.

        description: ATA Disk
        product: DG098DF09G809D-0
        vendor: Samsung
        physical id: 0
        bus info: ide@0.0
        logical name: /dev/sdb
        version: DA5GH62J
        serial: G709DGDG809DG8
        size: 126GB
        capacity: 126GB

Note: This is a sample output and the output on your terminal may differ slightly depending on the make and capacity of the disk.

Now, we are only interested in the following line from this output - logical name: /dev/sdb. This is the logical device path (/dev/sdb) assigned by Ubuntu to your newly installed hard disk. We'll be using this logical path in different commands to complete the configuration and installation of the hard disk.

Partition and format the hard disk

At this stage, your hard disk is in a raw state and is not usable by the operating system for general reading and writing. You have to create a logical partition on your hard drive and must format it with the appropriate filesystem to make space for storage.

You can partition and format your hard disk in different ways on a Linux system. You can complete this task both from the graphical desktop environment and through the regular shell commands.

Method - 1
You can use the GNOME Partition Editor to partition and format your hard disk directly from the graphical interface. If it's not installed on your Unbuntu desktop, you can easily install it through the following command.

sudo apt-get install gparted

This command will automatically search the respective software application and will install it without any user intervention. Now run this application from your desktop environment by double clicking the application's icon. This application automatically scans the entire system and populates the table with all the available hard drives. Search for label /dev/sdb in the list and select the white row or bar associated with the logical path. This white bar denotes raw disk space available on your new hard disk. Now follow these steps to partition and format it correctly.
  • Right-click on the white bar and choose 'New' option to create a fresh logical partition.
  • Choose 'maximum allowable' for the 'New size' option. This ensures you use the entire disk space for that single partition.
  • While selecting the partition type - choose 'Primary Partition'.
  • Next important step involves selecting the filesystem. Choose ext3 and click 'Add'.
  • This will change the graphical list and now you can see a new partition in the list.
  • Finally, click 'Apply' and wait till the entire partition is formatted.
Method - 2
Power users can opt for shell based partition and formatting commands to complete the same process discussed above. Here's a step-by-step procedure to get things done via shell prompt. Reminder: You must have the administrator privilege to use these commands.
  • Start with issuing the following command - sudo fdisk /dev/sdb. This will open the shell-based partition manager to configure your hard disk.
  • Now we need to create a new partition on the raw disk. Press 'n' and enter key to complete the command.
  • Next, we have to tell the type of partition it is going to be. Press 'p' and enter key to complete the command. This tells the partition manager that it's going to be a primary partition.
  • In the next step, you have to tell the application about the partition number for the newly created space. Press '1' as it will be sole partition on the disk.
  • Now press 'w' and enter key to write the new partition's entry in the system's partition table.
Now the new primary partition created through fdisk utility will be assigned the logical path - /dev/sdb1. This means that your Linux desktop system will recognize and use this partition as /dev/sdb1. At this stage, your newly created partition is unusable because there's no filesystem on the partition. To format it with your preferred filesystem, use the following command.

sudo mkfs -t ext3 /dev/sdb1

This command will format the newly created primary partition with ext3 filesystem. Now we have the following things in our hand.
  • You new hard disk has been successfully installed (physically) in your computer.
  • Your Linux desktop has assigned the following logical path for the entire raw hard disk - /dev/sdb.
  • You've created a new primary partition on this new disk covering the entire disk space.
  • Ubuntu has assigned the following logical path to the newly created primary partition on your new hard disk - /dev/sdb1.

Configure automated mounting of disk

Whenever a Linux computer boots, it reads the file /etc/fstab to mount (connect) different drives and partitions with their respective mount points (directories) so that data can be written and fetched from these drives and partitions. In simple words, this file brings all the hard drives in working condition such that users can use them easily through graphical or shell environment.

To use our new hard drive, we must create an entry in this file so that it is also mounted every time our system boots up. Simply use the following command to open the file.

gksu gedit /etc/fstab

Once the file is opened, paste the following line at the end of the file on a new line.

/dev/sdb1        /media/newharddisk        ext3        defaults        0        2

You can see we have used the mount point /media/newharddisk. Generally media directory is used in Linux to mount hard disks available in the system. You can use some other name in place of 'newharddisk'. This line tells Ubuntu to connect your new hard disk's primary partition with /media/newharddisk directory every time the system is booted. Any file or directories created under /media/newharddisk directory are essentially using the primary partition of your new hard disk. After writing this entry in the fstab file, you can reboot your Ubuntu desktop and can use your new hard disk.