How to Add a New Disk Drive to a Linux Machine
Linux

How to Add a New Disk Drive to a Linux Machine

In this article, we will demonstrate How to Add a New Disk to an Existing Linux Server and some simple steps that you can use to increase disk space on Linux CentOS 7 without rebooting the server using Linux commands.

There are two different types of firmware on a motherboard

  • Legacy BIOS (Basic Input Output System)
  • UEFI (Unified Extensible Firmware Interface)

Disk management perspectives the key distinction between Legacy BIOS and UEFI is that whereas UEFI supports both MBR and GPT partition schemes, BIOS only supports the MBR partition scheme.

How to Add a New Disk to an Existing Linux Server in hard drives and solid state drives are two examples of physical block devices that are used to store data. Before a hard drive can be used, it must have a partition table. Master Boot Record (MBR) and GUID Partition Table (GPT) are the two types of partition tables. If the system has BIOS, we can only use MBR partition tables, if the system has UEFI we can use any partition table.

Add a New Disk in Linux Server

How to Add a New Disk to an Existing Linux Server with a detailed step-by-step explanation has been discussed. Before going to start understanding the concept of a partition.

Run the below command to check the type of partition table in your server

parted -l
How to Add a New Disk to an Existing Linux Server

Check if Computer Uses UEFI or Legacy BIOS

  • If Partition Table contains gpt – this is a GPT partition table
  • If Partition Table contains msdos – this is a standard MBR partition table

What is a partition?

Divide a single hard drive into many logical drives. A partition is a contiguous set of blocks on a drive that is treated as an independent disk. In a partition table, partitions are assigned to sections of the hard drive.

Types of partitions:

  1. Primary Partition
  2. Extended partition
  3. Logical Partition

What is Filesystem?

It is a method of storing data on a disk in an organized manner. Except for the MBR and Extended partitions, every partition on the disk should be assigned a file system to store data. The term ‘file system’ is applied to a partition by formatting it with a specific type of file system. You can format all Partition Types in the same way.

 Add a New Disk to an Existing Linux Server:

As mentioned below 2 different kinds of partition.

Disk Partitioning Criteria in MBR

Disk Partitioning Criteria in MBR

MBR stores the boot and partition data in the same location at the start of the partition. If this data is missing or corrupted, the entire operating system fails because the bootloader is broken. In MBR, the maximum supported disk size is 2Tebibyte (TiB).

  • Every disk can have only 4 Primary Partitions (3 Primary + 1 Extended)
  • A primary partition is one that usually contains the operating system.
  • An Extended Partition is a special type of primary partition that can be subdivided into multiple logical partitions. If the user wants to make more partitions than three primary partitions, all available space on the disk should be divided up among extended partitions, which will eventually be used to create logical partitions. Per disk, there can only be one extended partition
  • With the help of extended partitions, we can create a maximum of up to16 partitions
  • Under the extended partition, logical partitions can be created by using all the space within the extended partition.
CRITERIA OF DISK PARTITIONING IN GPT:
Disk Partitioning Criteria

Disk Partitioning Criteria GPT

  • It supports up to 128 partitions per disk
  • The partition size is limited to 8 Zebibyte (ZiB). GPT stores multiple copies of boot and partition data across multiple discs. These duplicates can be used to recover the corrupted data.
  • Furthermore, GPT includes a cyclic redundancy check (CRC) that checks the data’s integrity on a regular basis. If one file is corrupted, the system will boot from the other file

Disk Identification:

In Linux, different types of disks will have different initials:

  1. Integrated Drive Electronics (IDE) drives will be shown as /dev/hda, /dev/hdb, /dev/hdc, etc., and partitions are like /dev/hda1, /dev/hda2, /dev/hda3, etc
  2. Internet Small Scale System Interface (iSCSI)/Small Scale System Interface (SCSI) and Serial Advanced Technology Attachment (SATA) drives will be shown as /dev/sda, /dev/sdb,..etc., and the partitions are like /dev/sda1, /dev/sda2, …etc.
  3. Virtual drives are like /dev/vda, /dev/vdb, /dev/vdc, …etc., and the partitions are /dev/vda1, /dev/vda2, /dev/vda3, etc.
  4. Non-Volatile Memory express (NVMe) attached storage /dev/nvme0, /dev/nvme1.

Types of file systems supported in RHEL/Centos:

  • Ext2 → Second Extended File System (Maximum file size is 2TB & default in RHEL 3 & 4)
  • Ext3 → Third Extended File System (Maximum file size is 2TB & default in RHEL  5)
  • Ext4 → Fourth Extended File System (Maximum file size is 16TB & default in RHEL  6)
  • xfs → Extended file system (Maximum file size is 16 TB & default in RHEL 7, RHEL 8 & 9)
  • tempfs → Temporary File System (TMPFS) file system stores all of its files in virtual memory.

Partition Creation and Configuration in Four Steps:

  1. Create a NEW Partition
  2. Perform Partprobe
  3. Format the Partition (with Filesystem)
  4. Mount the NEW Partition

How to Add a New Disk to an Existing Linux Server

Step 1: Create a NEW Partition

Firstly, check the current disk space in your machine

Display the amount of free space in the file system

Display the amount of free space in the file system

