How to add volume to VM

How to add volume to VM

After attaching the volume please run the below commands to print the partitions, partion types and available disks on the VM.

df -HT
lsblk

in the above image, we have vdb volume attached to the VM.

1. Create a Partition on the Disk

Launch fdisk for the disk:
fdisk /dev/vdb

Inside fdisk:
Press n to create a new partition.
Choose p for a primary partition.
Accept the default values for the first and last sectors (or customize as needed).
Press w to write the changes and exit.

2. Format the Partition

Format the new partition (/dev/vdb1, assuming the first partition is created) with a filesystem like ext4 or xfs.

For ext4
mkfs.ext4 /dev/vdb1

For xfs

mkfs.xfs /dev/vdb1

3. Create a Mount Point

Create a directory where you want to mount the new partition:

mkdir /mnt/newdisk

4. Mount the Partition

Mount the partition to the directory:

mount /dev/vdb1 /mnt/newdisk

5. Verify the Mount

df -HT

6. Make the Mount Permanent

To ensure the partition mounts automatically on reboot:
1. Get the UUID of the partition:

blkid /dev/vdb1


Example output:
[root@cloudpe ~]# blkid /dev/vdb1
/dev/vdb1: UUID="26503f62-8c8f-4564-a2d3-3db97ff08f3a" TYPE="ext4" PARTUUID="b3f5f32c-01"

2. Edit /etc/fstab and add the following line:
Replace your-uuid-here with the actual UUID and ext4 with your chosen filesystem.

UUID=26503f62-8c8f-4564-a2d3-3db97ff08f3a /mnt/newdisk ext4 defaults 0 0

  3.Test the fstab configuration:

mount -a

You’re done! The disk is now partitioned, formatted, mounted, and set up for persistent mounting.

Was this article helpful?

Related Articles