How to configure/mount additional Drive in Linux

Mounting additional hard disks in Linux involves the process of making the operating system recognize and utilize the newly added storage devices. This can include internal hard drives, external drives, or other storage media. Mounting additional hard disks in Linux contributes to improved storage management, performance optimization, data organization, redundancy, and scalability, providing a more robust and flexible system environment.

To configure and mount an additional drive on a Linux system, follow these steps:

  1. Identify the Drive:
    • Connect the additional drive physically to your server or system.
  2. List Drives:
    • Open a terminal or SSH into your system and run the command lsblk or fdisk -l to list available drives and their partitions. Identify
      the new drive (e.g., /dev/sdb).command



      loop0 7:0 0 1.6G 0 loop /var/tmp
      sda 8:0 0 38.2G 0 disk
      ├─sda1 8:1 0 38.1G 0 part /
      ├─sda14 8:14 0 64M 0 part /boot/efi
      └─sda15 8:15 0 1M 0 part
      sr0 11:0 1 1024M 0 rom
  3. Partition the Drive (if not already done):
    • let’s use parted
      parted /dev/sdb

      oh no,

      -bash: parted: command not found

      let’s install parted first.

      yum -y install parted

      If at the end of the output, you find something like this, parted is installed successfully then.

      parted.x86_64 0:2.1-21.el6

      Once again run,

      parted /dev/sdb

      out put

      GNU Parted 2.1
      Using /dev/sdb
      Welcome to GNU Parted! Type 'help' to view a list of commands.

      on parted prompt, make a new partition table, called GPT dislabel

      (parted) mklabel gpt


      Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
      Yes/No? yes

      Next step is to set unit. Enter the unit as GB in following command. If you prefer TB, you may use that.

       (parted) unit GB

      to create a 3000 GB partition,

      (parted) mkpart primary 0.00GB 3000.00GB

      To see how partition is created,

      (parted) print


      (parted) print
      Model: ATA ST33000650NS (scsi)
      Disk /dev/sdb: 3001GB
      Sector size (logical/physical): 512B/512B
      Partition Table: gpt
      Number Start End Size File system Name Flags
      1 0.00GB 3000GB 3000GB primary

      Thats all, we are done with parted, now quit

      (parted) quit


      Information: You may need to update /etc/fstab.
  4. Format the Partition:
    • Use a file system tool like mkfs to format the partition. For example, for ext4: sudo mkfs.ext4 /dev/sdb1.
      warning by formatting the drive your data will be deleted
  5. Create a Mount Point:
    • Choose a directory where you want to mount the drive. For example, create a directory named /mnt/mydrive: sudo mkdir /mnt/mydrive.
  6. Mount /etc/fstab:
    • Open the /etc/fstab file in a text editor (e.g., sudo nano /etc/fstab) and add a line to automatically mount the drive at boot. Add a line like this:
      /dev/sdb1 /mnt/mydrive ext4 defaults 0 0
      • /dev/sdb1: The path to the partition you want to mount.
      • /mnt/mydrive: The directory where you want to mount the drive.
      • ext4: The file system type.
      • defaults: Mount options (you can customize this as needed).
      • 0 0: These are dump and fsck options, which are typically set to 0.
        Please update with caution, as any incorrect changes could result in the system becoming unreachable.
  7. Mount the Drive:
    • Either reboot your system or manually mount the drive using sudo mount -a. This will mount all entries listed in /etc/fstab.
  8. Verify:
    • Check if the drive is mounted correctly by running df -h or mount.

Now, the additional drive should be configured and mounted on your system. Any data written to /mnt/mydrive will be stored on the new drive. Remember to adjust paths and names based on your specific setup.