How to add new disk to existing Linux system

When you are adding a new disk to an existing Linux system, you will need to format and partition it, add a file system to it, and then mount the disk to some path where you plan to access it from. This might sound complex or like a lot of steps, but it really only takes a few minutes. The following tutorial will make it very easy.

In this tutorial, we will cover the step by step instructions to add a new hard drive or solid state drive to an existing Linux system. We will show the steps for both command line and GUI methods, so you can follow along with set of instructions you are most comfortable with. Let’s get started.

In this tutorial you will learn:

  • How to format and partition a disk with fdisk
  • How to add a new file system with mkfs
  • How to mount and access the new disk
  • How to prepare a new disk via GUI
How to add new disk to existing Linux system
How to add new disk to existing Linux system
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software fdisk, mkfs, mount, Disks GUI utility
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to add new disk to exisiting Linux system step by step instructions




There are two sections below. In the first one, we add a new disk via command line. If you would prefer the GUI method, scroll down to the next section you see.

Add new disk via command line

Open a terminal and type the following commands to format your new hard drive or solid state drive:

  1. First, let’s figure out how to identify the new drive we wish to format. The name should start with /dev/sd and then a letter. Type the following command in terminal to see:
    $ sudo fdisk -l
    
    Find your device name in the fdisk output
    Find your device name in the fdisk output
  2. In our example, the new drive has been assigned /dev/sdb device path. To create a new partition on the empty disk, we will provide it as argument to fdisk:
    $ sudo fdisk /dev/sdX
    
  3. The fdisk utility awaits our commands. We would like to create a new partition, so we press “n”.
    Command (m for help): n
    
  4. We are to create a primary partition, so the answer to the next question is “p”.
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p
    
  5. The next questions are about partition number, first and last sector, which will determine the actual size of the partition. In our example we are creating a single partition that will cover the disk, and default values are first partition, first available sector to start, and last sector to end with, which is just what we need. So we will accept the defaults for these questions.
    Partition number (1-4, default 1): 
    First sector (2048-104857599, default 2048): 
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-104857599, default 104857599): 
    
    Created a new partition 1 of type 'Linux' and of size 50 GiB.
    



  6. The partition is now complete, but as the utility points out on start, the changes are in-memory only until we write them out to the disk. This is on purpose and the warning is in place for a good reason: by writing out the changes to the disk, we destroy anything that resided on the sector range we cover with our new partition. We are sure there will be no data loss, so we write the changes to disk:
    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.
    
    We are finished partitioning the new drive with fdisk utility
    We are finished partitioning the new drive with fdisk utility
  7. Next, we still need to add a file system to our hard disk. Our new partition is under the device path of /dev/sdb1 (use fdisk -l command to see your own). Use the mkfs command to format the disk with any file system you would like. In this example, we are using ext4, which is the recommended file system for new HDDs and SSDs on Linux:
    $ sudo mkfs -t ext4 /deb/sdX1
    
    Formatting our new disk with the ext4 file system
    Formatting our new disk with the ext4 file system
  8. We will now use the mount command to mount the newly formatted partition on our system. We will mount our new disk to the /media/disk directory.
    $ sudo mkdir -p /media/disk
    $ sudo mount /dev/sdb1 /media/disk
    




That’s all there is to it. You can now access your newly formatted drive under the /mount/disk directory or where ever you decided to mount it. To make the drive get mounted automatically, see our guide on configuring the /etc/fstab file.

Add new disk via GUI

Depending on what Linux distribution you are using, the screenshots below may not match up with exactly what you see on your own screen. We are using Ubuntu Linux in these steps and the GNOME desktop environment, but the process should be mostly the same no matter what distro you are on. The key point is that you will need to find and open your operating system’s disk utility software.

  1. Get started by opening your system’s disk management application.
    Open the disk utility software from the application launcher
    Open the disk utility software from the application launcher
  2. You should see your new disk listed among the other storage devices on your system. Make sure you select the one that you wish to format.
    The disk is listed among the other storarge devices on the system
    The disk is listed among the other storarge devices on the system
  3. You will have several options on what to do with this drive. Click the one that says “Format Disk” or something similar.
    Select to format disk from the menu of options
    Select to format disk from the menu of options
  4. On our test system, we have a few different options for erasing and partitioning our new disk. A quick format will not securely erase the current data on the disk but it will perform the formatting very quickly, as the name implies. The other option is to rewrite the disk with all zeros (not necessary in the majority of situations). You can also create a MBR or GPT table, or apply no partitioning. If you are not sure, just leave the defaults selected and click “Format.”
    Choose formatting options or just leave the defaults
    Choose formatting options or just leave the defaults
  5. As mentioned earlier in the guide, this process will completely erase the contents in your disk. The formatting software warns us once again to make sure we are aware, then it wipes the drive completely.



    Confirmation box about wiping the hard drive
    Confirmation box about wiping the hard drive

That’s all there is to it. If you chose the quick format option, the whole process should only take a matter of seconds. If you would like to learn how to do this via command line, which is more universal across all Linux systems, we cover that in the previous section.

Closing Thoughts

In this tutorial, we saw how to format a new disk that was added to an existing Linux system. We used the ext4 file system to complete the job, which is the recommended configuration that you use for optimal performance. The GUI method of formatting a new drive proves a bit easier, as the program does some of the legwork for us. However, manually formatting a drive from the command line gives us more control and really is not that hard either.



Comments and Discussions
Linux Forum