How to add a new disk to an existing Linux Virtual Machine?
corpline

To add a new disk to a virtual machine, please follow these steps:

1. Shutdown the VM and add a new disk

Log in as the root user on your Linux virtual machine and execute the following command. Take note of the sd* entries.

[root@dbdocs ~]# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdb1 
Right-click on the virtual machine and select "Settings". In the settings menu, navigate to the "Storage" section. Locate the SATA controller and select it. Click on the "Add Hard Disk" button to add a new hard disk. Adding a new disk to VM Click on "Create" to proceed. Adding a new disk to VM Choose "VDI (VirtualBox Disk Image)" from the available options. Adding a new disk to VM Specify the location and size of the disk. Click on "Finish" to proceed. Adding a new disk to VM Adding a new disk to VM The VM now includes the newly added disk named dbdocs_1.vdi.
Start the VM Adding a new disk to VM

2. Mount the disk and create a Volume

Log in as the root user on your Linux virtual machine and execute the following command. We now see a new entry:/dev/sdc

[root@dbdocs ~]# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdb1  /dev/sdc
Execute the following command to create a partition on the new disk:

[root@dbdocs ~]# fdisk /dev/sdc

Welcome to fdisk (util-linux 2.37.4).
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.
Created a new DOS disklabel with disk identifier 0x0f1bf131.

Command (m for help): p
Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VBOX HARDDISK
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: dos
Disk identifier: 0x0f1bf131

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519):

Created a new partition 1 of type 'Linux' and of size 10 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@dbdocs ~]#

Create an ext3 file system on the partition that was previously created on the new disk:
 
[root@dbdocs ~]# mkfs -t ext3 /dev/sdc1
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 2621184 4k blocks and 655360 inodes
Filesystem UUID: df2e1931-462d-49b7-8aba-589b32412cb2
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

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

[root@dbdocs ~]#   
Execute the "fdisk" command to confirm the presence of the newly created disk partition:
 fdisk -l 
Execute the following command to establish a mount point for the newly created disk partition:
 --To create a user-friendly mount point, use the following command:
mkdir /u03 
Execute the following command to view the current contents of the /etc/fstab file:
cat /etc/fstab
Using a text editor, open the /etc/fstab file and insert the following line to include the disk partition, ensuring it remains accessible after reboots
/dev/sdc1 /u03 ext3 defaults 1 3 
Restart the Linux virtual machine to make the new disk partition accessible. The new volume /u03 is now available.

[root@dbdocs ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               4.0M     0  4.0M   0% /dev
tmpfs                  890M     0  890M   0% /dev/shm
tmpfs                  356M  5.6M  351M   2% /run
/dev/mapper/rhel-root   17G   14G  3.5G  80% /
/dev/sda1             1014M  292M  723M  29% /boot
/dev/sdb1              2.9G   92K  2.8G   1% /u02
/dev/sdc1              9.8G   92K  9.3G   1% /u03
tmpfs                  178M   52K  178M   1% /run/user/42
tmpfs                  178M   36K  178M   1% /run/user/0
[root@dbdocs ~]#
The new volume /u03 is now available.


Rate Your Experience

: 0 : 0

Online Tests
Read more

Oracle Database
Read more

MSSQL Database
Read more

PostGres Database
Read more

Linux
Read more

ASP/C#
Read more

Navigation Panel