Add a New Disk to an Existing Linux Server

In this article describes how to add a file system on exiting Linux OS. As OS is running on VM, First will show how to add a disk on VM then Create a Filesystem on OS Level.

Click on Storage for your target server, Then select Controller: SATA -> Click on (Adds New Hard Disk) icon.

Click on Create icon.

Select VDI and Click Next..

Select Dynamically allocated or Fixed size based on your requirement and Click Next..

Provide File size with GB and Click Next..

Select the disk which has been created (it will be under Not Attached section) Click on Choose.

New disk has been added on VM. Start the Server.

List of Disk.

[root@ol71ora193 ~]# ls -l /dev/sd*
brw-rw----. 1 root disk 8,  0 Sep 15 13:00 /dev/sda
brw-rw----. 1 root disk 8,  1 Sep 15 13:00 /dev/sda1
brw-rw----. 1 root disk 8,  2 Sep 15 13:00 /dev/sda2
brw-rw----. 1 root disk 8, 16 Sep 15 13:00 /dev/sdb

Create partition using fdisk. Make sure selected correct one.

[root@ol71ora193 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xb9b25f66.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-83886079, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079):
Using default value 83886079
Partition 1 of type Linux and of size 40 GiB is set

Command (m for help): p

Disk /dev/sdb: 42.9 GB, 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
Disk label type: dos
Disk identifier: 0xb9b25f66

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    83886079    41942016   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Now format the disk with mkfs command.

[root@ol71ora193 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2621440 inodes, 10485504 blocks
524275 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2157969408
320 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Mount the disk.

[root@ol71ora193 ~]# mount /dev/sdb1 /u02
[root@ol71ora193 ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/ol-root   27G   23G  4.0G  85% /
devtmpfs             1.8G     0  1.8G   0% /dev
tmpfs                1.9G   80K  1.9G   1% /dev/shm
tmpfs                1.9G  8.8M  1.8G   1% /run
tmpfs                1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1            497M  150M  348M  31% /boot
/dev/sdb1             40G   49M   38G   1% /u02

Add this line on /etc/fstab : /dev/sdb1 /u02 ext4 defaults 1 3

[root@ol71ora193 ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Sun Aug 30 18:49:08 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/ol-root     /                       xfs     defaults        0 0
UUID=df124436-ee4b-40a4-896f-ab1998475a0c /boot                   xfs     defaults        0 0
/dev/mapper/ol-swap     swap                    swap    defaults        0 0
/dev/sdb1               /u02                    ext4    defaults        1 3