Here we can see a device called /dev/sda (contains /dev/sda1 & /dev/sda2). Now will create a new device and mount into one of the file systems.

Before doing anything with the disks and partitions, view basic information about all available partitions in the system.

[root@RHEL ~]# fdisk -l
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: B1737E47-9D4A-42C3-8617-8BD76CFFE7F3

Device Start End Sectors Size Type
/dev/sda1 2048 1230847 1228800 600M EFI System
/dev/sda2 1230848 3327999 2097152 1G Linux filesystem
/dev/sda3 3328000 83884031 80556032 38.4G Linux LVM

→ Add New Hard Disk on the virtual machine level. In this example have added 10GB.

In general, after adding a hard disk on VM level need to reboot the machine to be visible in the operating system (OS). But without rebooting the virtual machine, run the following commands to expand disc space in the physical volume of the Operating System by re-scanning the SCSI Bus and then adding SCSI Device.

echo 1 > /sys/class/block/sd?/device/rescan

NOTE: Replace the ? with you disk (example sda or sdb )  in our example it is ” echo 1 > /sys/class/block/sdb/device/rescan ”

After executing the above command, found a new hard disk called sdb .To check the device run the below command.

[root@RHEL ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 600M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 38.4G 0 part
├─rhel-root 253:0 0 34.4G 0 lvm /
└─rhel-swap 253:1 0 4G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
[root@RHEL ~]#
[root@RHEL ~]# fdisk -l |grep sdb
Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors

The FDISK tool allows you to modify hard disk partitions. To enter into the disk utility run the below syntax

fdisk <disk name>

Use p to list out the partition information first

"fdisk

” width=”937″ height=”431″> fdisk /dev/sdb(is the disk)

Use n to create a new partition and since it is a first-time partition select p as primary. Now use w write table to new disk and exit from fdisk.

Create Primary Partition - Add a New Disk to an Existing Linux Serve

Create Primary Partition

NOTE:  Select the size of the disk as per our requirements

1.First sector (2048-20971519, default 2048) → just give enter since the default value has already placed.

2. Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): I need complete 10GiB, so given enter it taken default value. If you need only 5GiB then give +5GiB

New Partition has been created /dev/sdb1 from /dev/sdb

Step 2: Perform Partprobe

We created a new partition (/dev/sdb1), but the Linux kernel/operating system did not recognize it. The following command can be run to notify the operating system that the partition table has changed.

partprobe <hard-drive>
[root@RHEL ~]# partprobe /dev/sdb
[root@RHEL ~]#
[root@RHEL ~]# fdisk -l |grep sdb
Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors
/dev/sdb1 2048 20971519 20969472 10G 83 Linux

Step 3: Format the Partition (with Filesystem)

After creating a partition, we must assign it a file system so that we can start storing data on it. The following syntax is used to format a partition.

mkfs.<file-system-type> <partition>

NOTE: Select file system type based on your operating system-supported versions.

How to Add a New Disk to an Existing Linux Server

We can set the file system on the partition

To check UUID (universally-unique identifier) and Filesystem type run the below command

[root@RHEL ~]# blkid /dev/sdb1
/dev/sdb1: UUID="ec136c18-fa7d-4877-92d7-930633a272f4" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="fa990b7a-01"

Step 4: Mount the NEW Partition

Even after formatting the partition, we are unable to add data to it. It is necessary to mount the partition before adding data to it.

  • To mount the /dev/sdb1 partition. we first need to create a mount point as shown below.

Here directory name is bhanuwriter

mkdir /<directory name>
  • Now perform mount operation as shown below, my new device name is /dev/sdb1
mount <device name> <directory name (mount point)>
  • It is recommended you add the partition to /etc/fstab file to make it permanent mount, so if you reboot the system, the partition will not be unmounted.
creating directory, mount point and adding in fstab

creating directory, mount point and adding in fstab

Block device, Filesystems, Mountpoints, and Mount options are all stored in the /etc/fstab file, which is one of the most important files in a Linux Operating System.

Tables generally have six columns, with each column designating a parameter and must be set up correctly.

  1. Device Name: /dev/sdb1
  2. Mount Point: /bhanuwriter
  3. File System Type: xfs
  4. Mount options: If we want to use the default set of mount options, we specify Mount Option as default value
  5. Backup Operation: 1 for dump utility backup of the partition & 0 for no backup.
  6. File System Check Order: 0 means that Check Sequence (fsck) will not check the filesystem.

Note:

Once you run the below command all unmounted partitions with entries in /etc/fstab will now be mounted.

mount -a
How to Add a New Disk to an Existing Linux Server

Verify the new partitionNew partition (/bhanuwriter)  created successfully and ready to use.

If you want to reduce same partition in centos or RHEL follow the steps in reverse order.

Conclusion

How to Add a New Disk to an Existing Linux Server has explained a simple manner. This procedure is same for CentOS, Red Hat Enterprise Linux, ubuntu flavors. In next article about LVM concept.

If you require any further information about How to Add a New Disk to an Existing Linux Server, please feel free to contact me.

Next PostLinux Logical Volume Manager (LVM) Procedure Previous PostWhat’s New in Red Hat Enterprise Linux (RHEL) 9

Leave a Reply

Your email address will not be published. Required fields are marked *